本文整理汇总了PHP中CRM_Core_DAO::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO::fetch方法的具体用法?PHP CRM_Core_DAO::fetch怎么用?PHP CRM_Core_DAO::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_DAO
的用法示例。
在下文中一共展示了CRM_Core_DAO::fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: defined
function __construct()
{
// don’t display the ‘Add these Contacts to Group’ button
$this->_add2groupSupported = FALSE;
$dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN);
$this->db = $dsn['database'];
$this->log_conn_id = CRM_Utils_Request::retrieve('log_conn_id', 'Integer', CRM_Core_DAO::$_nullObject);
$this->log_date = CRM_Utils_Request::retrieve('log_date', 'String', CRM_Core_DAO::$_nullObject);
$this->cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
$this->raw = CRM_Utils_Request::retrieve('raw', 'Boolean', CRM_Core_DAO::$_nullObject);
parent::__construct();
CRM_Utils_System::resetBreadCrumb();
$breadcrumb = array(array('title' => ts('Home'), 'url' => CRM_Utils_System::url()), array('title' => ts('CiviCRM'), 'url' => CRM_Utils_System::url('civicrm', 'reset=1')), array('title' => ts('View Contact'), 'url' => CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->cid}")), array('title' => ts('Search Results'), 'url' => CRM_Utils_System::url('civicrm/contact/search', "force=1")));
CRM_Utils_System::appendBreadCrumb($breadcrumb);
if (CRM_Utils_Request::retrieve('revert', 'Boolean', CRM_Core_DAO::$_nullObject)) {
$reverter = new CRM_Logging_Reverter($this->log_conn_id, $this->log_date);
$reverter->revert($this->tables);
CRM_Core_Session::setStatus(ts('The changes have been reverted.'));
if ($this->cid) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view', "reset=1&selectedChild=log&cid={$this->cid}", FALSE, NULL, FALSE));
} else {
CRM_Utils_System::redirect(CRM_Report_Utils_Report::getNextUrl($this->summary, 'reset=1', FALSE, TRUE));
}
}
// make sure the report works even without the params
if (!$this->log_conn_id or !$this->log_date) {
$dao = new CRM_Core_DAO();
$dao->query("SELECT log_conn_id, log_date FROM `{$this->db}`.log_{$this->tables[0]} WHERE log_action = 'Update' ORDER BY log_date DESC LIMIT 1");
$dao->fetch();
$this->log_conn_id = $dao->log_conn_id;
$this->log_date = $dao->log_date;
}
$this->_columnHeaders = array('field' => array('title' => ts('Field')), 'from' => array('title' => ts('Changed From')), 'to' => array('title' => ts('Changed To')));
}
示例2: buildQuickForm
public function buildQuickForm()
{
$config = CRM_Core_Config::singleton();
global $tsLocale;
$this->_locales = array_keys($config->languageLimit);
// get the part of the database we want to edit and validate it
$table = CRM_Utils_Request::retrieve('table', 'String', $this);
$field = CRM_Utils_Request::retrieve('field', 'String', $this);
$id = CRM_Utils_Request::retrieve('id', 'Int', $this);
$this->_structure = CRM_Core_I18n_SchemaStructure::columns();
if (!isset($this->_structure[$table][$field])) {
CRM_Core_Error::fatal("{$table}.{$field} is not internationalized.");
}
$this->addElement('hidden', 'table', $table);
$this->addElement('hidden', 'field', $field);
$this->addElement('hidden', 'id', $id);
$cols = array();
foreach ($this->_locales as $locale) {
$cols[] = "{$field}_{$locale} {$locale}";
}
$query = 'SELECT ' . implode(', ', $cols) . " FROM {$table} WHERE id = {$id}";
$dao = new CRM_Core_DAO();
$dao->query($query, FALSE);
$dao->fetch();
// get html type and attributes for this field
$widgets = CRM_Core_I18n_SchemaStructure::widgets();
$widget = $widgets[$table][$field];
// attributes
$attributes = array('class' => '');
if (isset($widget['rows'])) {
$attributes['rows'] = $widget['rows'];
}
if (isset($widget['cols'])) {
$attributes['cols'] = $widget['cols'];
}
$required = !empty($widget['required']);
if ($widget['type'] == 'RichTextEditor') {
$widget['type'] = 'wysiwyg';
$attributes['class'] .= ' collapsed';
}
$languages = CRM_Core_I18n::languages(TRUE);
foreach ($this->_locales as $locale) {
$attr = $attributes;
$name = "{$field}_{$locale}";
if ($locale == $tsLocale) {
$attr['class'] .= ' default-lang';
}
$this->add($widget['type'], $name, $languages[$locale], $attr, $required);
$this->_defaults[$name] = $dao->{$locale};
}
$this->addDefaultButtons(ts('Save'), 'next', NULL);
CRM_Utils_System::setTitle(ts('Languages'));
$this->assign('locales', $this->_locales);
$this->assign('field', $field);
}
示例3: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
$values = $ids = array();
$params = array('id' => $this->get('id'));
CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids);
$values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
$sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
$dao = new CRM_Core_DAO();
$dao->query($sql);
if ($dao->fetch()) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
$values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
}
$honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id');
$values['honor_type'] = $honor[$values['honor_type_id']];
}
//handle custom data.
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
if (!empty($values['contribution_page_id'])) {
$values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
}
$values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType());
if ($values['status_id']) {
$values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus());
}
$url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
}
if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
}
$displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
$this->assign('displayName', $displayName);
$title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['financial_type'] . ')';
// add Pledge to Recent Items
CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], NULL, $recentOther);
// Check if this is default domain contact CRM-10482
if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
$displayName .= ' (' . ts('default organization') . ')';
}
// omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
CRM_Utils_System::setTitle(ts('View Pledge by') . ' ' . $displayName);
//do check for campaigns
if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
$values['campaign'] = $campaigns[$campaignId];
}
$this->assign($values);
}
示例4: setDefaultValues
function setDefaultValues()
{
$defaults = parent::setDefaultValues();
if (!CRM_Utils_Array::value('weight', $defaults)) {
$query = "SELECT max( `weight` ) as weight FROM `civicrm_booking_resource_config_set`";
$dao = new CRM_Core_DAO();
$dao->query($query);
$dao->fetch();
$defaults['weight'] = $dao->weight + 1;
}
return $defaults;
}
示例5: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
require_once 'CRM/Pledge/BAO/Pledge.php';
$values = $ids = array();
$params = array('id' => $this->get('id'));
CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids);
$values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
$sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
$dao = new CRM_Core_DAO();
$dao->query($sql);
if ($dao->fetch()) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
$values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
}
$honor = CRM_Core_PseudoConstant::honor();
$values['honor_type'] = $honor[$values['honor_type_id']];
}
//handle custom data.
$groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
if (CRM_Utils_Array::value('contribution_page_id', $values)) {
$values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
}
$values['contribution_type'] = CRM_Utils_Array::value($values['contribution_type_id'], CRM_Contribute_PseudoConstant::contributionType());
if ($values['status_id']) {
$values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus());
}
require_once 'CRM/Utils/Recent.php';
require_once 'CRM/Contact/BAO/Contact.php';
$url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
}
if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
}
require_once 'CRM/Utils/Money.php';
$displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
$this->assign('displayName', $displayName);
$title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['contribution_type'] . ')';
// add Pledge to Recent Items
CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], null, $recentOther);
$this->assign($values);
}
示例6: defined
function __construct()
{
$this->_add2groupSupported = false;
// don’t display the ‘Add these Contacts to Group’ button
$dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN);
$this->loggingDB = $dsn['database'];
$this->log_conn_id = CRM_Utils_Request::retrieve('log_conn_id', 'Integer', CRM_Core_DAO::$_nullObject);
$this->log_date = CRM_Utils_Request::retrieve('log_date', 'String', CRM_Core_DAO::$_nullObject);
// make sure the report works even without the params
if (!$this->log_conn_id or !$this->log_date) {
$dao = new CRM_Core_DAO();
$dao->query("SELECT log_conn_id, log_date FROM `{$this->loggingDB}`.log_civicrm_contact WHERE log_action = 'Update' ORDER BY log_date DESC LIMIT 1");
$dao->fetch();
$this->log_conn_id = $dao->log_conn_id;
$this->log_date = $dao->log_date;
}
$this->_columnHeaders = array('field' => array('title' => ts('Field')), 'from' => array('title' => ts('Changed From')), 'to' => array('title' => ts('Changed To')));
parent::__construct();
}
示例7: buildQuickForm
function buildQuickForm()
{
$config = CRM_Core_Config::singleton();
$this->_locales = array_keys($config->languageLimit);
// get the part of the database we want to edit and validate it
$table = CRM_Utils_Request::retrieve('table', 'String', $this);
$field = CRM_Utils_Request::retrieve('field', 'String', $this);
$id = CRM_Utils_Request::retrieve('id', 'Int', $this);
$this->_structure = CRM_Core_I18n_SchemaStructure::columns();
if (!isset($this->_structure[$table][$field])) {
CRM_Core_Error::fatal("{$table}.{$field} is not internationalized.");
}
$this->addElement('hidden', 'table', $table);
$this->addElement('hidden', 'field', $field);
$this->addElement('hidden', 'id', $id);
$cols = array();
foreach ($this->_locales as $locale) {
$cols[] = "{$field}_{$locale} {$locale}";
}
$query = 'SELECT ' . implode(', ', $cols) . " FROM {$table} WHERE id = {$id}";
$dao = new CRM_Core_DAO();
$dao->query($query, FALSE);
$dao->fetch();
// we want TEXTAREAs for long fields and INPUTs for short ones
$this->_structure[$table][$field] == 'text' ? $type = 'textarea' : ($type = 'text');
$languages = CRM_Core_I18n::languages(TRUE);
foreach ($this->_locales as $locale) {
$this->addElement($type, "{$field}_{$locale}", $languages[$locale], array('cols' => 60, 'rows' => 3));
$this->_defaults["{$field}_{$locale}"] = $dao->{$locale};
}
$this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE)));
global $tsLocale;
$this->assign('tsLocale', $tsLocale);
$this->assign('locales', $this->_locales);
$this->assign('field', $field);
$this->assign('context', CRM_Utils_Request::retrieve('context', 'String', $this));
}
示例8: array
/**
* @param CRM_Core_DAO $dao
* @param bool $flip
* @param bool $grouping
* @param bool $localize
* @param string $valueColumnName
*
* @return array
*/
public static function &valuesCommon($dao, $flip = FALSE, $grouping = FALSE, $localize = FALSE, $valueColumnName = 'label')
{
self::$_values = array();
while ($dao->fetch()) {
if ($flip) {
if ($grouping) {
self::$_values[$dao->value] = $dao->grouping;
} else {
self::$_values[$dao->{$valueColumnName}] = $dao->value;
}
} else {
if ($grouping) {
self::$_values[$dao->{$valueColumnName}] = $dao->grouping;
} else {
self::$_values[$dao->value] = $dao->{$valueColumnName};
}
}
}
if ($localize) {
$i18n = CRM_Core_I18n::singleton();
$i18n->localizeArray(self::$_values);
}
return self::$_values;
}
示例9: getZipCodeInfo
static function getZipCodeInfo()
{
$stateID = mt_rand(1000, 5132);
$offset = mt_rand(1, 4132);
$query = "SELECT id, country_id from civicrm_state_province LIMIT {$offset}, 1";
$dao = new CRM_Core_DAO();
$dao->query($query);
while ($dao->fetch()) {
return array($dao->country_id, $dao->id);
}
return array();
}
示例10: getTotalCount
/**
* Get row count for the event selector.
*
* @param int $mailing_id
* ID of the mailing.
* @param int $job_id
* Optional ID of a job to filter on.
* @param bool $is_distinct
* Group by queue ID?.
*
* @param string $org_unsubscribe
*
* @param string $toDate
*
* @return int
* Number of rows in result set
*/
public static function getTotalCount($mailing_id, $job_id = NULL, $is_distinct = FALSE, $org_unsubscribe = NULL, $toDate = NULL)
{
$dao = new CRM_Core_DAO();
$unsub = self::$_tableName;
$queueObject = new CRM_Mailing_Event_BAO_Queue();
$queue = $queueObject->getTableName();
$mailingObject = new CRM_Mailing_BAO_Mailing();
$mailing = $mailingObject->getTableName();
$jobObject = new CRM_Mailing_BAO_MailingJob();
$job = $jobObject->getTableName();
$query = "\n SELECT COUNT({$unsub}.id) as unsubs\n FROM {$unsub}\n INNER JOIN {$queue}\n ON {$unsub}.event_queue_id = {$queue}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n AND {$job}.is_test = 0\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
if (!empty($toDate)) {
$query .= " AND {$unsub}.time_stamp <= {$toDate}";
}
if (!empty($job_id)) {
$query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
if ($org_unsubscribe !== NULL) {
$query .= " AND {$unsub}.org_unsubscribe = " . ($org_unsubscribe ? 0 : 1);
}
if ($is_distinct) {
$query .= " GROUP BY {$queue}.id ";
}
$dao->query($query);
$dao->fetch();
if ($is_distinct) {
return $dao->N;
} else {
return $dao->unsubs ? $dao->unsubs : 0;
}
}
示例11: getZipCodeInfo
/**
* @return array
*/
public function getZipCodeInfo()
{
if (!$this->stateMap) {
$query = 'SELECT id, name, abbreviation from civicrm_state_province where country_id = 1228';
$dao = new CRM_Core_DAO();
$dao->query($query);
$this->stateMap = array();
while ($dao->fetch()) {
$this->stateMap[$dao->abbreviation] = $dao->id;
$this->states[$dao->id] = $dao->name;
}
$dao->free();
}
$offset = mt_rand(1, 43000);
$query = "SELECT city, state, zip, latitude, longitude FROM zipcodes LIMIT {$offset}, 1";
$dao = new CRM_Core_DAO();
$dao->query($query);
while ($dao->fetch()) {
if ($this->stateMap[$dao->state]) {
$stateID = $this->stateMap[$dao->state];
} else {
$stateID = 1004;
}
$zip = str_pad($dao->zip, 5, '0', STR_PAD_LEFT);
return array(1228, $stateID, $dao->city, $zip, $dao->latitude, $dao->longitude);
}
}
示例12: ON
/**
* function to get the information to map a event
*
* @param array $ids the list of ids for which we want map info
*
* @return null|string title of the event
* @static
* @access public
*/
static function &getMapInfo(&$id)
{
$sql = "\nSELECT \n civicrm_event.id AS event_id, \n civicrm_event.title AS display_name, \n civicrm_address.street_address AS street_address, \n civicrm_address.city AS city, \n civicrm_address.postal_code AS postal_code, \n civicrm_address.postal_code_suffix AS postal_code_suffix, \n civicrm_address.geo_code_1 AS latitude, \n civicrm_address.geo_code_2 AS longitude, \n civicrm_state_province.abbreviation AS state, \n civicrm_country.name AS country, \n civicrm_location_type.name AS location_type\nFROM \n civicrm_event\n LEFT JOIN civicrm_loc_block ON ( civicrm_event.loc_block_id = civicrm_loc_block.id )\n LEFT JOIN civicrm_address ON ( civicrm_loc_block.address_id = civicrm_address.id )\n LEFT JOIN civicrm_state_province ON ( civicrm_address.state_province_id = civicrm_state_province.id )\n LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id\n LEFT JOIN civicrm_location_type ON ( civicrm_location_type.id = civicrm_address.location_type_id )\nWHERE civicrm_address.geo_code_1 IS NOT NULL \n AND civicrm_address.geo_code_2 IS NOT NULL \n AND civicrm_event.id = " . CRM_Utils_Type::escape($id, 'Integer');
$dao = new CRM_Core_DAO();
$dao->query($sql);
$locations = array();
$config = CRM_Core_Config::singleton();
while ($dao->fetch()) {
$location = array();
$location['displayName'] = addslashes($dao->display_name);
$location['lat'] = $dao->latitude;
$location['marker_class'] = 'Event';
$location['lng'] = $dao->longitude;
$address = '';
CRM_Utils_String::append($address, '<br />', array($dao->street_address, $dao->city));
CRM_Utils_String::append($address, ', ', array($dao->state, $dao->postal_code));
CRM_Utils_String::append($address, '<br /> ', array($dao->country));
$location['address'] = addslashes($address);
$location['url'] = CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id);
$location['location_type'] = $dao->location_type;
$eventImage = '<img src="' . $config->resourceBase . 'i/contact_org.gif" alt="Organization " height="20" width="15" />';
$location['image'] = $eventImage;
$location['displayAddress'] = str_replace('<br />', ', ', $address);
$locations[] = $location;
}
return $locations;
}
示例13: getDisplayAndImage
/**
* Get the display name and image of a contact.
*
* @param int $id
* The contactId.
*
* @param bool $includeTypeInReturnParameters
* Should type be part of the returned array?
*
* @return array
* the displayName and contactImage for this contact
*/
public static function getDisplayAndImage($id, $includeTypeInReturnParameters = FALSE)
{
//CRM-14276 added the * on the civicrm_contact table so that we have all the contact info available
$sql = "\nSELECT civicrm_contact.*,\n civicrm_email.email as email\nFROM civicrm_contact\nLEFT JOIN civicrm_email ON civicrm_email.contact_id = civicrm_contact.id\n AND civicrm_email.is_primary = 1\nWHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer');
$dao = new CRM_Core_DAO();
$dao->query($sql);
if ($dao->fetch()) {
$image = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? $dao->contact_sub_type : $dao->contact_type, FALSE, $id);
$imageUrl = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? $dao->contact_sub_type : $dao->contact_type, TRUE, $id);
// use email if display_name is empty
if (empty($dao->display_name)) {
$displayName = $dao->email;
} else {
$displayName = $dao->display_name;
}
CRM_Utils_Hook::alterDisplayName($displayName, $id, $dao);
return $includeTypeInReturnParameters ? array($displayName, $image, $dao->contact_type, $dao->contact_sub_type, $imageUrl) : array($displayName, $image, $imageUrl);
}
return NULL;
}
示例14: civicrmVersion
/**
* 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);
}
}
}
示例15: rebuildMultilingualSchema
/**
* Rebuild multilingual indices, views and triggers (useful for upgrades)
*
* @param $locales array locales to be rebuilt
* @param $version string version of schema structure to use
* @return void
*/
static function rebuildMultilingualSchema($locales, $version = null)
{
if ($version) {
// fetch all the SchemaStructure versions we ship and sort by version
$schemas = array();
foreach (scandir(dirname(__FILE__)) as $file) {
$matches = array();
if (preg_match('/^SchemaStructure_([0-9a-z_]+)\\.php$/', $file, $matches)) {
$schemas[] = str_replace('_', '.', $matches[1]);
}
}
usort($schemas, 'version_compare');
// find the latest schema structure older than (or equal to) $version
do {
$latest = array_pop($schemas);
} while (version_compare($latest, $version, '>'));
$latest = str_replace('.', '_', $latest);
$class = "CRM_Core_I18n_SchemaStructure_{$latest}";
require_once "CRM/Core/I18n/SchemaStructure_{$latest}.php";
} else {
$class = 'CRM_Core_I18n_SchemaStructure';
require_once 'CRM/Core/I18n/SchemaStructure.php';
}
eval("\$indices =& {$class}::indices();");
eval("\$tables =& {$class}::tables();");
$queries = array();
$dao = new CRM_Core_DAO();
// get all of the already existing indices
$existing = array();
foreach (array_keys($indices) as $table) {
$existing[$table] = array();
$dao->query("SHOW INDEX FROM {$table}", false);
while ($dao->fetch()) {
if (preg_match('/_[a-z][a-z]_[A-Z][A-Z]$/', $dao->Key_name)) {
$existing[$table][] = $dao->Key_name;
}
}
}
// from all of the CREATE INDEX queries fetch the ones creating missing indices
foreach ($locales as $locale) {
foreach (array_keys($indices) as $table) {
$allQueries = self::createIndexQueries($locale, $table, $class);
foreach ($allQueries as $name => $query) {
if (!in_array("{$name}_{$locale}", $existing[$table])) {
$queries[] = $query;
}
}
}
}
// rebuild views
foreach ($locales as $locale) {
foreach ($tables as $table) {
$queries[] = self::createViewQuery($locale, $table, $dao, $class);
}
}
// rebuild triggers
$last = array_pop($locales);
$queries = array_merge($queries, self::createTriggerQueries($locales, $last, $class));
foreach ($queries as $query) {
$dao->query($query, false);
}
}