function run() { require_once 'CRM/Utils/Menu.php'; $items =& CRM_Utils_Menu::items(); $config =& CRM_Core_Config::singleton(); $groups = array(ts('Manage'), ts('Configure'), ts('Setup')); if (in_array("CiviContribute", $config->enableComponents)) { $groups[] = 'CiviContribute'; } $adminPanel = array(); foreach ($groups as $group) { $adminPanel[$group] = array(); foreach ($items as $item) { if ($config->userFramework == 'Mambo' && $item['path'] == 'civicrm/admin/access') { // access control not yet implemented for mambo continue; } if (CRM_Utils_Array::value('adminGroup', $item) == $group) { $value = array('title' => $item['title'], 'url' => CRM_Utils_System::url($item['path'], CRM_Utils_Array::value('qs', $item)), 'icon' => $item['icon'], 'extra' => CRM_Utils_Array::value('extra', $item)); $adminPanel[$group][$item['weight'] . '.' . $item['title']] = $value; } } ksort($adminPanel[$group]); } require_once 'CRM/Utils/VersionCheck.php'; $versionCheck =& CRM_Utils_VersionCheck::singleton(); $this->assign('newVersion', $versionCheck->newerVersion()); $this->assign('localVersion', $versionCheck->localVersion); $this->assign('adminPanel', $adminPanel); return parent::run(); }
/** * @dataProvider securityUpdateDataProvider * @param string $localVersion * @param array $versionInfo * @param bool $expectedResult */ public function testSecurityUpdate($localVersion, $versionInfo, $expectedResult) { $vc = CRM_Utils_VersionCheck::singleton(); // These values are set by the constructor but for testing we override them $vc->localVersion = $localVersion; $vc->localMajorVersion = $vc->getMajorVersion($localVersion); $vc->versionInfo = $versionInfo; $this->assertEquals($vc->isSecurityUpdateAvailable(), $expectedResult); }
function run() { // ensure that all CiviCRM tables are InnoDB, else abort if (CRM_Core_DAO::isDBMyISAM()) { $errorMessage = 'Your database is configured to use the MyISAM database engine. CiviCRM requires InnoDB. You will need to convert any MyISAM tables in your database to InnoDB. Using MyISAM tables will result in data integrity issues. This will be a fatal error in CiviCRM v2.1.'; require_once 'CRM/Core/Session.php'; CRM_Core_Session::setStatus($errorMessage); } if (!CRM_Utils_System::isDBVersionValid($errorMessage)) { CRM_Core_Session::setStatus($errorMessage); } $groups = array('Customize' => ts('Customize'), 'Configure' => ts('Configure'), 'Manage' => ts('Manage'), 'Option Lists' => ts('Option Lists')); $config =& CRM_Core_Config::singleton(); if (in_array("CiviContribute", $config->enableComponents)) { $groups['CiviContribute'] = ts('CiviContribute'); } if (in_array("CiviMember", $config->enableComponents)) { $groups['CiviMember'] = ts('CiviMember'); } if (in_array("CiviEvent", $config->enableComponents)) { $groups['CiviEvent'] = ts('CiviEvent'); } if (in_array("CiviMail", $config->enableComponents)) { $groups['CiviMail'] = ts('CiviMail'); } if (in_array("CiviCase", $config->enableComponents)) { $groups['CiviCase'] = ts('CiviCase'); } if (in_array("CiviReport", $config->enableComponents)) { $groups['CiviReport'] = ts('CiviReport'); } require_once 'CRM/Core/Menu.php'; $values =& CRM_Core_Menu::getAdminLinks(); require_once 'CRM/Core/ShowHideBlocks.php'; $this->_showHide =& new CRM_Core_ShowHideBlocks(); foreach ($groups as $group => $title) { $this->_showHide->addShow("id_{$group}_show"); $this->_showHide->addHide("id_{$group}"); $v = CRM_Core_ShowHideBlocks::links($this, $group, '', '', false); $adminPanel[$group] = $values[$group]; $adminPanel[$group]['show'] = $v['show']; $adminPanel[$group]['hide'] = $v['hide']; $adminPanel[$group]['title'] = $title; } require_once 'CRM/Utils/VersionCheck.php'; $versionCheck =& CRM_Utils_VersionCheck::singleton(); $this->assign('newVersion', $versionCheck->newerVersion()); $this->assign('localVersion', $versionCheck->localVersion); $this->assign('adminPanel', $adminPanel); $this->_showHide->addToTemplate(); return parent::run(); }
/** * Show the message about CiviCRM versions * * @param obj: $template (reference) */ static function versionCheck($template) { if (CRM_Core_Config::isUpgradeMode()) { return; } $versionCheck = CRM_Utils_VersionCheck::singleton(); $newerVersion = $versionCheck->newerVersion(); $template->assign('newer_civicrm_version', $newerVersion); }
/** * Static instance provider * * Method providing static instance of CRM_Utils_VersionCheck, * as in Singleton pattern * * @return CRM_Utils_VersionCheck */ static function &singleton() { if (!isset(self::$_singleton)) { self::$_singleton = new CRM_Utils_VersionCheck(); } return self::$_singleton; }
function run() { // ensure that all CiviCRM tables are InnoDB, else abort // this is not a very fast operation, so we do it randomly 10% of the times // but we do it for most / all tables // http://bugs.mysql.com/bug.php?id=43664 if (rand(1, 10) == 3 && CRM_Core_DAO::isDBMyISAM(150)) { $errorMessage = 'Your database is configured to use the MyISAM database engine. CiviCRM requires InnoDB. You will need to convert any MyISAM tables in your database to InnoDB. Using MyISAM tables will result in data integrity issues.'; CRM_Core_Session::setStatus($errorMessage); } if (!CRM_Utils_System::isDBVersionValid($errorMessage)) { CRM_Core_Session::setStatus($errorMessage); } $groups = array('Customize Data and Screens' => ts('Customize Data and Screens'), 'Communications' => ts('Communications'), 'Localization' => ts('Localization'), 'Users and Permissions' => ts('Users and Permissions'), 'System Settings' => ts('System Settings')); $config = CRM_Core_Config::singleton(); if (in_array('CiviContribute', $config->enableComponents)) { $groups['CiviContribute'] = ts('CiviContribute'); } if (in_array('CiviMember', $config->enableComponents)) { $groups['CiviMember'] = ts('CiviMember'); } if (in_array('CiviEvent', $config->enableComponents)) { $groups['CiviEvent'] = ts('CiviEvent'); } if (in_array('CiviMail', $config->enableComponents)) { $groups['CiviMail'] = ts('CiviMail'); } if (in_array('CiviCase', $config->enableComponents)) { $groups['CiviCase'] = ts('CiviCase'); } if (in_array('CiviReport', $config->enableComponents)) { $groups['CiviReport'] = ts('CiviReport'); } if (in_array('CiviCampaign', $config->enableComponents)) { $groups['CiviCampaign'] = ts('CiviCampaign'); } $values = CRM_Core_Menu::getAdminLinks(); $this->_showHide = new CRM_Core_ShowHideBlocks(); foreach ($groups as $group => $title) { $this->_showHide->addShow("id_{$group}_show"); $this->_showHide->addHide("id_{$group}"); $v = CRM_Core_ShowHideBlocks::links($this, $group, '', '', FALSE); if (isset($values[$group])) { $adminPanel[$group] = $values[$group]; $adminPanel[$group]['show'] = $v['show']; $adminPanel[$group]['hide'] = $v['hide']; $adminPanel[$group]['title'] = $title; } else { $adminPanel[$group] = array(); $adminPanel[$group]['show'] = ''; $adminPanel[$group]['hide'] = ''; $adminPanel[$group]['title'] = $title; } } $versionCheck = CRM_Utils_VersionCheck::singleton(); $this->assign('newVersion', $versionCheck->newerVersion()); $this->assign('localVersion', $versionCheck->localVersion); $this->assign('adminPanel', $adminPanel); $this->_showHide->addToTemplate(); return parent::run(); }
/** * Check for CiviCRM software updates. * * Anonymous site statistics are sent back to civicrm.org during this check. */ function civicrm_api3_job_version_check() { $vc = new CRM_Utils_VersionCheck(); $vc->fetch(); return civicrm_api3_create_success(); }
/** * Checks if new versions are available * @return array */ public function checkVersion() { $messages = array(); if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'versionAlert', NULL, 1)) { $vc = CRM_Utils_VersionCheck::singleton(); $newerVersion = $vc->isNewerVersionAvailable(); $title = ts('Update Status'); if ($newerVersion['version']) { $vInfo = array(1 => $newerVersion['version'], 2 => $vc->localVersion); // LTS = long-term support version if ($newerVersion['status'] == 'lts') { $vInfo[1] .= ' ' . ts('(long-term support)'); } if ($newerVersion['upgrade'] == 'security') { // Security $severity = \Psr\Log\LogLevel::CRITICAL; $title = ts('Security Update Required'); $message = ts('New security release %1 is available. The site is currently running %2.', $vInfo); } elseif ($newerVersion['status'] == 'eol') { // Warn about EOL $severity = \Psr\Log\LogLevel::WARNING; $title = ts('CiviCRM Update Needed'); $message = ts('New version %1 is available. The site is currently running %2, which has reached its end of life.', $vInfo); } else { // For most new versions, just make them notice $severity = \Psr\Log\LogLevel::NOTICE; $title = ts('CiviCRM Update Available'); $message = ts('New version %1 is available. The site is currently running %2.', $vInfo); } } else { $vNum = $vc->localVersion; // LTS = long-term support version if ($newerVersion['status'] == 'lts') { $vNum .= ' ' . ts('(long-term support)'); } $severity = \Psr\Log\LogLevel::INFO; $message = ts('Version %1 is up-to-date.', array(1 => $vNum)); } $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, $message, $title, $severity, 'fa-cloud-upload'); } else { $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('The check for new versions of CiviCRM has been disabled.'), ts('Update Check Disabled'), \Psr\Log\LogLevel::NOTICE, 'fa-times-circle-o'); } return $messages; }
/** * Checks if new versions are available * @return array */ public function checkVersion() { $messages = array(); if (Civi::settings()->get('versionCheck')) { $vc = CRM_Utils_VersionCheck::singleton(); $newerVersion = $vc->isNewerVersionAvailable(); if ($newerVersion['version']) { $vInfo = array(1 => $newerVersion['version'], 2 => $vc->localVersion); // LTS = long-term support version if ($newerVersion['status'] == 'lts') { $vInfo[1] .= ' ' . ts('(long-term support)'); } if ($newerVersion['upgrade'] == 'security') { // Security $severity = \Psr\Log\LogLevel::CRITICAL; $title = ts('CiviCRM Security Update Required'); $message = ts('New security release %1 is available. The site is currently running %2.', $vInfo); } elseif ($newerVersion['status'] == 'eol') { // Warn about EOL $severity = \Psr\Log\LogLevel::WARNING; $title = ts('CiviCRM Update Needed'); $message = ts('New version %1 is available. The site is currently running %2, which has reached its end of life.', $vInfo); } else { // For most new versions, just make them notice $severity = \Psr\Log\LogLevel::NOTICE; $title = ts('CiviCRM Update Available'); $message = ts('New version %1 is available. The site is currently running %2.', $vInfo); } } else { $vNum = $vc->localVersion; // LTS = long-term support version if ($newerVersion['status'] == 'lts') { $vNum .= ' ' . ts('(long-term support)'); } $severity = \Psr\Log\LogLevel::INFO; $title = ts('CiviCRM Up-to-Date'); $message = ts('CiviCRM version %1 is up-to-date.', array(1 => $vNum)); } $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, $message, $title, $severity, 'fa-cloud-upload'); } else { $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('The check for new versions of CiviCRM has been disabled. <a %1>Re-enable the setting</a> to receive important security update notifications.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/misc', 'reset=1'))), ts('Update Check Disabled'), \Psr\Log\LogLevel::NOTICE, 'fa-times-circle-o'); } return $messages; }
/** * This function takes care of all the things common to all * pages. This typically involves assigning the appropriate * smarty variable :) * * @return string The content generated by running this page */ function run() { if ($this->_embedded) { return; } self::$_template->assign('mode', $this->_mode); $pageTemplateFile = $this->getHookedTemplateFileName(); self::$_template->assign('tplFile', $pageTemplateFile); // invoke the pagRun hook, CRM-3906 CRM_Utils_Hook::pageRun($this); if ($this->_print) { if (in_array($this->_print, array(CRM_Core_Smarty::PRINT_SNIPPET, CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM, CRM_Core_Smarty::PRINT_JSON))) { $content = self::$_template->fetch('CRM/common/snippet.tpl'); } else { $content = self::$_template->fetch('CRM/common/print.tpl'); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $this->overrideExtraTemplateFileName()); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); if ($this->_print == CRM_Core_Smarty::PRINT_PDF) { CRM_Utils_PDF_Utils::html2pdf($content, "{$this->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape')); } elseif ($this->_print == CRM_Core_Smarty::PRINT_JSON) { $this->ajaxResponse['content'] = $content; CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse); } else { echo $content; } CRM_Utils_System::civiExit(); } $config = CRM_Core_Config::singleton(); // TODO: Is there a better way to ensure these actions don't happen during AJAX requests? if (empty($_GET['snippet'])) { // Version check and intermittent alert to admins CRM_Utils_VersionCheck::singleton()->versionAlert(); CRM_Utils_Check_Security::singleton()->showPeriodicAlerts(); // Debug msg once per hour if ($config->debug && CRM_Core_Permission::check('administer CiviCRM') && CRM_Core_Session::singleton()->timer('debug_alert', 3600)) { $msg = ts('Warning: Debug is enabled in <a href="%1">system settings</a>. This should not be enabled on production servers.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1'))); CRM_Core_Session::setStatus($msg, ts('Debug Mode')); } } $content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl'); // Render page header if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); echo CRM_Utils_System::theme($content, $this->_print); return; }
/** * Checks if new versions are available * @return array */ public function checkVersion() { $messages = array(); try { $vc = new CRM_Utils_VersionCheck(); $vc->initialize(); } catch (Exception $e) { $messages[] = new CRM_Utils_Check_Message('checkVersionError', ts('Directory %1 is not writable. Please change your file permissions.', array(1 => dirname($vc->cacheFile))), ts('Directory not writable'), \Psr\Log\LogLevel::ERROR, 'fa-times-circle-o'); return $messages; } // Show a notice if the version_check job is disabled if (empty($vc->cronJob['is_active'])) { $args = empty($vc->cronJob['id']) ? array('reset' => 1) : array('reset' => 1, 'action' => 'update', 'id' => $vc->cronJob['id']); $messages[] = new CRM_Utils_Check_Message('checkVersionDisabled', ts('The check for new versions of CiviCRM has been disabled. <a %1>Re-enable the scheduled job</a> to receive important security update notifications.', array(1 => 'href="' . CRM_Utils_System::url('civicrm/admin/job', $args) . '"')), ts('Update Check Disabled'), \Psr\Log\LogLevel::NOTICE, 'fa-times-circle-o'); } if ($vc->isInfoAvailable) { $newerVersion = $vc->isNewerVersionAvailable(); if ($newerVersion['version']) { $vInfo = array(1 => $newerVersion['version'], 2 => $vc->localVersion); // LTS = long-term support version if ($newerVersion['status'] == 'lts') { $vInfo[1] .= ' ' . ts('(long-term support)'); } if ($newerVersion['upgrade'] == 'security') { // Security $severity = \Psr\Log\LogLevel::CRITICAL; $title = ts('CiviCRM Security Update Required'); $message = ts('New security release %1 is available. The site is currently running %2.', $vInfo); } elseif ($newerVersion['status'] == 'eol') { // Warn about EOL $severity = \Psr\Log\LogLevel::WARNING; $title = ts('CiviCRM Update Needed'); $message = ts('New version %1 is available. The site is currently running %2, which has reached its end of life.', $vInfo); } else { // For most new versions, just make them notice $severity = \Psr\Log\LogLevel::NOTICE; $title = ts('CiviCRM Update Available'); $message = ts('New version %1 is available. The site is currently running %2.', $vInfo); } } elseif (!empty($vc->cronJob['is_active'])) { $vNum = $vc->localVersion; // LTS = long-term support version if ($newerVersion['status'] == 'lts') { $vNum .= ' ' . ts('(long-term support)'); } $severity = \Psr\Log\LogLevel::INFO; $title = ts('CiviCRM Up-to-Date'); $message = ts('CiviCRM version %1 is up-to-date.', array(1 => $vNum)); } if (!empty($message)) { $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, $message, $title, $severity, 'fa-cloud-upload'); } } return $messages; }
public function testCronFallback() { // Fake "remote" source data $tmpSrc = '/tmp/versionCheckTestFile.json'; file_put_contents($tmpSrc, json_encode($this->sampleVersionInfo)); $vc = new CRM_Utils_VersionCheck(); $vc->pingbackUrl = $tmpSrc; // If the cachefile doesn't exist, fallback should kick in if (file_exists($vc->cacheFile)) { unlink($vc->cacheFile); } $vc->initialize(); $this->assertEquals($this->sampleVersionInfo, $vc->versionInfo); unset($vc); // Update "remote" source data $remoteData = array('4.3' => $this->sampleVersionInfo['4.3']); file_put_contents($tmpSrc, json_encode($remoteData)); // Cache was just updated, so fallback should not happen - assert we are still using cached data $vc = new CRM_Utils_VersionCheck(); $vc->pingbackUrl = $tmpSrc; $vc->initialize(); $this->assertEquals($this->sampleVersionInfo, $vc->versionInfo); unset($vc); // Ensure fallback happens if file is too old $vc = new CRM_Utils_VersionCheck(); $vc->pingbackUrl = $tmpSrc; // Set cachefile to be 1 minute older than expire time touch($vc->cacheFile, time() - 60 - $vc::CACHEFILE_EXPIRE); clearstatcache(); $vc->initialize(); $this->assertEquals($remoteData, $vc->versionInfo); }
/** * This function takes care of all the things common to all * pages. This typically involves assigning the appropriate * smarty variable :) * * @return string The content generated by running this page */ function run() { if ($this->_embedded) { return; } self::$_template->assign('mode', $this->_mode); $pageTemplateFile = $this->getHookedTemplateFileName(); self::$_template->assign('tplFile', $pageTemplateFile); // invoke the pagRun hook, CRM-3906 CRM_Utils_Hook::pageRun($this); if ($this->_print) { if (in_array($this->_print, array(CRM_Core_Smarty::PRINT_SNIPPET, CRM_Core_Smarty::PRINT_PDF, CRM_Core_Smarty::PRINT_NOFORM, CRM_Core_Smarty::PRINT_JSON))) { $content = self::$_template->fetch('CRM/common/snippet.tpl'); } else { $content = self::$_template->fetch('CRM/common/print.tpl'); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content, $this->overrideExtraTemplateFileName()); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); if ($this->_print == CRM_Core_Smarty::PRINT_PDF) { CRM_Utils_PDF_Utils::html2pdf($content, "{$this->_name}.pdf", FALSE, array('paper_size' => 'a3', 'orientation' => 'landscape')); } elseif ($this->_print == CRM_Core_Smarty::PRINT_JSON) { $this->ajaxResponse['content'] = $content; CRM_Core_Page_AJAX::returnJsonResponse($this->ajaxResponse); } else { echo $content; } CRM_Utils_System::civiExit(); } $config = CRM_Core_Config::singleton(); // Version check and intermittent alert to admins CRM_Utils_VersionCheck::singleton()->versionAlert(); CRM_Utils_Check::singleton()->showPeriodicAlerts(); if ($this->useLivePageJS && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'ajaxPopupsEnabled', NULL, TRUE)) { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); $this->assign('includeWysiwygEditor', TRUE); } $content = self::$_template->fetch('CRM/common/' . strtolower($config->userFramework) . '.tpl'); // Render page header if (!defined('CIVICRM_UF_HEAD') && ($region = CRM_Core_Region::instance('html-header', FALSE))) { CRM_Utils_System::addHTMLHead($region->render('')); } CRM_Utils_System::appendTPLFile($pageTemplateFile, $content); //its time to call the hook. CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this); echo CRM_Utils_System::theme($content, $this->_print); return; }
/** * Show the message about CiviCRM versions. * * @param CRM_Core_Smarty $template */ public static function versionCheck($template) { if (CRM_Core_Config::isUpgradeMode()) { return; } $newerVersion = $securityUpdate = NULL; if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'versionAlert', NULL, 1) & 1) { $newerVersion = CRM_Utils_VersionCheck::singleton()->isNewerVersionAvailable(); } if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityUpdateAlert', NULL, 3) & 1) { $securityUpdate = CRM_Utils_VersionCheck::singleton()->isSecurityUpdateAvailable(); } $template->assign('newer_civicrm_version', $newerVersion); $template->assign('security_update', $securityUpdate); }