/**
  * Returns the group IDs corresponding to the group information returned
  * by the CiviCRM API.
  *
  * The behaviour of the API changed in CiviCRM 4.7.11, see issue #240.
  *
  * @param string $api_group_result As output by the CiviCRM api for a contact
  * when you request the 'group' output (which comes in a key called 'groups').
  * @param array $group_details As from CRM_Mailchimp_Utils::getGroupsToSync
  * but only including groups you're interested in.
  * @return array CiviCRM groupIds.
  */
 public static function getGroupIds($api_group_result, $group_details)
 {
     if (version_compare(CRM_Utils_System::version(), '4.7.11', '<')) {
         return self::splitGroupTitles($api_group_result, $group_details);
     }
     return array_filter(explode(',', $api_group_result));
 }
Пример #2
0
 function verifyPreDBState(&$errorMessage)
 {
     $latestVer = CRM_Utils_System::version();
     $errorMessage = ts('Pre-condition failed for upgrade to %1.', array(1 => $latestVer));
     // check table, if the db is 3.1
     if (CRM_Core_DAO::checkTableExists('civicrm_acl_contact_cache')) {
         $errorMessage = ts("Database check failed - it looks like you have already upgraded to the latest version (v%1) of the database. OR If you think this message is wrong, it is very likely that this a partially upgraded db and you will need to reload the correct db on which upgrade was never tried.", array(1 => $latestVer));
         return false;
     }
     // check table-column, if the db is 3.1
     if (CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'date_format')) {
         $errorMessage = ts("Database check failed - it looks like you have already upgraded to the latest version (v%1) of the database. OR If you think this message is wrong, it is very likely that this a partially upgraded db and you will need to reload the correct db on which upgrade was never tried.", array(1 => $latestVer));
         return false;
     }
     //check previous version table e.g 3.0.*
     if (!CRM_Core_DAO::checkTableExists('civicrm_participant_status_type') || !CRM_Core_DAO::checkTableExists('civicrm_navigation')) {
         $errorMessage .= ' Few important tables were found missing.';
         return false;
     }
     // check fields which MUST be present if a proper 3.0.* db
     if (!CRM_Core_DAO::checkFieldExists('civicrm_relationship_type', 'label_a_b') || !CRM_Core_DAO::checkFieldExists('civicrm_mapping_field', 'im_provider_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'email_greeting_id')) {
         // db looks to have stuck somewhere between 2.2 & 3.0
         $errorMessage .= ' Few important fields were found missing in some of the tables.';
         return false;
     }
     return true;
 }
 /**
  * Will acquire a lock with the given name, 
  * if no other lock has been acquired by this process.
  * 
  * If the same lock has been acquired before (and not been released),
  * in internal counter is increased. Therefore you can acquire the same
  * lock multiple times, but you will then have to release them 
  * the same amount of times
  *
  * @return a SafeLock instance or NULL if timed out
  */
 public static function acquireLock($name, $timeout = 60)
 {
     if (self::$_acquired_lock == NULL) {
         // it's free, we'll try to take it
         $lock = new CRM_Core_Lock($name, $timeout);
         if (version_compare(CRM_Utils_System::version(), '4.6', '>=')) {
             // before 4.6, a new lock would be automatically acquired
             $lock->acquire();
         }
         if ($lock != NULL && $lock->isAcquired()) {
             // we got it!
             self::$_acquired_lock = new CRM_Utils_SepaSafeLock($lock, $name);
             //error_log('acquired ' . getmypid());
             return self::$_acquired_lock;
         } else {
             // timed out
             return NULL;
         }
     } elseif (self::$_acquired_lock->getName() == $name) {
         // this means acquiring 'our' lock again:
         $lock = self::$_acquired_lock;
         $lock->counter += 1;
         //error_log('acquired ' . getmypid() . "[{$lock->counter}]");
         return $lock;
     } else {
         // this is the BAD case: somebody's trying to acquire ANOTHER LOCK,
         //  while we still own another one
         $lock_name = $self::$_acquired_lock->getName();
         throw new Exception("This process cannot acquire more than one lock! It still owns lock '{$lock_name}'.");
     }
 }
