/**
  * 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;
 }
 /**
  * @param bool $auth
  */
 public function execute($auth = TRUE)
 {
     $this->logEntry('Starting scheduled jobs execution');
     if ($auth && !CRM_Utils_System::authenticateKey(TRUE)) {
         $this->logEntry('Could not authenticate the site key.');
     }
     require_once 'api/api.php';
     // it's not asynchronous at this stage
     CRM_Utils_Hook::cron($this);
     foreach ($this->jobs as $job) {
         if ($job->is_active) {
             if ($job->needsRunning()) {
                 $this->executeJob($job);
             }
         }
     }
     $this->logEntry('Finishing scheduled jobs execution.');
     // Set last cron date for the status check
     $statusPref = array('name' => 'checkLastCron', 'check_info' => gmdate('U'));
     CRM_Core_BAO_StatusPreference::create($statusPref);
 }