/**
  * 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);
         }
     }
 }
Esempio n. 2
0
/**
 * Converts an DAO object to an array.
 *
 * @param CRM_Core_DAO $dao
 *   Object to convert.
 * @param array $params
 * @param bool $uniqueFields
 * @param string $entity
 * @param bool $autoFind
 *
 * @return array
 */
function _civicrm_api3_dao_to_array($dao, $params = NULL, $uniqueFields = TRUE, $entity = "", $autoFind = TRUE)
{
    $result = array();
    if (isset($params['options']) && !empty($params['options']['is_count'])) {
        return $dao->count();
    }
    if (empty($dao)) {
        return array();
    }
    if ($autoFind && !$dao->find()) {
        return array();
    }
    if (isset($dao->count)) {
        return $dao->count;
    }
    $fields = array_keys(_civicrm_api3_build_fields_array($dao, $uniqueFields));
    while ($dao->fetch()) {
        $tmp = array();
        foreach ($fields as $key) {
            if (array_key_exists($key, $dao)) {
                // not sure on that one
                if ($dao->{$key} !== NULL) {
                    $tmp[$key] = $dao->{$key};
                }
            }
        }
        $result[$dao->id] = $tmp;
        if (_civicrm_api3_custom_fields_are_required($entity, $params)) {
            _civicrm_api3_custom_data_get($result[$dao->id], $entity, $dao->id);
        }
    }
    return $result;
}