Пример #4
0
 function verifyPreDBState(&$errorMessage)
 {
     $latestVer = CRM_Utils_System::version();
     $errorMessage = ts('Pre-condition failed for upgrade to %1.', array(1 => $latestVer));
     // check table, if the db is 3.0
     if (CRM_Core_DAO::checkTableExists('civicrm_navigation') && CRM_Core_DAO::checkTableExists('civicrm_participant_status_type')) {
         $errorMessage = ts("Database check failed - it looks like you have already upgraded to the latest version (v%1) of the database. OR If you think this message is wrong, it is very likely that this a partially upgraded db and you will need to reload the correct db on which upgrade was never tried.", array(1 => $latestVer));
         return false;
     }
     // check table-column, if the db is 3.0
     if (CRM_Core_DAO::checkFieldExists('civicrm_menu', 'domain_id') && CRM_Core_DAO::checkFieldExists('civicrm_event', 'created_id') && CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_template') && CRM_Core_DAO::checkFieldExists('civicrm_uf_field', 'is_reserved') && CRM_Core_DAO::checkFieldExists('civicrm_contact', 'email_greeting_id') && CRM_Core_DAO::checkFieldExists('civicrm_payment_processor_type', 'payment_type')) {
         $errorMessage = ts("Database check failed - it looks like you have already upgraded to the latest version (v%1) of the database. OR If you think this message is wrong, it is very likely that this a partially upgraded db and you will need to reload the correct db on which upgrade was never tried.", array(1 => $latestVer));
         return false;
     }
     //check previous version table e.g 2.2.*
     if (!CRM_Core_DAO::checkTableExists('civicrm_cache') || !CRM_Core_DAO::checkTableExists('civicrm_pcp_block') || !CRM_Core_DAO::checkTableExists('civicrm_menu') || !CRM_Core_DAO::checkTableExists('civicrm_discount') || !CRM_Core_DAO::checkTableExists('civicrm_pcp') || !CRM_Core_DAO::checkTableExists('civicrm_pledge_block') || !CRM_Core_DAO::checkTableExists('civicrm_contribution_soft')) {
         $errorMessage .= ' Few important tables were found missing.';
         return false;
     }
     // check fields which MUST be present if a proper 2.2.* db
     if (!CRM_Core_DAO::checkFieldExists('civicrm_activity', 'due_date_time') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'greeting_type_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution', 'check_number')) {
         // db looks to have stuck somewhere between 2.1 & 2.2
         $errorMessage .= ' Few important fields were found missing in some of the tables.';
         return false;
     }
     return true;
 }
 /**
  * This hook is called once for every batch before the pdf template is rendered.
  * You should use this for performance reasons when the token can be shared between chunk items (for example a contact
  * address that is the same for all files)
  *
  * You can implement this hook to add/modify template tokens
  * e.g. in your hook implementation call $template->assign('myCustomToken', 'my custom token');
  * and place a token called {$myCustomToken} in the template.
  *
  * @param object $template
  *
  * @return mixed based on op. pre-hooks return a boolean or
  * an error message which aborts the operation
  * @access public
  */
 static function pdf_shared_token(&$template, &$chunk)
 {
     if (version_compare(CRM_Utils_System::version(), '4.5', '<')) {
         return CRM_Utils_Hook::singleton()->invoke(1, $template, $chunk_item, self::$null, self::$null, self::$null, 'civicrm_pdf_shared_token');
     } else {
         return CRM_Utils_Hook::singleton()->invoke(1, $template, $chunk_item, self::$null, self::$null, self::$null, self::$null, 'civicrm_pdf_shared_token');
     }
 }
Пример #6
0
 /**
  * @return array
  */
 public function readActiveConfig()
 {
     if (!defined('CIVICRM_SETTINGS_PATH') || CIVICRM_SETTINGS_PATH !== $this->settingsFile) {
         return array();
     }
     $paths = is_callable(array('Civi', 'paths')) ? \Civi::paths() : NULL;
     $data = array('CMS_DB_DSN' => CIVICRM_UF_DSN, 'CMS_VERSION' => \CRM_Core_Config::singleton()->userSystem->getVersion(), 'CIVI_DB_DSN' => CIVICRM_DSN, 'CIVI_SITE_KEY' => CIVICRM_SITE_KEY, 'CIVI_VERSION' => \CRM_Utils_System::version(), 'CIVI_SETTINGS' => CIVICRM_SETTINGS_PATH, 'CIVI_TEMPLATEC' => \CRM_Core_Config::singleton()->templateCompileDir, 'CIVI_UF' => \CRM_Core_Config::singleton()->userFramework, 'IS_INSTALLED' => '1', 'SITE_TYPE' => 'cv-auto', 'CMS_URL' => $paths ? \Civi::paths()->getUrl('[cms.root]/', 'absolute') : \CRM_Utils_System::languageNegotiationURL(\CRM_Utils_System::baseCMSURL(), FALSE, TRUE), 'CMS_ROOT' => $paths ? \Civi::paths()->getPath('[cms.root]/.') : \CRM_Core_Config::singleton()->userSystem->cmsRootPath(), 'CIVI_CORE' => $paths ? \Civi::paths()->getPath('[civicrm.root]/.') : $GLOBALS['civicrm_root'], 'CIVI_URL' => $paths ? \Civi::paths()->getUrl('[civicrm.root]/', 'absolute') : '', 'CIVI_FILES' => $paths ? \Civi::paths()->getPath('[civicrm.root]/.') : dirname(\CRM_Core_Config::singleton()->templateCompileDir));
     return $data;
 }
Пример #7
0
 /**
  * This hook data transforms data stored in accounts_data to be formatted into a standard format.
  *
  * The called hook is expected to add a key 'civicrm_formatted' to the accountsData array
  * with the data using the same field names as the relevant CiviCRM api.
  *
  * @param array $accountsData data from accounts system
  * @param string $entity entity - eg. 'AccountContact'
  * @param string $plugin plugin in use
  *
  * @return mixed
  *   Ignore value.
  */
 public static function mapAccountsData(&$accountsData, $entity, $plugin)
 {
     $codeVersion = explode('.', CRM_Utils_System::version());
     if (version_compare($codeVersion[0] . '.' . $codeVersion[1], 4.5) >= 0) {
         return CRM_Utils_Hook::singleton()->invoke(3, $accountsData, $entity, $plugin, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, 'civicrm_mapAccountsData');
     } else {
         return CRM_Utils_Hook::singleton()->invoke(3, $accountsData, $entity, $plugin, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, 'civicrm_mapAccountsData');
     }
 }
