예제 #1
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     global $civicrm_root;
     $config = CRM_Core_Config::singleton();
     $localFile = $civicrm_root . DIRECTORY_SEPARATOR . self::LOCALFILE_NAME;
     $this->cacheFile = $config->uploadDir . self::CACHEFILE_NAME;
     if (file_exists($localFile)) {
         require_once $localFile;
     }
     if (function_exists('civicrmVersion')) {
         $info = civicrmVersion();
         $this->localVersion = trim($info['version']);
         $this->localMajorVersion = $this->getMajorVersion($this->localVersion);
     }
     // Populate $versionInfo
     if (Civi::settings()->get('versionCheck')) {
         // Use cached data if available and not stale
         if (!$this->readCacheFile()) {
             // Collect stats for pingback
             $this->getSiteStats();
             // Get the latest version and send site info
             $this->pingBack();
         }
         // Sort version info in ascending order for easier comparisons
         ksort($this->versionInfo, SORT_NUMERIC);
     }
 }
예제 #2
0
function is_civi_newer($version)
{
    $installedVersion = civicrmVersion();
    $installedVersion = $installedVersion['version'];
    list($installedMajor, $installedMinor, ) = explode('.', $installedVersion);
    list($major, $minor) = explode('.', $version);
    if ($installedMajor == $major) {
        return $installedMinor >= $minor;
    } else {
        if ($installedMajor > $major) {
            return true;
        } else {
            return false;
        }
    }
    return true;
}
예제 #3
0
 /**
  * Class constructor
  *
  * @access private
  */
 function __construct()
 {
     global $civicrm_root;
     $config = CRM_Core_Config::singleton();
     $localfile = $civicrm_root . DIRECTORY_SEPARATOR . self::LOCALFILE_NAME;
     $cachefile = $config->uploadDir . self::CACHEFILE_NAME;
     if (file_exists($localfile)) {
         require_once $localfile;
         if (function_exists('civicrmVersion')) {
             $info = civicrmVersion();
             $this->localVersion = trim($info['version']);
         }
     }
     if ($config->versionCheck) {
         $expiryTime = time() - self::CACHEFILE_EXPIRE;
         // if there's a cachefile and it's not stale use it to
         // read the latestVersion, else read it from the Internet
         if (file_exists($cachefile) && filemtime($cachefile) > $expiryTime) {
             $this->latestVersion = trim(file_get_contents($cachefile));
         } else {
             $siteKey = md5(defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : '');
             $this->stats = array('hash' => md5($siteKey . $config->userFrameworkBaseURL), 'version' => $this->localVersion, 'uf' => $config->userFramework, 'lang' => $config->lcMessages, 'co' => $config->defaultContactCountry, 'ufv' => $config->userFrameworkVersion, 'PHP' => phpversion(), 'MySQL' => CRM_CORE_DAO::singleValueQuery('SELECT VERSION()'), 'communityMessagesUrl' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'communityMessagesUrl', NULL, '*default*'));
             // Add usage stats
             $this->payProcStats();
             $this->entityStats();
             $this->extensionStats();
             // Get the latest version and send site info
             $this->pingBack();
             // Update cache file
             if ($this->latestVersion) {
                 $fp = @fopen($cachefile, 'w');
                 if (!$fp) {
                     if (CRM_Core_Permission::check('administer CiviCRM')) {
                         CRM_Core_Session::setStatus(ts('Unable to write file') . ":{$cachefile}<br />" . ts('Please check your system file permissions.'), ts('File Error'), 'error');
                     }
                     return;
                 }
                 fwrite($fp, $this->latestVersion);
                 fclose($fp);
             }
         }
     }
 }
