}
$this->assign('localExtensionRows', $localExtensionRows);
+ try {
+ $remoteExtensions = CRM_Extension_System::singleton()->getBrowser()->getExtensions();
+ }
+ catch (CRM_Extension_Exception $e) {
+ $remoteExtensions = array();
+ CRM_Core_Session::setStatus($e->getMessage(), ts('Extension download error'), 'error');
+ }
+
// build list of available downloads
$remoteExtensionRows = array();
- foreach (CRM_Extension_System::singleton()->getBrowser()->getExtensions() as $info) {
+ foreach ($remoteExtensions as $info) {
$row = (array) $info;
$row['id'] = $info->key;
$action = CRM_Core_Action::UPDATE;
* extensions.
*
* @return string
+ * @throws \CRM_Extension_Exception
*/
private function grabRemoteJson() {
if (FALSE === $this->getRepositoryUrl()) {
// don't check if the user has configured civi not to check an external
// url for extensions. See CRM-10575.
- CRM_Core_Session::setStatus(ts('Not checking remote URL for extensions since ext_repo_url is set to false.'), ts('Check Settings'), 'alert');
return array();
}
$filename = $this->cacheDir . DIRECTORY_SEPARATOR . self::CACHE_JSON_FILE;
$url = $this->getRepositoryUrl() . $this->indexPath;
$status = CRM_Utils_HttpClient::singleton()->fetch($url, $filename);
- if ($status !== CRM_Utils_HttpClient::STATUS_OK) {
- CRM_Core_Session::setStatus(ts('The CiviCRM public extensions directory at %1 could not be contacted - please check your webserver can make external HTTP requests or contact CiviCRM team on <a href="http://forum.civicrm.org/">CiviCRM forum</a>.<br />', array(1 => $this->getRepositoryUrl())), ts('Connection Error'), 'error');
- }
- else {
- // Don't call grabCachedJson here, that would risk infinite recursion
- $json = file_get_contents($filename);
- }
-
- // CRM-13141 There may not be any compatible extensions available for the requested CiviCRM version + CMS. If so, $extdir is empty so just return a notification.
- if (empty($json)) {
- $config = CRM_Core_Config::singleton();
- CRM_Core_Session::setStatus(ts('There are currently no extensions on the CiviCRM public extension directory which are compatible with version %2 (<a href="%1">requested extensions from here</a>). If you want to install an extension which is not marked as compatible, you may be able to <a href="%3">download and install extensions manually</a> (depending on access to your web server).<br />', array(
- 1 => $this->getRepositoryUrl(),
- 2 => CRM_Utils_System::version(),
- 3 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Extensions',
- )), ts('No Extensions Available for this Version'), 'info');
- }
ini_restore('allow_url_fopen');
ini_restore('default_socket_timeout');
restore_error_handler();
- return $json;
+ if ($status !== CRM_Utils_HttpClient::STATUS_OK) {
+ throw new CRM_Extension_Exception(ts('The CiviCRM public extensions directory at %1 could not be contacted - please check your webserver can make external HTTP requests or contact CiviCRM team on <a href="http://forum.civicrm.org/">CiviCRM forum</a>.', array(1 => $this->getRepositoryUrl())), 'connection_error');
+ }
+
+ // Don't call grabCachedJson here, that would risk infinite recursion
+ return file_get_contents($filename);
}
/**
$extensionSystem = CRM_Extension_System::singleton();
$mapper = $extensionSystem->getMapper();
$manager = $extensionSystem->getManager();
- $remotes = $extensionSystem->getBrowser()->getExtensions();
if ($extensionSystem->getDefaultContainer()) {
$basedir = $extensionSystem->getDefaultContainer()->baseDir;
return $messages;
}
+ if (!$extensionSystem->getBrowser()->isEnabled()) {
+ $messages[] = new CRM_Utils_Check_Message(
+ 'checkExtensions',
+ ts('Not checking remote URL for extensions since ext_repo_url is set to false.'),
+ ts('Extensions check disabled'),
+ \Psr\Log\LogLevel::NOTICE
+ );
+ return $messages;
+ }
+
+ try {
+ $remotes = $extensionSystem->getBrowser()->getExtensions();
+ }
+ catch (CRM_Extension_Exception $e) {
+ $messages[] = new CRM_Utils_Check_Message(
+ 'checkExtensions',
+ $e->getMessage(),
+ ts('Extension download error'),
+ \Psr\Log\LogLevel::ERROR
+ );
+ return $messages;
+ }
+
+ if (!$remotes) {
+ // CRM-13141 There may not be any compatible extensions available for the requested CiviCRM version + CMS. If so, $extdir is empty so just return a notice.
+ $messages[] = new CRM_Utils_Check_Message(
+ 'checkExtensions',
+ ts('There are currently no extensions on the CiviCRM public extension directory which are compatible with version %1. If you want to install an extension which is not marked as compatible, you may be able to <a %2>download and install extensions manually</a> (depending on access to your web server).', array(
+ 1 => CRM_Utils_System::majorVersion(),
+ 2 => 'href="http://wiki.civicrm.org/confluence/display/CRMDOC/Extensions"',
+ )),
+ ts('No Extensions Available for this Version'),
+ \Psr\Log\LogLevel::NOTICE
+ );
+ return $messages;
+ }
+
$keys = array_keys($manager->getStatuses());
sort($keys);
$severity = 1;
}
// OK, return several data rows
- // $returnValues = array(
- // array('status' => $return, 'message' => $msg),
- // );
-
$messages[] = new CRM_Utils_Check_Message(
'checkExtensions',
$msg,
$fp = @fopen($localFile, "w");
if (!$fp) {
+ // Fixme: throw error instead of setting message
CRM_Core_Session::setStatus(ts('Unable to write to %1.<br />Is the location writable?', array(1 => $localFile)), ts('Write Error'), 'error');
return self::STATUS_WRITE_ERROR;
}
curl_exec($ch);
if (curl_errno($ch)) {
+ // Fixme: throw error instead of setting message
CRM_Core_Session::setStatus(ts('Unable to download extension from %1. Error Message: %2',
- array(1 => $remoteFile, 2 => curl_error($ch))), ts('Download Error'), 'error');
+ array(1 => $remoteFile, 2 => curl_error($ch))), ts('Extension download error'), 'error');
return self::STATUS_DL_ERROR;
}
else {
return $version;
}
+ /**
+ * Gives the first two parts of the version string E.g. 6.1
+ *
+ * @return string
+ */
+ public static function majorVersion() {
+ list($a, $b) = explode('.', self::version());
+ return "$a.$b";
+ }
+
/**
* Determines whether a string is a valid CiviCRM version string.
*