Пример #8
0
 /**
  * Add civicrm settings.
  *
  * @param array $params
  *   Associated array of civicrm variables.
  *
  * @return void
  */
 public static function add(&$params)
 {
     self::fixParams($params);
     // also set a template url so js files can use this
     // CRM-6194
     $params['civiRelativeURL'] = CRM_Utils_System::url('CIVI_BASE_TEMPLATE');
     $params['civiRelativeURL'] = str_replace('CIVI_BASE_TEMPLATE', '', $params['civiRelativeURL']);
     // also add the version number for use by template / js etc
     $params['civiVersion'] = CRM_Utils_System::version();
     $domain = new CRM_Core_DAO_Domain();
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $values = unserialize($domain->config_backend);
         self::formatParams($params, $values);
     }
     // CRM-6151
     if (isset($params['localeCustomStrings']) && is_array($params['localeCustomStrings'])) {
         $domain->locale_custom_strings = serialize($params['localeCustomStrings']);
     }
     // unset any of the variables we read from file that should not be stored in the database
     // the username and certpath are stored flat with _test and _live
     // check CRM-1470
     $skipVars = self::skipVars();
     foreach ($skipVars as $var) {
         unset($params[$var]);
     }
     CRM_Core_BAO_Setting::fixAndStoreDirAndURL($params);
     // also skip all Dir Params, we dont need to store those in the DB!
     foreach ($params as $name => $val) {
         if (substr($name, -3) == 'Dir') {
             unset($params[$name]);
         }
     }
     //keep user preferred language upto date, CRM-7746
     $session = CRM_Core_Session::singleton();
     $lcMessages = CRM_Utils_Array::value('lcMessages', $params);
     if ($lcMessages && $session->get('userID')) {
         $languageLimit = CRM_Utils_Array::value('languageLimit', $params);
         if (is_array($languageLimit) && !in_array($lcMessages, array_keys($languageLimit))) {
             $lcMessages = $session->get('lcMessages');
         }
         $ufm = new CRM_Core_DAO_UFMatch();
         $ufm->contact_id = $session->get('userID');
         if ($lcMessages && $ufm->find(TRUE)) {
             $ufm->language = $lcMessages;
             $ufm->save();
             $session->set('lcMessages', $lcMessages);
             $params['lcMessages'] = $lcMessages;
         }
     }
     $domain->config_backend = serialize($params);
     $domain->save();
 }
Пример #9
0
/**
 * Display the CiviCRM version
 *
 * @code
 * The version is {crmVersion}.
 *
 * {crmVersion redact=auto assign=ver}The version is {$ver}.
 * @endcode
 *
 * @param $params
 * @param $smarty
 *
 * @return string
 */
function smarty_function_crmVersion($params, &$smarty)
{
    $version = CRM_Utils_System::version();
    if (!CRM_Core_Permission::check('access CiviCRM')) {
        $version = CRM_Utils_System::majorVersion();
    }
    if (isset($params['assign'])) {
        $smarty->assign($params['assign'], $version);
    } else {
        return $version;
    }
}
 /**
  * Construct the basic widget object.
  */
 public function __construct()
 {
     // Widget actual processes.
     parent::__construct('civicontribute-widget', __('CiviCRM Contribution Page Widget', 'civicontribute-widget'), array('description' => __('Displays contribution page widgets from CiviContribute as native WordPress widgets.', 'civicontribute-widget')));
     if (!function_exists('civicrm_initialize')) {
         return;
     }
     civicrm_initialize();
     require_once 'CRM/Utils/System.php';
     $this->_civiversion = CRM_Utils_System::version();
     $this->_civiBasePage = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'wpBasePage');
 }
Пример #11
0
 /**
  * Static instance provider.
  *
  * Method providing static instance of SmartTemplate, as
  * in Singleton pattern.
  */
 public static function &singleton()
 {
     if (version_compare(CRM_Utils_System::version(), '4.6', '<')) {
         // < 4.6: we need to create a wrapper
         $smarty = CRM_Core_Smarty::singleton();
         $smarty_wrapper = new CRM_Banking_Helpers_Smarty($smarty);
         return $smarty_wrapper;
     } else {
         // >= 4.6: just use the core smarty implementation
         return CRM_Core_Smarty::singleton();
     }
 }
 /**
  * Register resources required by Angular.
  */
 public function registerResources($region = 'html-header', $includeExtras = true)
 {
     $modules = $this->angular->getModules();
     $page = $this;
     // PHP 5.3 does not propagate $this to inner functions.
     $page->res->addSettingsFactory(function () use(&$modules, $page) {
         // TODO optimization; client-side caching
         return array_merge($page->angular->getResources(array_keys($modules), 'settings', 'settings'), array('resourceUrls' => \CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(), 'angular' => array('modules' => array_merge(array('ngRoute'), array_keys($modules)), 'cacheCode' => $page->res->getCacheCode())));
     });
     $page->res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', -100, $region, FALSE);
     if ($includeExtras) {
         //Civi vs 4.7 and above has reworked how wysiwyg works and we don't
         //have to side load ckeditor anymore
         $version = substr(CRM_Utils_System::version(), 0, 3);
         if ($version <= 4.6) {
             //crmUi depends on loading ckeditor, but ckeditor doesn't work properly with aggregation.
             //Add a basepath so that CKEditor works when Drupal (or other extension/cms) does the aggregation
             $basePath = $page->res->getUrl("civicrm") . "packages/ckeditor/";
             $page->res->addScript("window.CKEDITOR_BASEPATH = '{$basePath}';", 119, $region, FALSE);
             $page->res->addScriptFile('civicrm', 'packages/ckeditor/ckeditor.js', 120, $region, FALSE);
         }
         //Add jquery Notify
         $page->res->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.notify.min.js', 10, $region, FALSE);
         $page->assign("includeNotificationTemplate", true);
     }
     $headOffset = 1;
     $config = \CRM_Core_Config::singleton();
     if ($config->debug) {
         foreach ($modules as $moduleName => $module) {
             foreach ($page->angular->getResources($moduleName, 'css', 'cacheUrl') as $url) {
                 $page->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $region);
             }
             foreach ($page->angular->getResources($moduleName, 'js', 'cacheUrl') as $url) {
                 $page->res->addScriptUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $region);
                 // addScriptUrl() bypasses the normal string-localization of addScriptFile(),
                 // but that's OK because all Angular strings (JS+HTML) will load via crmResource.
             }
         }
     } else {
         // Note: addScriptUrl() bypasses the normal string-localization of addScriptFile(),
         // but that's OK because all Angular strings (JS+HTML) will load via crmResource.
         $aggScriptUrl = \CRM_Utils_System::url('civicrm/ajax/volunteer-angular-modules', 'format=js&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE);
         $page->res->addScriptUrl($aggScriptUrl, 1, $region);
         // FIXME: The following CSS aggregator doesn't currently handle path-adjustments - which can break icons.
         //$aggStyleUrl = \CRM_Utils_System::url('civicrm/ajax/angular-modules', 'format=css&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE);
         //$page->res->addStyleUrl($aggStyleUrl, 1, $region);
         foreach ($page->angular->getResources(array_keys($modules), 'css', 'cacheUrl') as $url) {
             $page->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $region);
         }
     }
 }