예제 #4
0
}
// Exit with error if CiviCRM has already been installed.
if ($alreadyInstalled) {
    $errorTitle = ts("Oops! CiviCRM is already installed");
    $settings_directory = $cmsPath;
    if ($installType == 'drupal') {
        $settings_directory = implode(CIVICRM_DIRECTORY_SEPARATOR, array(ts('[your Drupal root directory]'), 'sites', $siteDir));
    }
    $docLink = CRM_Utils_System::docURL2('Installation and Upgrades', FALSE, ts('Installation Guide'), NULL, NULL, "wiki");
    $errorMsg = ts("CiviCRM has already been installed. <ul><li>To <strong>start over</strong>, you must delete or rename the existing CiviCRM settings file - <strong>civicrm.settings.php</strong> - from <strong>%1</strong>.</li><li>To <strong>upgrade an existing installation</strong>, <a href='%2'>refer to the online documentation</a>.</li></ul>", array(1 => $settings_directory, 2 => $docLink));
    errorDisplayPage($errorTitle, $errorMsg, FALSE);
}
$versionFile = $crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'civicrm-version.php';
if (file_exists($versionFile)) {
    require_once $versionFile;
    $civicrm_version = civicrmVersion();
} else {
    $civicrm_version = 'unknown';
}
if ($installType == 'drupal') {
    // Ensure that they have downloaded the correct version of CiviCRM
    if ($civicrm_version['cms'] != 'Drupal' && $civicrm_version['cms'] != 'Drupal6') {
        $errorTitle = ts("Oops! Incorrect CiviCRM version");
        $errorMsg = ts("This installer can only be used for the Drupal version of CiviCRM.");
        errorDisplayPage($errorTitle, $errorMsg);
    }
    define('DRUPAL_ROOT', $cmsPath);
    $drupalVersionFiles = array(implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'modules', 'system', 'system.module')), implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'includes', 'bootstrap.inc')));
    foreach ($drupalVersionFiles as $drupalVersionFile) {
        if (file_exists($drupalVersionFile)) {
            require_once $drupalVersionFile;
예제 #5
0
 /**
  * Return the running civicrm version.
  *
  * @return string
  *   civicrm version
  */
 public static function version()
 {
     static $version;
     if (!$version) {
         $verFile = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', '..', 'civicrm-version.php'));
         if (file_exists($verFile)) {
             require_once $verFile;
             if (function_exists('civicrmVersion')) {
                 $info = civicrmVersion();
                 $version = $info['version'];
             }
         } else {
             // svn installs don't have version.txt by default. In that case version.xml should help -
             $verFile = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', '..', 'xml', 'version.xml'));
             if (file_exists($verFile)) {
                 $str = file_get_contents($verFile);
                 $xmlObj = simplexml_load_string($str);
                 $version = (string) $xmlObj->version_no;
             }
         }
         // pattern check
         if (!CRM_Utils_System::isVersionFormatValid($version)) {
             CRM_Core_Error::fatal('Unknown codebase version.');
         }
     }
     return $version;
 }
 /**
  * Class constructor
  *
  * @access private
  */
 function __construct()
 {
     global $civicrm_root;
     $config = CRM_Core_Config::singleton();
     $localfile = $civicrm_root . DIRECTORY_SEPARATOR . self::LOCALFILE_NAME;
     $cachefile = $config->uploadDir . self::CACHEFILE_NAME;
     if ($config->versionCheck && file_exists($localfile)) {
         require_once $localfile;
         if (function_exists('civicrmVersion')) {
             $info = civicrmVersion();
             $this->localVersion = $info['version'];
         }
         $expiryTime = time() - self::CACHEFILE_EXPIRE;
         // if there's a cachefile and it's not stale use it to
         // read the latestVersion, else read it from the Internet
         if (file_exists($cachefile) and filemtime($cachefile) > $expiryTime) {
             $this->latestVersion = file_get_contents($cachefile);
         } else {
             // we have to set the error handling to a dummy function, otherwise
             // if the URL is not working (e.g., due to our server being down)
             // the users would be presented with an unsuppressable warning
             ini_set('default_socket_timeout', self::CHECK_TIMEOUT);
             set_error_handler(array('CRM_Utils_VersionCheck', 'downloadError'));
             $hash = md5($config->userFrameworkBaseURL);
             $url = self::LATEST_VERSION_AT . "?version={$this->localVersion}&uf={$config->userFramework}&hash={$hash}&lang={$config->lcMessages}&ufv={$config->userFrameworkVersion}";
             // add PHP and MySQL versions
             $dao = new CRM_Core_DAO();
             $dao->query('SELECT VERSION() AS version');
             $dao->fetch();
             $url .= '&MySQL=' . $dao->version . '&PHP=' . phpversion();
             $tables = array('CRM_Activity_DAO_Activity' => 'is_test = 0', 'CRM_Case_DAO_Case' => NULL, 'CRM_Contact_DAO_Contact' => NULL, 'CRM_Contact_DAO_Relationship' => NULL, 'CRM_Contribute_DAO_Contribution' => 'is_test = 0', 'CRM_Contribute_DAO_ContributionPage' => 'is_active = 1', 'CRM_Contribute_DAO_ContributionProduct' => NULL, 'CRM_Contribute_DAO_Widget' => 'is_active = 1', 'CRM_Core_DAO_Discount' => NULL, 'CRM_Price_DAO_SetEntity' => NULL, 'CRM_Core_DAO_UFGroup' => 'is_active = 1', 'CRM_Event_DAO_Event' => 'is_active = 1', 'CRM_Event_DAO_Participant' => 'is_test = 0', 'CRM_Friend_DAO_Friend' => 'is_active = 1', 'CRM_Grant_DAO_Grant' => NULL, 'CRM_Mailing_DAO_Mailing' => 'is_completed = 1', 'CRM_Member_DAO_Membership' => 'is_test = 0', 'CRM_Member_DAO_MembershipBlock' => 'is_active = 1', 'CRM_Pledge_DAO_Pledge' => 'is_test = 0', 'CRM_Pledge_DAO_PledgeBlock' => NULL);
             // add &key=count pairs to $url, where key is the last part of the DAO
             foreach ($tables as $daoName => $where) {
                 require_once str_replace('_', '/', $daoName) . '.php';
                 eval("\$dao = new {$daoName};");
                 if ($where) {
                     $dao->whereAdd($where);
                 }
                 $url .= '&' . array_pop(explode('_', $daoName)) . "={$dao->count()}";
             }
             // get active payment processor types
             $dao = new CRM_Core_DAO_PaymentProcessor();
             $dao->is_active = 1;
             $dao->find();
             $ppTypes = array();
             while ($dao->fetch()) {
                 $ppTypes[] = $dao->payment_processor_type;
             }
             // add the .-separated list of the processor types (urlencoded just in case)
             $url .= '&PPTypes=' . urlencode(implode('.', array_unique($ppTypes)));
             // get the latest version using the stats-carrying $url
             $this->latestVersion = file_get_contents($url);
             ini_restore('default_socket_timeout');
             restore_error_handler();
             if (!preg_match('/^\\d+\\.\\d+\\.\\d+$/', $this->latestVersion)) {
                 $this->latestVersion = NULL;
             }
             if (!$this->latestVersion) {
                 return;
             }
             $fp = @fopen($cachefile, 'w');
             if (!$fp) {
                 $message = ts('Do not have permission to write to file: %1', array(1 => $cachefile));
                 CRM_Core_Session::setStatus($message);
                 return;
             }
             fwrite($fp, $this->latestVersion);
             fclose($fp);
         }
     }
 }