Ejemplo n.º 1
0
 /**
  * Function to for pre-processing
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     parent::preProcess();
     $this->_key = CRM_Utils_Request::retrieve('key', 'String', $this, FALSE, 0);
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse');
     $session->pushUserContext($url);
     $this->assign('id', $this->_id);
     $this->assign('key', $this->_key);
     switch ($this->_action) {
         case CRM_Core_Action::ADD:
         case CRM_Core_Action::DELETE:
         case CRM_Core_Action::ENABLE:
         case CRM_Core_Action::DISABLE:
             $info = CRM_Extension_System::singleton()->getMapper()->keyToInfo($this->_key);
             $extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
             $this->assign('extension', $extInfo);
             break;
         case CRM_Core_Action::UPDATE:
             if (!CRM_Extension_System::singleton()->getBrowser()->isEnabled()) {
                 CRM_Core_Error::fatal(ts('The system administrator has disabled this feature.'));
             }
             $info = CRM_Extension_System::singleton()->getBrowser()->getExtension($this->_key);
             $extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
             $this->assign('extension', $extInfo);
             break;
         default:
             CRM_Core_Error::fatal(ts('Unsupported action'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $info = CRM_Extension_System::singleton()->getMapper()->keyToInfo($this->_key);
     $extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
     $extName = $extInfo['name'];
     switch ($this->_action) {
         case CRM_Core_Action::ADD:
             $buttonName = ts('Install');
             $title = ts('Install ' . $extName . '?');
             break;
         case CRM_Core_Action::UPDATE:
             $buttonName = ts('Download and Install');
             $title = ts('Download and Install ' . $extName . '?');
             break;
         case CRM_Core_Action::DELETE:
             $buttonName = ts('Uninstall');
             $title = ts('Uninstall ' . $extName . '?');
             break;
         case CRM_Core_Action::ENABLE:
             $buttonName = ts('Enable');
             $title = ts('Enable ' . $extName . '?');
             break;
         case CRM_Core_Action::DISABLE:
             $buttonName = ts('Disable');
             $title = ts('Disable ' . $extName . '?');
             break;
     }
     $this->assign('title', $title);
     $this->addButtons(array(array('type' => 'next', 'name' => $buttonName, 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
Ejemplo 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();
     $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;
 }
Ejemplo n.º 4
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;
 }
Ejemplo 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();
     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;
 }