Пример #13
0
/**
 * Display the CiviCRM version
 *
 * @code
 * The version is {crmVersion}.
 *
 * {crmVersion redact=auto assign=ver}The version is {$ver}.
 * @endcode
 *
 * @param $params
 * @param $smarty
 *
 * @return string
 */
function smarty_function_crmVersion($params, &$smarty)
{
    $version = CRM_Utils_System::version();
    $redact = !CRM_Core_Permission::check('access CiviCRM');
    if ($redact) {
        $parts = explode('.', $version);
        $version = $parts[0] . '.' . $parts[1] . '.x';
    }
    if (isset($params['assign'])) {
        $smarty->assign($params['assign'], $version);
    } else {
        return $version;
    }
}
Пример #14
0
 function verifyPreDBState(&$errorMessage)
 {
     $latestVer = CRM_Utils_System::version();
     $errorMessage = ts('Pre-condition failed for upgrade to %1.', array(1 => $latestVer));
     // check tables and table-columns, if the db is already 3.1
     if (CRM_Core_DAO::checkTableExists('civicrm_acl_contact_cache') || CRM_Core_DAO::checkTableExists('civicrm_contact_type') || CRM_Core_DAO::checkTableExists('civicrm_dashboard') || CRM_Core_DAO::checkTableExists('civicrm_dashboard_contact') || CRM_Core_DAO::checkFieldExists('civicrm_country', 'is_province_abbreviated') || CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'date_format') || CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'time_format') || CRM_Core_DAO::checkFieldExists('civicrm_mail_settings', 'domain_id') || CRM_Core_DAO::checkFieldExists('civicrm_msg_template', 'workflow_id') || CRM_Core_DAO::checkFieldExists('civicrm_msg_template', 'is_default') || CRM_Core_DAO::checkFieldExists('civicrm_msg_template', 'is_reserved') || CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'domain_id') || CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'contact_autocomplete_options') || CRM_Core_DAO::checkFieldExists('civicrm_preferences_date', 'date_format') || CRM_Core_DAO::checkFieldExists('civicrm_preferences_date', 'time_format') || CRM_Core_DAO::checkFieldExists('civicrm_price_set', 'domain_id') || CRM_Core_DAO::checkFieldExists('civicrm_price_set', 'extends') || CRM_Core_DAO::checkFieldExists('civicrm_relationship_type', 'contact_sub_type_a') || CRM_Core_DAO::checkFieldExists('civicrm_relationship_type', 'contact_sub_type_b') || CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'domain_id')) {
         $errorMessage = ts("Database check failed - it looks like you have already upgraded to the latest version (v%1) of the database. OR If you think this message is wrong, it is very likely that this a partially upgraded database and you will need to reload the correct database from backup on which upgrade was never tried.", array(1 => $latestVer));
         return false;
     }
     //check previous version tables e.g 3.0.*
     if (!CRM_Core_DAO::checkTableExists('civicrm_participant_status_type') || !CRM_Core_DAO::checkTableExists('civicrm_navigation')) {
         $errorMessage .= ' Few important tables were found missing.';
         return false;
     }
     // check fields which MUST be present if a proper 3.0.* db
     if (!CRM_Core_DAO::checkFieldExists('civicrm_contact', 'email_greeting_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'created_id') || !CRM_Core_DAO::checkFieldExists('civicrm_custom_group', 'created_date') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_template') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'created_id') || !CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'created_date') || !CRM_Core_DAO::checkFieldExists('civicrm_mapping_field', 'im_provider_id') || !CRM_Core_DAO::checkFieldExists('civicrm_membership_type', 'domain_id') || !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'domain_id') || !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'fee_currency') || !CRM_Core_DAO::checkFieldExists('civicrm_payment_processor', 'domain_id') || !CRM_Core_DAO::checkFieldExists('civicrm_payment_processor_type', 'payment_type') || !CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'domain_id') || !CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'navigation') || !CRM_Core_DAO::checkFieldExists('civicrm_relationship_type', 'label_a_b') || !CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'navigation_id') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_field', 'is_reserved') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_group', 'created_id') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_match', 'domain_id')) {
         // db looks to have stuck somewhere between 3.0 & 3.1
         $errorMessage .= ' Few important fields were found missing in some of the tables.';
         return false;
     }
     return true;
 }
