Exemplo n.º 1
0
 /**
  * @param string $name
  *   Symbolic name for the check.
  * @param string $message
  *   Printable message (short or long).
  * @param string $title
  *   Printable message (short).
  * @param string $level
  *   The severity of the message. Use PSR-3 log levels.
  *
  * @see Psr\Log\LogLevel
  */
 public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel::WARNING)
 {
     $this->name = $name;
     $this->message = $message;
     $this->title = $title;
     // Handle non-integer severity levels.
     if (!CRM_Utils_Rule::integer($level)) {
         $level = CRM_Utils_Check::severityMap($level);
     }
     $this->level = $level;
 }
Exemplo n.º 2
0
 /**
  * Create or update a Status Preference entry.
  *
  * @param array $params
  *
  * @return array
  */
 public static function create($params)
 {
     $statusPreference = new CRM_Core_BAO_StatusPreference();
     // Default severity level to ignore is 0 (DEBUG).
     if (!isset($params['ignore_severity'])) {
         $params['ignore_severity'] = 0;
     }
     // Severity can be either text ('critical') or an integer <= 7.
     // It's a magic number, but based on PSR-3 standards.
     if (!CRM_Utils_Rule::integer($params['ignore_severity'])) {
         $params['ignore_severity'] = CRM_Utils_Check::severityMap($params['ignore_severity']);
     }
     if ($params['ignore_severity'] > 7) {
         CRM_Core_Error::fatal(ts('You can not pass a severity level higher than 7.'));
     }
     // If severity is now blank, you have an invalid severity string.
     if (is_null($params['ignore_severity'])) {
         CRM_Core_Error::fatal(ts('Invalid string passed as severity level.'));
     }
     // Check if this StatusPreference already exists.
     if (empty($params['id']) && CRM_Utils_Array::value('name', $params)) {
         $statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
         $statusPreference->name = $params['name'];
         $statusPreference->find(TRUE);
     }
     $statusPreference->copyValues($params);
     $edit = $statusPreference->id ? TRUE : FALSE;
     if ($edit) {
         CRM_Utils_Hook::pre('edit', 'StatusPreference', $statusPreference->id, $statusPreference);
     } else {
         CRM_Utils_Hook::pre('create', 'StatusPreference', NULL, $statusPreference);
     }
     $statusPreference->save();
     if ($edit) {
         CRM_Utils_Hook::post('edit', 'StatusPreference', $statusPreference->id, $statusPreference);
     } else {
         CRM_Utils_Hook::post('create', 'StatusPreference', NULL, $statusPreference);
     }
     return $statusPreference;
 }
Exemplo n.º 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);
     $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;
 }
Exemplo n.º 4
0
 /**
  * Set severity level
  *
  * @param string|int $level
  * @throws \CRM_Core_Exception
  */
 public function setLevel($level)
 {
     // Convert level to integer
     if (!CRM_Utils_Rule::positiveInteger($level)) {
         $level = CRM_Utils_Check::severityMap($level);
     } else {
         // Validate numeric input - this will throw an exception if invalid
         CRM_Utils_Check::severityMap($level, TRUE);
     }
     $this->level = $level;
     // Clear internal caches
     unset($this->isVisible, $this->hiddenUntil);
 }
Exemplo n.º 5
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();
     $remotes = $extensionSystem->getBrowser()->getExtensions();
     if ($extensionSystem->getDefaultContainer()) {
         $basedir = $extensionSystem->getDefaultContainer()->baseDir;
     }
     if (empty($basedir)) {
         // no extension directory
         $messages[] = new CRM_Utils_Check_Message('checkExtensions', 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);
         return $messages;
     }
     if (!is_dir($basedir)) {
         $messages[] = new CRM_Utils_Check_Message('checkExtensions', 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);
         return $messages;
     } elseif (!is_writable($basedir)) {
         $messages[] = new CRM_Utils_Check_Message('checkExtensions', 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);
         return $messages;
     }
     if (empty($extensionSystem->getDefaultContainer()->baseUrl)) {
         $messages[] = new CRM_Utils_Check_Message('checkExtensions', 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 directory not writable'), \Psr\Log\LogLevel::ERROR);
         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
     // $returnValues = array(
     //   array('status' => $return, 'message' => $msg),
     // );
     $messages[] = new CRM_Utils_Check_Message('checkExtensions', $msg, ts('Extension Updates'), CRM_Utils_Check::severityMap($severity, TRUE));
     return $messages;
 }