*/
public function checkVersion() {
$messages = array();
- $vc = new CRM_Utils_VersionCheck();
- $vc->initialize();
+ try {
+ $vc = new CRM_Utils_VersionCheck();
+ $vc->initialize();
+ }
+ catch (Exception $e) {
+ $messages[] = new CRM_Utils_Check_Message(
+ 'checkVersionError',
+ ts('Directory %1 is not writable. Please change your file permissions.',
+ array(1 => dirname($vc->cacheFile))),
+ ts('Directory not writable'),
+ \Psr\Log\LogLevel::ERROR,
+ 'fa-times-circle-o'
+ );
+ return $messages;
+ }
// Show a notice if the version_check job is disabled
if (empty($vc->cronJob['is_active'])) {
__FUNCTION__,
ts('Your extensions directory is not set. Click <a href="%1">here</a> to set the extensions directory.',
array(1 => CRM_Utils_System::url('civicrm/admin/setting/path', 'reset=1'))),
- ts('Extensions directory not writable'),
+ ts('Directory not writable'),
\Psr\Log\LogLevel::NOTICE,
'fa-plug'
);
elseif (!is_writable($basedir)) {
$messages[] = new CRM_Utils_Check_Message(
__FUNCTION__,
- ts('Your extensions directory, %1, is not writable. Please change your file permissions.',
+ ts('Directory %1 is not writable. Please change your file permissions.',
array(1 => $basedir)),
- ts('Extensions directory not writable'),
+ ts('Directory not writable'),
\Psr\Log\LogLevel::ERROR,
'fa-plug'
);
/**
* Self-populates version info
+ *
+ * @throws \Exception
*/
public function initialize() {
$this->getJob();
if (!empty($this->cronJob['is_active']) &&
(!$this->isInfoAvailable || filemtime($this->cacheFile) < $expiryTime)
) {
+ // First try updating the files modification time, for 2 reasons:
+ // - if the file is not writeable, this saves the trouble of pinging back
+ // - if the remote server is down, this will prevent an immediate retry
+ if (touch($this->cacheFile) === FALSE) {
+ throw new Exception('File not writable');
+ }
$this->fetch();
}
}
/**
* Save version info to file.
* @param string $contents
+ * @throws \Exception
*/
private function writeCacheFile($contents) {
- $fp = fopen($this->cacheFile, 'w');
- fwrite($fp, $contents);
- fclose($fp);
+ if (file_put_contents($this->cacheFile, $contents) === FALSE) {
+ throw new Exception('File not writable');
+ }
}
/**