Пример #15
0
 /**
  * Attempt to enable the extension on the linked CiviCRM site
  *
  * @return bool TRUE on success; FALSE if there's no site or if there's an error
  */
 protected function tryEnable(InputInterface $input, OutputInterface $output, $key)
 {
     $civicrm_api3 = $this->getContainer()->get('civicrm_api3');
     if ($civicrm_api3 && $civicrm_api3->local && version_compare(\CRM_Utils_System::version(), '4.3.dev', '>=')) {
         $siteName = \CRM_Utils_System::baseURL();
         // \CRM_Core_Config::singleton()->userSystem->cmsRootPath();
         $output->writeln("<info>Refresh extension list for \"{$siteName}\"</info>");
         if (!$civicrm_api3->Extension->refresh(array('local' => TRUE, 'remote' => FALSE))) {
             $output->writeln("<error>Refresh error: " . $civicrm_api3->errorMsg() . "</error>");
             return FALSE;
         }
         if ($this->confirm($input, $output, "Enable extension ({$key}) in \"{$siteName}\"? [Y/n] ")) {
             $output->writeln("<info>Enable extension ({$key}) in \"{$siteName}\"</info>");
             if (!$civicrm_api3->Extension->install(array('key' => $key))) {
                 $output->writeln("<error>Install error: " . $civicrm_api3->errorMsg() . "</error>");
             }
         }
         return TRUE;
     }
     // fallback
     $output->writeln("NOTE: This might be a good time to refresh the extension list and install \"{$key}\".");
     return FALSE;
 }
Пример #16
0
 function run()
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $latestVer = CRM_Utils_System::version();
     $currentVer = CRM_Core_BAO_Domain::version();
     if (!$currentVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
     } else {
         if (stripos($currentVer, 'upgrade')) {
             CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.'));
         }
     }
     if (!$latestVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.'));
     }
     // hack to make past ver compatible /w new incremental upgrade process
     $convertVer = array('2.1' => '2.1.0', '2.2' => '2.2.alpha1', '2.2.alph' => '2.2.alpha3', '3.1.0' => '3.1.1');
     if (isset($convertVer[$currentVer])) {
         $currentVer = $convertVer[$currentVer];
     }
     // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
     // lets do a pattern check -
     if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
         CRM_Core_Error::fatal(ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'));
     }
     // This could be removed in later rev
     if ($currentVer == '2.1.6') {
         $config =& CRM_Core_Config::singleton();
         // also cleanup the templates_c directory
         $config->cleanup(1, false);
         if ($config->userFramework !== 'Standalone') {
             // clean the session
             $session =& CRM_Core_Session::singleton();
             $session->reset(2);
         }
     }
     // end of hack
     CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $upgrade =& new CRM_Upgrade_Form();
     $template =& CRM_Core_Smarty::singleton();
     $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $template->assign('menuRebuildURL', CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1'));
     $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
     if (version_compare($currentVer, $latestVer) > 0) {
         // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error.
         $dbToolsLink = CRM_Utils_System::docURL2("Database Troubleshooting Tools", true);
         $error = ts('Your database is marked with an unexpected version number: %1. The automated upgrade to version %2 can not be run - and the %2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. The database tools utility at %3 may be helpful. You may want to revert to the codebase you were using prior to beginning this upgrade until you resolve this problem.', array(1 => $currentVer, 2 => $latestVer, 3 => $dbToolsLink));
         CRM_Core_Error::fatal($error);
     } else {
         if (version_compare($currentVer, $latestVer) == 0) {
             $message = ts('Your database has already been upgraded to CiviCRM %1', array(1 => $latestVer));
             $template->assign('upgraded', true);
         } else {
             $message = ts('CiviCRM upgrade was successful.');
             $template->assign('currentVersion', $currentVer);
             $template->assign('newVersion', $latestVer);
             $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', array(1 => $currentVer, 2 => $latestVer)));
             $template->assign('upgraded', false);
             if (CRM_Utils_Array::value('upgrade', $_POST)) {
                 $revisions = $upgrade->getRevisionSequence();
                 foreach ($revisions as $rev) {
                     // proceed only if $currentVer < $rev
                     if (version_compare($currentVer, $rev) < 0) {
                         // as soon as we start doing anything we append ".upgrade" to version.
                         // this also helps detect any partial upgrade issues
                         $upgrade->setVersion($rev . '.upgrade');
                         $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
                         if (is_callable(array($this, $phpFunctionName))) {
                             eval("\$this->{$phpFunctionName}('{$rev}');");
                         } else {
                             $upgrade->processSQL($rev);
                         }
                         // after an successful intermediate upgrade, set the complete version
                         $upgrade->setVersion($rev);
                     }
                 }
                 $upgrade->setVersion($latestVer);
                 $template->assign('upgraded', true);
                 // also cleanup the templates_c directory
                 $config =& CRM_Core_Config::singleton();
                 $config->cleanup(1, false);
                 // clear db caching
                 $config->clearDBCache();
                 // clean the session. Note: In case of standalone this makes the user logout.
                 // So skip this step for standalone.
                 if ($config->userFramework !== 'Standalone') {
                     $session =& CRM_Core_Session::singleton();
                     $session->reset(2);
                 }
             }
         }
     }
     $template->assign('message', $message);
     $content = $template->fetch('CRM/common/success.tpl');
     echo CRM_Utils_System::theme('page', $content, true, $this->_print, false, true);
 }
