/**
 * Display the CiviCRM version
 *
 * @code
 * The version is {crmVersion}.
 *
 * {crmVersion redact=auto assign=ver}The version is {$ver}.
 * @endcode
 *
 * @param $params
 * @param $smarty
 *
 * @return string
 */
function smarty_function_crmVersion($params, &$smarty)
{
    $version = CRM_Utils_System::version();
    if (!CRM_Core_Permission::check('access CiviCRM')) {
        $version = CRM_Utils_System::majorVersion();
    }
    if (isset($params['assign'])) {
        $smarty->assign($params['assign'], $version);
    } else {
        return $version;
    }
}
Example #2
0
 /**
  * Checks if extensions are set up properly
  * @return array
  */
 public function checkExtensions()
 {
     $messages = array();
     $extensionSystem = CRM_Extension_System::singleton();
     $mapper = $extensionSystem->getMapper();
     $manager = $extensionSystem->getManager();
     if ($extensionSystem->getDefaultContainer()) {
         $basedir = $extensionSystem->getDefaultContainer()->baseDir;
     }
     if (empty($basedir)) {
         // no extension directory
         $messages[] = new CRM_Utils_Check_Message(__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'), \Psr\Log\LogLevel::NOTICE, 'fa-plug');
         return $messages;
     }
     if (!is_dir($basedir)) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Your extensions directory path points to %1, which is not a directory.  Please check your file system.', array(1 => $basedir)), ts('Extensions directory incorrect'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
         return $messages;
     } elseif (!is_writable($basedir)) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Your extensions directory, %1, is not writable.  Please change your file permissions.', array(1 => $basedir)), ts('Extensions directory not writable'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
         return $messages;
     }
     if (empty($extensionSystem->getDefaultContainer()->baseUrl)) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('The extensions URL is not properly set. Please go to the <a href="%1">URL setting page</a> and correct it.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/url', 'reset=1'))), ts('Extensions url missing'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
         return $messages;
     }
     if (!$extensionSystem->getBrowser()->isEnabled()) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Not checking remote URL for extensions since ext_repo_url is set to false.'), ts('Extensions check disabled'), \Psr\Log\LogLevel::NOTICE, 'fa-plug');
         return $messages;
     }
     try {
         $remotes = $extensionSystem->getBrowser()->getExtensions();
     } catch (CRM_Extension_Exception $e) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, $e->getMessage(), ts('Extension download error'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
         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(__FUNCTION__, 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, 'fa-plug');
         return $messages;
     }
     $keys = array_keys($manager->getStatuses());
     sort($keys);
     $severity = 1;
     $msgArray = $okextensions = array();
     foreach ($keys as $key) {
         try {
             $obj = $mapper->keyToInfo($key);
         } catch (CRM_Extension_Exception $ex) {
             $severity = 4;
             $msgArray[] = ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key));
             continue;
         }
         $row = CRM_Admin_Page_Extensions::createExtendedInfo($obj);
         switch ($row['status']) {
             case CRM_Extension_Manager::STATUS_INSTALLED_MISSING:
                 $severity = 4;
                 $msgArray[] = ts('%1 extension (%2) is installed but missing files.', array(1 => CRM_Utils_Array::value('label', $row), 2 => $key));
                 break;
             case CRM_Extension_Manager::STATUS_INSTALLED:
                 if (CRM_Utils_Array::value($key, $remotes)) {
                     if (version_compare($row['version'], $remotes[$key]->version, '<')) {
                         $severity = $severity < 3 ? 3 : $severity;
                         $msgArray[] = ts('%1 extension (%2) is upgradeable to version %3.', array(1 => CRM_Utils_Array::value('label', $row), 2 => $key, 3 => $remotes[$key]->version));
                     } else {
                         $okextensions[] = CRM_Utils_Array::value('label', $row) ? "{$row['label']} ({$key})" : $key;
                     }
                 } else {
                     $okextensions[] = CRM_Utils_Array::value('label', $row) ? "{$row['label']} ({$key})" : $key;
                 }
                 break;
             case CRM_Extension_Manager::STATUS_UNINSTALLED:
             case CRM_Extension_Manager::STATUS_DISABLED:
             case CRM_Extension_Manager::STATUS_DISABLED_MISSING:
             default:
         }
     }
     $msg = implode('  ', $msgArray);
     if (empty($msgArray)) {
         $msg = empty($okextensions) ? ts('No extensions installed.') : ts('Extensions are up-to-date:') . ' ' . implode(', ', $okextensions);
     } elseif (!empty($okextensions)) {
         $msg .= '  ' . ts('Other extensions are up-to-date:') . ' ' . implode(', ', $okextensions);
     }
     // OK, return several data rows
     $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, $msg, ts('Extension Updates'), CRM_Utils_Check::severityMap($severity, TRUE), 'fa-plug');
     return $messages;
 }