Пример #17
0
 /**
  * Evaluate any tokens in a URL.
  *
  * @param string|FALSE $url
  * @return string|FALSE
  */
 public static function evalUrl($url)
 {
     if ($url === FALSE) {
         return FALSE;
     } else {
         $config = CRM_Core_Config::singleton();
         $vars = array('{ver}' => CRM_Utils_System::version(), '{uf}' => $config->userFramework, '{php}' => phpversion(), '{sid}' => md5('sid_' . (defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : '') . '_' . $config->userFrameworkBaseURL), '{baseUrl}' => $config->userFrameworkBaseURL, '{lang}' => $config->lcMessages, '{co}' => $config->defaultContactCountry);
         foreach (array_keys($vars) as $k) {
             $vars[$k] = urlencode($vars[$k]);
         }
         return strtr($url, $vars);
     }
 }
Пример #18
0
 /**
  * Conditionally fire an event during the first page run.
  *
  * The install system is currently implemented several times, so it's hard to add
  * new installation logic. We use a poor-man's method to detect the first run.
  *
  * Situations to test:
  *  - New installation
  *  - Upgrade from an old version (predating first-run tracker)
  *  - Upgrade from an old version (with first-run tracking)
  */
 public function handleFirstRun()
 {
     // Ordinarily, we prefetch settings en masse and find that the system is already installed.
     // No extra SQL queries required.
     if (Civi::settings()->get('installed')) {
         return;
     }
     // Q: How should this behave during testing?
     if (defined('CIVICRM_TEST')) {
         return;
     }
     // If schema hasn't been loaded yet, then do nothing. Don't want to interfere
     // with the existing installers. NOTE: If we change the installer pageflow,
     // then we may want to modify this behavior.
     if (!CRM_Core_DAO::checkTableExists('civicrm_domain')) {
         return;
     }
     // If we're handling an upgrade, then the system has already been used, so this
     // is not the first run.
     if (CRM_Core_Config::isUpgradeMode()) {
         return;
     }
     $dao = CRM_Core_DAO::executeQuery('SELECT version FROM civicrm_domain');
     while ($dao->fetch()) {
         if ($dao->version && version_compare($dao->version, CRM_Utils_System::version(), '<')) {
             return;
         }
     }
     // The installation flag is stored in civicrm_setting, which is domain-aware. The
     // flag could have been stored under a different domain.
     $dao = CRM_Core_DAO::executeQuery('
   SELECT domain_id, value FROM civicrm_setting
   WHERE is_domain = 1 AND name = "installed"
 ');
     while ($dao->fetch()) {
         $value = unserialize($dao->value);
         if (!empty($value)) {
             Civi::settings()->set('installed', 1);
             return;
         }
     }
     // OK, this looks new.
     Civi::service('dispatcher')->dispatch(\Civi\Core\Event\SystemInstallEvent::EVENT_NAME, new \Civi\Core\Event\SystemInstallEvent());
     Civi::settings()->set('installed', 1);
 }
 /**
  * Submits an API request through the iATS SOAP API Toolkit.
  *
  * @param $request
  *   The request object or array containing the parameters of the requested services.
  *
  * @return
  *   The response object from the API with properties pertinent to the requested
  *     services.
  */
 function request($credentials, $payment)
 {
     // Attempt the SOAP request and log the exception on failure.
     $method = $this->method['method'];
     if (empty($method)) {
         dsm($this->method);
         return FALSE;
     }
     // do some massaging of parameters for badly behaving iATS methods ($method is now the iATS method, not our internal key)
     switch ($method) {
         case 'CreateCreditCardCustomerCode':
         case 'UpdateCreditCardCustomerCode':
             $dummy_date = date('c', time());
             // now
             foreach (array('beginDate', 'endDate') as $key) {
                 if (empty($request_params[$key])) {
                     $request_params[$key] = $dummy_date;
                 }
             }
             break;
     }
     $message = $this->method['message'];
     $response = $this->method['response'];
     // always log requests to my own table, start by making a copy of the original request
     // note: this is different from the drupal watchdog logging that only happens if userframework logging and debug are enabled
     if (!empty($payment['invoiceNum'])) {
         $logged_request = $payment;
         // mask the cc numbers
         $this->mask($logged_request);
         // log: ip, invoiceNum, , cc, total, date
         // dpm($logged_request);
         $cc = isset($logged_request['creditCardNum']) ? $logged_request['creditCardNum'] : (isset($logged_request['ccNum']) ? $logged_request['ccNum'] : '');
         $ip = $logged_request['customerIPAddress'];
         $query_params = array(1 => array($logged_request['invoiceNum'], 'String'), 2 => array($ip, 'String'), 3 => array(substr($cc, -4), 'String'), 4 => array('', 'String'), 5 => array($logged_request['total'], 'String'));
         CRM_Core_DAO::executeQuery("INSERT INTO civicrm_iats_request_log\n        (invoice_num, ip, cc, customer_code, total, request_datetime) VALUES (%1, %2, %3, %4, %5, NOW())", $query_params);
         if (!$this->is_ipv4($ip)) {
             $payment['customerIPAddress'] = substr($ip, 0, 30);
         }
         // save the invoiceNum so I can log it for the response
         $this->invoiceNum = $logged_request['invoiceNum'];
     }
     // the agent user and password only get put in here so they don't end up in a log above
     try {
         /* until iATS fixes it's box verify, we need to have trace on to make the hack below work */
         $soapClient = new SoapClient($this->_wsdl_url, array('trace' => 1, 'soap_version' => SOAP_1_2));
         /* build the request manually as per the iATS docs */
         $xml = '<' . $message . ' xmlns="' . $this->_wsdl_url_ns . '">';
         $request = array_merge($this->request, (array) $credentials, (array) $payment);
         // Pass CiviCRM tag + version to iATS
         $request['comment'] = 'CiviCRM: ' . CRM_Utils_System::version() . ' + ' . 'iATS Extension: ' . $this->iats_extension_version();
         $tags = !empty($this->_tag_order) ? $this->_tag_order : array_keys($request);
         foreach ($tags as $k) {
             if (isset($request[$k])) {
                 $xml .= '<' . $k . '>' . $request[$k] . '</' . $k . '>';
             }
         }
         $xml .= '</' . $message . '>';
         if (!empty($this->options['log'])) {
             watchdog('civicrm_iatspayments_com', 'Method info: !method', array('!method' => $method), WATCHDOG_NOTICE);
             watchdog('civicrm_iatspayments_com', 'XML: !xml', array('!xml' => $xml), WATCHDOG_NOTICE);
         }
         $soapRequest = new SoapVar($xml, XSD_ANYXML);
         if (!empty($this->options['log'])) {
             watchdog('civicrm_iatspayments_com', 'Request !request', array('!request' => print_r($soapRequest, TRUE)), WATCHDOG_NOTICE);
         }
         $soapResponse = $soapClient->{$method}($soapRequest);
         if (!empty($this->options['log']) && !empty($this->options['debug'])) {
             $request_log = "\n HEADER:\n";
             $request_log .= $soapClient->__getLastRequestHeaders();
             $request_log .= "\n BODY:\n";
             $request_log .= $soapClient->__getLastRequest();
             $request_log .= "\n BODYEND:\n";
             watchdog('civicrm_iatspayments_com', 'Request: !request', array('!request' => '<pre>' . $request_log . '</pre>'), WATCHDOG_NOTICE);
             $response_log = "\n HEADER:\n";
             $response_log .= $soapClient->__getLastResponseHeaders();
             $response_log .= "\n BODY:\n";
             $response_log .= $soapClient->__getLastResponse();
             $response_log .= "\n BODYEND:\n";
             watchdog('civicrm_iatspayments_com', 'Response: !response', array('!response' => '<pre>' . $response_log . '</pre>'), WATCHDOG_NOTICE);
         }
     } catch (SoapFault $exception) {
         if (!empty($this->options['log'])) {
             watchdog('civicrm_iatspayments_com', 'SoapFault: !exception', array('!exception' => '<pre>' . print_r($exception, TRUE) . '</pre>'), WATCHDOG_ERROR);
             $response_log = "\n HEADER:\n";
             $response_log .= $soapClient->__getLastResponseHeaders();
             $response_log .= "\n BODY:\n";
             $response_log .= $soapClient->__getLastResponse();
             $response_log .= "\n BODYEND:\n";
             watchdog('civicrm_iatspayments_com', 'Raw Response: !response', array('!response' => '<pre>' . $response_log . '</pre>'), WATCHDOG_NOTICE);
         }
         return FALSE;
     }
     // Log the response if specified.
     if (!empty($this->options['log'])) {
         watchdog('civicrm_iatspayments_com', 'iATS SOAP response: !request', array('!request' => '<pre>' . print_r($soapResponse, TRUE) . '</pre>', WATCHDOG_DEBUG));
     }
     if (isset($soapResponse->{$response}->any)) {
         $xml_response = $soapResponse->{$response}->any;
         return new SimpleXMLElement($xml_response);
     } else {
         // deal with bad iats soap, this will only work if trace (debug) is on for now
         $hack = new stdClass();
         $hack->FILE = strip_tags($soapClient->__getLastResponse());
         return $hack;
     }
 }
Пример #20
0
 /**
  * Evaluate any tokens in a URL.
  *
  * @param string|FALSE $url
  *
  * @return string|FALSE
  */
 public static function evalUrl($url)
 {
     if (!$url || strpos($url, '{') === FALSE) {
         return $url;
     } else {
         $config = CRM_Core_Config::singleton();
         $vars = array('{ver}' => CRM_Utils_System::version(), '{uf}' => $config->userFramework, '{php}' => phpversion(), '{sid}' => self::getSiteID(), '{baseUrl}' => $config->userFrameworkBaseURL, '{lang}' => $config->lcMessages, '{co}' => $config->defaultContactCountry);
         return strtr($url, array_map('urlencode', $vars));
     }
 }
Пример #21
0
 /**
  * @param string $markup
  * @return string
  */
 public static function evalMarkup($markup)
 {
     $config = CRM_Core_Config::singleton();
     $vals = array('resourceUrl' => rtrim($config->resourceBase, '/'), 'ver' => CRM_Utils_System::version(), 'uf' => $config->userFramework, 'php' => phpversion(), 'sid' => CRM_Utils_System::getSiteID(), 'baseUrl' => $config->userFrameworkBaseURL, 'lang' => $config->lcMessages, 'co' => $config->defaultContactCountry);
     $vars = array();
     foreach ($vals as $k => $v) {
         $vars['%%' . $k . '%%'] = $v;
         $vars['{{' . $k . '}}'] = urlencode($v);
     }
     return strtr($markup, $vars);
 }
Пример #22
0
 static function versionSwitcher($numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg6, $fnSuffix, &$arg5 = NULL)
 {
     $version = CRM_Utils_System::version();
     preg_match('/4\\.[0-9]\\.[0-9]/', $version, $matches);
     $versionNum = str_replace(".", "", array_pop($matches));
     if ($versionNum >= 450) {
         return self::singleton()->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $fnSuffix);
     } else {
         return self::singleton()->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg6, $fnSuffix);
     }
 }
Пример #23
0
/**
 * System.Get API.
 *
 * @param array $params
 *
 * @return array
 */
function civicrm_api3_system_get($params)
{
    $config = CRM_Core_Config::singleton();
    $returnValues = array(array('version' => CRM_Utils_System::version(), 'uf' => CIVICRM_UF, 'php' => array('version' => phpversion(), 'tz' => date_default_timezone_get(), 'extensions' => get_loaded_extensions(), 'ini' => _civicrm_api3_system_get_redacted_ini()), 'mysql' => array('version' => CRM_Core_DAO::singleValueQuery('SELECT @@version')), 'cms' => array('type' => CIVICRM_UF, 'modules' => CRM_Core_Module::collectStatuses($config->userSystem->getModules())), 'civi' => array('version' => CRM_Utils_System::version(), 'dev' => (bool) CRM_Utils_System::isDevelopment(), 'components' => array_keys(CRM_Core_Component::getEnabledComponents()), 'extensions' => preg_grep('/^uninstalled$/', CRM_Extension_System::singleton()->getManager()->getStatuses(), PREG_GREP_INVERT), 'exampleUrl' => CRM_Utils_System::url('civicrm/example', NULL, TRUE, NULL, FALSE))));
    return civicrm_api3_create_success($returnValues, $params, 'System', 'get');
}
Пример #24
0
 function __construct($state = null, $action = CRM_Core_Action::NONE, $method = 'post', $name = null)
 {
     $this->_config =& CRM_Core_Config::singleton();
     $this->latestVersion = CRM_Utils_System::version();
     parent::__construct($state, $action, $method, $name);
 }