Example #3
0
 /**
  * Checks if extensions are set up properly
  * @return array
  */
 public function checkExtensions()
 {
     $messages = array();
     $extensionSystem = CRM_Extension_System::singleton();
     $mapper = $extensionSystem->getMapper();
     $manager = $extensionSystem->getManager();
     if ($extensionSystem->getDefaultContainer()) {
         $basedir = $extensionSystem->getDefaultContainer()->baseDir;
     }
     if (empty($basedir)) {
         // no extension directory
         $messages[] = new CRM_Utils_Check_Message(__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'), \Psr\Log\LogLevel::NOTICE, 'fa-plug');
         return $messages;
     }
     if (!is_dir($basedir)) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Your extensions directory path points to %1, which is not a directory.  Please check your file system.', array(1 => $basedir)), ts('Extensions directory incorrect'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
         return $messages;
     } elseif (!is_writable($basedir)) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Your extensions directory, %1, is not writable.  Please change your file permissions.', array(1 => $basedir)), ts('Extensions directory not writable'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
         return $messages;
     }
     if (empty($extensionSystem->getDefaultContainer()->baseUrl)) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('The extensions URL is not properly set. Please go to the <a href="%1">URL setting page</a> and correct it.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/url', 'reset=1'))), ts('Extensions url missing'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
         return $messages;
     }
     if (!$extensionSystem->getBrowser()->isEnabled()) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Not checking remote URL for extensions since ext_repo_url is set to false.'), ts('Extensions check disabled'), \Psr\Log\LogLevel::NOTICE, 'fa-plug');
         return $messages;
     }
     try {
         $remotes = $extensionSystem->getBrowser()->getExtensions();
     } catch (CRM_Extension_Exception $e) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, $e->getMessage(), ts('Extension download error'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
         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(__FUNCTION__, 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, 'fa-plug');
         return $messages;
     }
     $keys = array_keys($manager->getStatuses());
     sort($keys);
     $updates = $errors = $okextensions = array();
     foreach ($keys as $key) {
         try {
             $obj = $mapper->keyToInfo($key);
         } catch (CRM_Extension_Exception $ex) {
             $errors[] = ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key));
             continue;
         }
         $row = CRM_Admin_Page_Extensions::createExtendedInfo($obj);
         switch ($row['status']) {
             case CRM_Extension_Manager::STATUS_INSTALLED_MISSING:
                 $errors[] = ts('%1 extension (%2) is installed but missing files.', array(1 => CRM_Utils_Array::value('label', $row), 2 => $key));
                 break;
             case CRM_Extension_Manager::STATUS_INSTALLED:
                 if (!empty($remotes[$key]) && version_compare($row['version'], $remotes[$key]->version, '<')) {
                     $updates[] = ts('%1 (%2) version %3 is installed. <a %4>Upgrade to version %5</a>.', array(1 => CRM_Utils_Array::value('label', $row), 2 => $key, 3 => $row['version'], 4 => 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', "action=update&id={$key}&key={$key}") . '"', 5 => $remotes[$key]->version));
                 } else {
                     if (empty($row['label'])) {
                         $okextensions[] = $key;
                     } else {
                         $okextensions[] = ts('%1 (%2) version %3', array(1 => $row['label'], 2 => $key, 3 => $row['version']));
                     }
                 }
                 break;
         }
     }
     if (!$okextensions && !$updates && !$errors) {
         $messages[] = new CRM_Utils_Check_Message('extensionsOk', ts('No extensions installed. <a %1>Browse available extensions</a>.', array(1 => 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1') . '"')), ts('Extensions'), \Psr\Log\LogLevel::INFO, 'fa-plug');
     }
     if ($errors) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>', ts('Extension Error'), \Psr\Log\LogLevel::ERROR, 'fa-plug');
     }
     if ($updates) {
         $messages[] = new CRM_Utils_Check_Message('extensionUpdates', '<ul><li>' . implode('</li><li>', $updates) . '</li></ul>', ts('Extension Update Available', array('plural' => '%count Extension Updates Available', 'count' => count($updates))), \Psr\Log\LogLevel::WARNING, 'fa-plug');
     }
     if ($okextensions) {
         if ($updates || $errors) {
             $message = ts('1 extension is up-to-date:', array('plural' => '%count extensions are up-to-date:', 'count' => count($okextensions)));
         } else {
             $message = ts('All extensions are up-to-date:');
         }
         $messages[] = new CRM_Utils_Check_Message('extensionsOk', $message . '<ul><li>' . implode('</li><li>', $okextensions) . '</li></ul>', ts('Extensions'), \Psr\Log\LogLevel::INFO, 'fa-plug');
     }
     return $messages;
 }