/**
 * Check version is at least as high as the one passed.
 *
 * @param string $version
 *
 * @return bool
 */
function _cividiscount_version_at_least($version)
{
    if (version_compare(CRM_Utils_System::version(), $version) >= 0) {
        return TRUE;
    }
    return FALSE;
}
/**
 * Is version of at least the version provided.
 *
 * @param string $version
 *
 * @return bool
 */
function _versionAtLeast($version)
{
    $codeVersion = explode('.', CRM_Utils_System::version());
    if (version_compare($codeVersion[0] . '.' . $codeVersion[1], $version) >= 0) {
        return TRUE;
    }
    return FALSE;
}
Пример #27
0
/**
 * System.Get API.
 *
 * @param array $params
 *
 * @return array
 */
function civicrm_api3_system_get($params)
{
    $config = CRM_Core_Config::singleton();
    $returnValues = array(array('version' => CRM_Utils_System::version(), 'uf' => CIVICRM_UF, 'php' => array('version' => phpversion(), 'time' => time(), 'tz' => date_default_timezone_get(), 'sapi' => php_sapi_name(), 'extensions' => get_loaded_extensions(), 'ini' => _civicrm_api3_system_get_redacted_ini()), 'mysql' => array('version' => CRM_Core_DAO::singleValueQuery('SELECT @@version'), 'time' => CRM_Core_DAO::singleValueQuery('SELECT unix_timestamp()'), 'vars' => _civicrm_api3_system_get_redacted_mysql()), 'cms' => array('version' => $config->userSystem->getVersion(), 'type' => CIVICRM_UF, 'modules' => CRM_Core_Module::collectStatuses($config->userSystem->getModules())), 'civi' => array('version' => CRM_Utils_System::version(), 'dev' => (bool) CRM_Utils_System::isDevelopment(), 'components' => array_keys(CRM_Core_Component::getEnabledComponents()), 'extensions' => preg_grep('/^uninstalled$/', CRM_Extension_System::singleton()->getManager()->getStatuses(), PREG_GREP_INVERT), 'multidomain' => CRM_Core_DAO::singleValueQuery('SELECT count(*) FROM civicrm_domain') > 1, 'settings' => _civicrm_api3_system_get_redacted_settings(), 'exampleUrl' => CRM_Utils_System::url('civicrm/example', NULL, TRUE, NULL, FALSE)), 'http' => array('software' => CRM_Utils_Array::value('SERVER_SOFTWARE', $_SERVER), 'forwarded' => !empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['X_FORWARDED_PROTO']), 'port' => empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 ? 'Standard' : 'Nonstandard'), 'os' => array('type' => php_uname('s'), 'release' => php_uname('r'), 'version' => php_uname('v'), 'machine' => php_uname('m'))));
    return civicrm_api3_create_success($returnValues, $params, 'System', 'get');
}
Пример #28
0
 /**
  * check if price set is quick config price set, i.e for eg, if event is configured with default fee or
  * usiing price sets
  *
  * @param int $priceSetId price set id
  *
  * @return boolean true is it is quickconfig else false
  */
 static function checkForQuickConfigPriceSet($priceSetId)
 {
     if (version_compare(CRM_Utils_System::version(), '4.4') >= 0) {
         if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
             return true;
         }
     } else {
         if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config')) {
             return true;
         }
     }
     return false;
 }
Пример #29
0
 /**
  * Set the code major version.
  */
 function setVersion () {
   $this->majorVersion = str_replace('.', '', substr(CRM_Utils_System::version(), 0, 3));
 }
Пример #30
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     $this->localVersion = CRM_Utils_System::version();
     $this->localMajorVersion = $this->getMajorVersion($this->localVersion);
     $this->cacheFile = Civi::paths()->getPath(self::CACHEFILE_NAME);
 }