コード例 #1
0
ファイル: I18nSubscriber.php プロジェクト: kidaa30/yes
 /**
  * Sets the tsLocale and dbLocale for multi-lingual sites.
  * Some code duplication from CRM/Core/BAO/ConfigSetting.php retrieve()
  * to avoid regressions from refactoring.
  * @param $lcMessagesRequest
  * @throws \API_Exception
  */
 public function setLocale($lcMessagesRequest)
 {
     // We must validate whether the locale is valid, otherwise setting a bad
     // dbLocale could probably lead to sql-injection.
     $domain = new \CRM_Core_DAO_Domain();
     $domain->id = \CRM_Core_Config::domainID();
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         // are we in a multi-language setup?
         $multiLang = $domain->locales ? TRUE : FALSE;
         $lcMessages = NULL;
         // on multi-lang sites based on request and civicrm_uf_match
         if ($multiLang) {
             $languageLimit = array();
             if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
                 $languageLimit = $defaults['languageLimit'];
             }
             if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
                 $lcMessages = $lcMessagesRequest;
             } else {
                 throw new \API_Exception(ts('Language not enabled: %1', array(1 => $lcMessagesRequest)));
             }
         }
         global $dbLocale;
         // set suffix for table names - use views if more than one language
         if ($lcMessages) {
             $dbLocale = $multiLang && $lcMessages ? "_{$lcMessages}" : '';
             // FIXME: an ugly hack to fix CRM-4041
             global $tsLocale;
             $tsLocale = $lcMessages;
         }
     }
 }
コード例 #2
0
ファイル: Step4.php プロジェクト: prashantgajare/civicrm-core
 /**
  * @param $errorMessage
  *
  * @return bool
  */
 function verifyPreDBState(&$errorMessage)
 {
     $errorMessage = ts('Pre-condition failed for upgrade step %1.', array(1 => '4'));
     if (CRM_Core_DAO::checkTableExists('civicrm_event_page')) {
         return FALSE;
     }
     // check fields which MUST be present if a proper 2.2 db
     if (!CRM_Core_DAO::checkFieldExists('civicrm_event', 'intro_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'footer_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'confirm_title') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'confirm_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'confirm_footer_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_email_confirm') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'confirm_email_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'confirm_from_name') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'confirm_from_email') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'cc_confirm') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'bcc_confirm') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'default_fee_id') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'default_discount_id') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'thankyou_title') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'thankyou_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'thankyou_footer_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_pay_later') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'pay_later_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'pay_later_receipt') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_multiple_registrations')) {
         // 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;
     }
     if ($this->checkVersion('2.1.103')) {
         $this->setVersion('2.2');
     } else {
         return FALSE;
     }
     // update config defaults
     $domain = new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     $domain->selectAdd('config_backend');
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         // reset components
         $defaults['enableComponents'] = array('CiviContribute', 'CiviPledge', 'CiviMember', 'CiviEvent', 'CiviMail');
         $defaults['enableComponentIDs'] = array(1, 6, 2, 3, 4);
         $defaults['moneyvalueformat'] = '%!i';
         $defaults['fieldSeparator'] = ',';
         $defaults['fatalErrorTemplate'] = 'CRM/common/fatal.tpl';
         // serialise settings
         CRM_Core_BAO_ConfigSetting::add($defaults);
     }
     return $this->checkVersion('2.2');
 }
コード例 #3
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     CRM_Utils_System::setTitle(ts('Settings - Undelete, Logging and ReCAPTCHA'));
     $this->addYesNo('contactUndelete', ts('Contact Trash & Undelete'));
     // also check if we can enable triggers
     $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(FALSE);
     // FIXME: for now, disable logging for multilingual sites OR if triggers are not permittted
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $attribs = $domain->locales || !$validTriggerPermission ? array('disabled' => 'disabled') : NULL;
     $this->assign('validTriggerPermission', $validTriggerPermission);
     $this->addYesNo('logging', ts('Logging'), NULL, NULL, $attribs);
     $this->addYesNo('versionCheck', ts('Version Check & Statistics Reporting'));
     $this->addYesNo('doNotAttachPDFReceipt', ts('Attach PDF copy to receipts'));
     $this->addElement('text', 'wkhtmltopdfPath', ts('Path to wkhtmltopdf executable'), array('size' => 64, 'maxlength' => 256));
     $this->addElement('text', 'maxAttachments', ts('Maximum Attachments'), array('size' => 2, 'maxlength' => 8));
     $this->addElement('text', 'maxFileSize', ts('Maximum File Size'), array('size' => 2, 'maxlength' => 8));
     $this->addElement('text', 'recaptchaPublicKey', ts('Public Key'), array('size' => 64, 'maxlength' => 64));
     $this->addElement('text', 'recaptchaPrivateKey', ts('Private Key'), array('size' => 64, 'maxlength' => 64));
     $this->addElement('text', 'dashboardCacheTimeout', ts('Dashboard cache timeout'), array('size' => 3, 'maxlength' => 5));
     $this->addElement('text', 'checksumTimeout', ts('CheckSum Lifespan'), array('size' => 2, 'maxlength' => 8));
     $this->addElement('text', 'recaptchaOptions', ts('Recaptcha Options'), array('size' => 64, 'maxlength' => 64));
     $this->addRule('maxAttachments', ts('Value should be a positive number'), 'positiveInteger');
     $this->addRule('maxFileSize', ts('Value should be a positive number'), 'positiveInteger');
     $this->addRule('checksumTimeout', ts('Value should be a positive number'), 'positiveInteger');
     parent::buildQuickForm();
 }
コード例 #4
0
ファイル: Schema.php プロジェクト: sarehag/civicrm-core
 /**
  * Setting Callback - Validate.
  *
  * @param mixed $value
  * @param array $fieldSpec
  *
  * @return bool
  * @throws API_Exception
  */
 public static function checkLoggingSupport(&$value, $fieldSpec)
 {
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if (!CRM_Core_DAO::checkTriggerViewPermission(FALSE) && $value) {
         throw new API_Exception("In order to use this functionality, the installation's database user must have privileges to create triggers (in MySQL 5.0 – and in MySQL 5.1 if binary logging is enabled – this means the SUPER privilege). This install either does not seem to have the required privilege enabled.");
     }
     return TRUE;
 }
コード例 #5
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     CRM_Utils_System::setTitle(ts('Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)'));
     // also check if we can enable triggers
     $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(FALSE);
     // FIXME: for now, disable logging for multilingual sites OR if triggers are not permittted
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $attribs = $domain->locales || !$validTriggerPermission ? array('disabled' => 'disabled') : array();
     $this->assign('validTriggerPermission', $validTriggerPermission);
     $this->addYesNo('logging', ts('Logging'), NULL, NULL, $attribs);
     $this->addElement('text', 'wkhtmltopdfPath', ts('Path to wkhtmltopdf executable'), array('size' => 64, 'maxlength' => 256));
     $this->addElement('text', 'recaptchaPublicKey', ts('Public Key'), array('size' => 64, 'maxlength' => 64));
     $this->addElement('text', 'recaptchaPrivateKey', ts('Private Key'), array('size' => 64, 'maxlength' => 64));
     $this->addElement('text', 'dashboardCacheTimeout', ts('Dashboard cache timeout'), array('size' => 3, 'maxlength' => 5));
     $this->addElement('text', 'recaptchaOptions', ts('Recaptcha Options'), array('size' => 64, 'maxlength' => 64));
     $this->addFormRule(array('CRM_Admin_Form_Setting_Miscellaneous', 'formRule'), $this);
     parent::buildQuickForm();
     $this->addRule('checksumTimeout', ts('Value should be a positive number'), 'positiveInteger');
 }
コード例 #6
0
ファイル: Step2.php プロジェクト: prashantgajare/civicrm-core
 function upgrade()
 {
     $sqlFile = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', '..', 'Incremental', 'sql', '2.2.alpha1.mysql'));
     $tplFile = "{$sqlFile}.tpl";
     $isMultilingual = FALSE;
     if (file_exists($tplFile)) {
         $isMultilingual = $this->processLocales($tplFile, '2.2');
     } else {
         if (!file_exists($sqlFile)) {
             CRM_Core_Error::fatal("sqlfile - {$rev}.mysql not found.");
         }
         $this->source($sqlFile);
     }
     if ($isMultilingual) {
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(TRUE);
         $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
         CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, '2.2');
     }
     $this->setVersion('2.1.102');
 }
コード例 #7
0
ファイル: Form.php プロジェクト: hguru/224Civi
 function __construct($state = NULL, $action = CRM_Core_Action::NONE, $method = 'post', $name = NULL)
 {
     $this->_config = CRM_Core_Config::singleton();
     // this->latestVersion is legacy code, only used for 2.0 -> 2.1 upgrade
     // latest ver in 2.1 series
     $this->latestVersion = '2.1.6';
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $this->multilingual = (bool) $domain->locales;
     $this->locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
     $smarty = CRM_Core_Smarty::singleton();
     $smarty->compile_dir = $this->_config->templateCompileDir;
     $smarty->assign('multilingual', $this->multilingual);
     $smarty->assign('locales', $this->locales);
     // we didn't call CRM_Core_BAO_ConfigSetting::retrieve(), so we need to set $dbLocale by hand
     if ($this->multilingual) {
         global $dbLocale;
         $dbLocale = "_{$this->_config->lcMessages}";
     }
     parent::__construct($state, $action, $method, $name);
 }
コード例 #8
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     CRM_Utils_System::setTitle(ts('Settings - Miscellaneous'));
     $this->addYesNo('contactUndelete', ts('Contact Trash & Undelete'));
     // also check if we can enable triggers
     $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(false);
     // FIXME: for now, disable logging for multilingual sites OR if triggers are not permittted
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(true);
     $attribs = $domain->locales || !$validTriggerPermission ? array('disabled' => 'disabled') : null;
     $this->assign('validTriggerPermission', $validTriggerPermission);
     $this->addYesNo('logging', ts('Logging'), null, null, $attribs);
     $this->addYesNo('versionCheck', ts('Version Check & Statistics Reporting'));
     $this->addElement('text', 'maxAttachments', ts('Maximum Attachments'), array('size' => 2, 'maxlength' => 8));
     $this->addElement('text', 'maxFileSize', ts('Maximum File Size'), array('size' => 2, 'maxlength' => 8));
     $this->addElement('text', 'recaptchaPublicKey', ts('Public Key'), array('size' => 64, 'maxlength' => 64));
     $this->addElement('text', 'recaptchaPrivateKey', ts('Private Key'), array('size' => 64, 'maxlength' => 64));
     $this->addElement('text', 'dashboardCacheTimeout', ts('Dashboard cache timeout'), array('size' => 3, 'maxlength' => 5));
     $this->addRule('maxAttachments', ts('Value should be a positive number'), 'positiveInteger');
     $this->addRule('maxFileSize', ts('Value should be a positive number'), 'positiveInteger');
     parent::buildQuickForm();
 }
コード例 #9
0
ファイル: Step1.php プロジェクト: hampelm/Ginsberg-CiviDemo
 function verifyPreDBState(&$errorMessage)
 {
     $config = CRM_Core_Config::singleton();
     // Let's first update the config defaults
     require_once "CRM/Core/DAO/Domain.php";
     $domain = new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     $domain->selectAdd('config_backend');
     $domain->find(true);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         // reset components
         $defaults['enableComponents'] = array('CiviContribute', 'CiviPledge', 'CiviMember', 'CiviEvent', 'CiviMail');
         $defaults['enableComponentIDs'] = array(1, 6, 2, 3, 4);
         $defaults['moneyvalueformat'] = '%!i';
         $defaults['fieldSeparator'] = ',';
         $defaults['fatalErrorTemplate'] = 'CRM/common/fatal.tpl';
         // update cms-version
         if ($config->userFramework == 'Joomla') {
             $defaults['userFrameworkVersion'] = '1.5';
             if (class_exists('JVersion')) {
                 $version = new JVersion();
                 $defaults['userFrameworkVersion'] = $version->getShortVersion();
             }
         } else {
             if ($config->userFramework == 'Drupal') {
                 $defaults['userFrameworkVersion'] = '6.3';
                 if (defined('VERSION')) {
                     $defaults['userFrameworkVersion'] = VERSION;
                 }
             }
         }
         // serialise settings
         require_once "CRM/Core/BAO/Setting.php";
         CRM_Core_BAO_Setting::add($defaults);
         $config = CRM_Core_Config::singleton();
     }
     // check if log file is writable
     if (!is_writable($config->uploadDir . 'CiviCRM.log')) {
         $errorMessage = ts('Log file CiviCRM.log is not writable. Make sure files directory is writable.', array(1 => $config->uploadDir));
         return false;
     }
     $errorMessage = ts('Database check failed - the current database is not v2.0.');
     $is20db = true;
     // abort if partial upgraded db found.
     if ($this->checkVersion('2.01') || $this->checkVersion('2.02') || $this->checkVersion('2.03')) {
         $errorMessage = ts('Corrupt / Partial Upgraded database found. Looks like upgrade wizard failed to complete all the required steps to convert your database to v2.1. Please fix any errors and start the upgrade process again with a clean v2.0 database.');
         return false;
     }
     // abort if already 2.1
     if ($this->checkVersion('2.1')) {
         $errorMessage = ts('Database check failed - looks like you have already upgraded to the latest version (v2.1) of the database.');
         return false;
     }
     // check if 2.0 version
     if (!$this->checkVersion('2.0')) {
         $is20db = false;
     }
     // check if 2.0 tables exists
     if (!CRM_Core_DAO::checkTableExists('civicrm_activity') || !CRM_Core_DAO::checkTableExists('civicrm_activity_assignment') || !CRM_Core_DAO::checkTableExists('civicrm_activity_target') || !CRM_Core_DAO::checkTableExists('civicrm_address') || !CRM_Core_DAO::checkTableExists('civicrm_address') || !CRM_Core_DAO::checkTableExists('civicrm_case') || !CRM_Core_DAO::checkTableExists('civicrm_case_activity') || !CRM_Core_DAO::checkTableExists('civicrm_component') || !CRM_Core_DAO::checkTableExists('civicrm_contribution_widget') || !CRM_Core_DAO::checkTableExists('civicrm_grant') || !CRM_Core_DAO::checkTableExists('civicrm_group_nesting') || !CRM_Core_DAO::checkTableExists('civicrm_group_organization') || !CRM_Core_DAO::checkTableExists('civicrm_loc_block') || !CRM_Core_DAO::checkTableExists('civicrm_openid') || !CRM_Core_DAO::checkTableExists('civicrm_openid_associations') || !CRM_Core_DAO::checkTableExists('civicrm_openid_nonces') || !CRM_Core_DAO::checkTableExists('civicrm_preferences_date') || !CRM_Core_DAO::checkTableExists('civicrm_tell_friend') || !CRM_Core_DAO::checkTableExists('civicrm_timezone') || !CRM_Core_DAO::checkTableExists('civicrm_worldregion')) {
         // db is not 2.0
         $errorMessage .= ' Few 2.0 tables were found missing.';
         $is20db = false;
     }
     // check fields which MUST be present if a proper 2.0 db
     if ($is20db) {
         if (!CRM_Core_DAO::checkFieldExists('civicrm_activity', 'source_record_id') || !CRM_Core_DAO::checkFieldExists('civicrm_activity', 'activity_date_time') || !CRM_Core_DAO::checkFieldExists('civicrm_activity', 'status_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'first_name') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'last_name') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'gender_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'mail_to_household_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'user_unique_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'household_name') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'organization_name') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution', 'honor_type_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'is_pay_later') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'pay_later_text') || !CRM_Core_DAO::checkFieldExists('civicrm_country', 'region_id') || !CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'column_name') || !CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'option_group_id') || !CRM_Core_DAO::checkFieldExists('civicrm_custom_group', 'table_name') || !CRM_Core_DAO::checkFieldExists('civicrm_custom_group', 'is_multiple') || !CRM_Core_DAO::checkFieldExists('civicrm_domain', 'version') || !CRM_Core_DAO::checkFieldExists('civicrm_domain', 'loc_block_id') || !CRM_Core_DAO::checkFieldExists('civicrm_email', 'contact_id') || !CRM_Core_DAO::checkFieldExists('civicrm_email', 'location_type_id') || !CRM_Core_DAO::checkFieldExists('civicrm_email', 'is_billing') || !CRM_Core_DAO::checkFieldExists('civicrm_entity_tag', 'contact_id') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'participant_listing_id') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'loc_block_id') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'receipt_text') || !CRM_Core_DAO::checkFieldExists('civicrm_event_page', 'is_pay_later') || !CRM_Core_DAO::checkFieldExists('civicrm_event_page', 'pay_later_text') || !CRM_Core_DAO::checkFieldExists('civicrm_financial_trxn', 'contribution_id') || !CRM_Core_DAO::checkFieldExists('civicrm_im', 'contact_id') || !CRM_Core_DAO::checkFieldExists('civicrm_im', 'location_type_id') || !CRM_Core_DAO::checkFieldExists('civicrm_membership_payment', 'contribution_id') || !CRM_Core_DAO::checkFieldExists('civicrm_membership_type', 'receipt_text_signup') || !CRM_Core_DAO::checkFieldExists('civicrm_membership_type', 'receipt_text_renewal') || !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'component_id') || !CRM_Core_DAO::checkFieldExists('civicrm_participant_payment', 'contribution_id') || !CRM_Core_DAO::checkFieldExists('civicrm_payment_processor', 'url_api') || !CRM_Core_DAO::checkFieldExists('civicrm_payment_processor_type', 'url_api_default') || !CRM_Core_DAO::checkFieldExists('civicrm_phone', 'contact_id') || !CRM_Core_DAO::checkFieldExists('civicrm_phone', 'location_type_id') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_match', 'uf_name')) {
             // db looks to have stuck somewhere between 2.0 & 2.1
             $errorMessage .= ' Few important fields were found missing in some of the tables.';
             $is20db = false;
         }
     }
     if (!$is20db) {
         // check if the db is 2.1
         if (CRM_Core_DAO::checkTableExists('civicrm_cache') && CRM_Core_DAO::checkFieldExists('civicrm_cache', 'group_name') && CRM_Core_DAO::checkFieldExists('civicrm_cache', 'created_date') && CRM_Core_DAO::checkFieldExists('civicrm_cache', 'expired_date') && CRM_Core_DAO::checkTableExists('civicrm_group_contact_cache') && CRM_Core_DAO::checkFieldExists('civicrm_group_contact_cache', 'contact_id') && CRM_Core_DAO::checkTableExists('civicrm_menu') && CRM_Core_DAO::checkFieldExists('civicrm_menu', 'path_arguments') && CRM_Core_DAO::checkFieldExists('civicrm_menu', 'is_exposed') && CRM_Core_DAO::checkFieldExists('civicrm_menu', 'page_type') && CRM_Core_DAO::checkTableExists('civicrm_discount') && CRM_Core_DAO::checkFieldExists('civicrm_discount', 'option_group_id') && CRM_Core_DAO::checkFieldExists('civicrm_discount', 'end_date')) {
             $errorMessage = ts('Database check failed - it looks like you have already upgraded to the latest version (v2.1) of the database.');
         }
         return false;
     }
     // check tables which should not exist for v2.x
     if (CRM_Core_DAO::checkTableExists('civicrm_custom_option') || CRM_Core_DAO::checkTableExists('civicrm_custom_value') || CRM_Core_DAO::checkTableExists('civicrm_email_history') || CRM_Core_DAO::checkTableExists('civicrm_geo_coord') || CRM_Core_DAO::checkTableExists('civicrm_individual') || CRM_Core_DAO::checkTableExists('civicrm_location') || CRM_Core_DAO::checkTableExists('civicrm_meeting') || CRM_Core_DAO::checkTableExists('civicrm_organization') || CRM_Core_DAO::checkTableExists('civicrm_phonecall') || CRM_Core_DAO::checkTableExists('civicrm_sms_history') || CRM_Core_DAO::checkTableExists('civicrm_validation')) {
         // table(s) found in the db which are no longer required
         // for v2.x, though would not do any harm it's recommended
         // to remove them.
         CRM_Core_Session::setStatus(ts("Table(s) found in your db which are no longer required for v2.x, though would not do any harm it's recommended to remove them"));
     }
     // show error if any of the tables, use 'MyISAM' storage engine.
     // just check the first 10 civicrm tables, rather than checking all 106!
     if (CRM_Core_DAO::isDBMyISAM(10)) {
         $errorMessage = ts('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 before proceeding.');
         return false;
     }
     // check FK constraint names are in valid format.
     if (!CRM_Core_DAO::checkFKConstraintInFormat('civicrm_contact', 'domain_id') || !CRM_Core_DAO::checkFKConstraintInFormat('civicrm_contribution_page', 'domain_id') || !CRM_Core_DAO::checkFKConstraintInFormat('civicrm_contribution_recur', 'domain_id') || !CRM_Core_DAO::checkFKConstraintInFormat('civicrm_membership_status', 'domain_id') || !CRM_Core_DAO::checkFKConstraintInFormat('civicrm_contribution', 'contact_id') || !CRM_Core_DAO::checkFKConstraintInFormat('civicrm_contribution', 'contribution_type_id')) {
         $errorMessage = ts('Database consistency check failed. FK constraint names not in the required format. Please rebuild your 2.0 database to ensure schema integrity.');
         return false;
     }
     return true;
 }
コード例 #10
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $this->_numStrings = sizeof($params['old']);
     $enabled['exactMatch'] = $enabled['wildcardMatch'] = $disabled['exactMatch'] = $disabled['wildcardMatch'] = array();
     for ($i = 1; $i <= $this->_numStrings; $i++) {
         if (!empty($params['new'][$i]) && !empty($params['old'][$i])) {
             if (isset($params['enabled']) && !empty($params['enabled'][$i])) {
                 if (!empty($params['cb']) && !empty($params['cb'][$i])) {
                     $enabled['exactMatch'] += array($params['old'][$i] => $params['new'][$i]);
                 } else {
                     $enabled['wildcardMatch'] += array($params['old'][$i] => $params['new'][$i]);
                 }
             } else {
                 if (isset($params['cb']) && is_array($params['cb']) && array_key_exists($i, $params['cb'])) {
                     $disabled['exactMatch'] += array($params['old'][$i] => $params['new'][$i]);
                 } else {
                     $disabled['wildcardMatch'] += array($params['old'][$i] => $params['new'][$i]);
                 }
             }
         }
     }
     $overrides = array('enabled' => $enabled, 'disabled' => $disabled);
     $config = CRM_Core_Config::singleton();
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if ($domain->locales && $config->localeCustomStrings) {
         // for multilingual
         $addReplacements = $config->localeCustomStrings;
         $addReplacements[$config->lcMessages] = $overrides;
         $stringOverride = serialize($addReplacements);
     } else {
         // for single language
         $stringOverride = serialize(array($config->lcMessages => $overrides));
     }
     $params = array('locale_custom_strings' => $stringOverride);
     $id = CRM_Core_Config::domainID();
     $wordReplacementSettings = CRM_Core_BAO_Domain::edit($params, $id);
     if ($wordReplacementSettings) {
         // This controller was originally written to CRUD $config->locale_custom_strings,
         // but that's no longer the canonical store. Sync changes to canonical store.
         // This is inefficient - at some point, we should rewrite this UI.
         CRM_Core_BAO_WordReplacement::rebuildWordReplacementTable();
         CRM_Core_Session::setStatus("", ts("Settings Saved"), "success");
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/options/wordreplacements', "reset=1"));
     }
 }
コード例 #11
0
ファイル: Setting.php プロジェクト: kidaa30/yes
 /**
  * Move an item from being in the config array to being stored as a setting
  * remove from config - as appropriate based on metadata
  *
  * Note that where the key name is being changed the 'legacy_key' will give us the old name
  */
 public static function convertConfigToSetting($name, $domainID = NULL)
 {
     // we have to force this here in case more than one domain is in play.
     // whenever there is a possibility of more than one domain we must force it
     $config = CRM_Core_Config::singleton();
     if (empty($domainID)) {
         $domainID = CRM_Core_Config::domainID();
     }
     $domain = new CRM_Core_DAO_Domain();
     $domain->id = $domainID;
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $values = unserialize($domain->config_backend);
     } else {
         $values = array();
     }
     $spec = self::getSettingSpecification(NULL, array('name' => $name), $domainID);
     $configKey = CRM_Utils_Array::value('config_key', $spec[$name], CRM_Utils_Array::value('legacy_key', $spec[$name], $name));
     //if the key is set to config_only we don't need to do anything
     if (empty($spec[$name]['config_only'])) {
         if (!empty($values[$configKey])) {
             civicrm_api('setting', 'create', array('version' => 3, $name => $values[$configKey], 'domain_id' => $domainID));
         } else {
             civicrm_api('setting', 'fill', array('version' => 3, 'name' => $name, 'domain_id' => $domainID));
         }
         if (empty($spec[$name]['prefetch']) && !empty($values[$configKey])) {
             unset($values[$configKey]);
             $domain->config_backend = serialize($values);
             $domain->save();
             unset($config->{$configKey});
         }
     }
 }
コード例 #12
0
ファイル: I18n.php プロジェクト: FundingWorks/civicrm-core
 /**
  * Is the CiviCRM in multilingual mode.
  *
  * @return Bool
  *   True if CiviCRM is in multilingual mode.
  */
 public static function isMultilingual()
 {
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     return (bool) $domain->locales;
 }
コード例 #13
0
ファイル: SchemaHandler.php プロジェクト: ksecor/civicrm
 static function createIndexes(&$tables, $createIndexPrefix = 'index')
 {
     $queries = array();
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(true);
     $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
     // if we're multilingual, cache the information on internationalised fields
     static $columns = null;
     require_once 'CRM/Utils/System.php';
     if (!CRM_Utils_System::isNull($locales) and $columns === null) {
         require_once 'CRM/Core/I18n/SchemaStructure.php';
         $columns =& CRM_Core_I18n_SchemaStructure::columns();
     }
     foreach ($tables as $table => $fields) {
         $query = "SHOW INDEX FROM {$table}";
         $dao = CRM_Core_DAO::executeQuery($query);
         $currentIndexes = array();
         while ($dao->fetch()) {
             $currentIndexes[] = $dao->Key_name;
         }
         // now check for all fields if the index exists
         foreach ($fields as $field) {
             $names = array("index_{$field}", "FK_{$table}_{$field}", "UI_{$field}", "{$createIndexPrefix}_{$field}");
             // skip to the next $field if one of the above $names exists; handle multilingual for CRM-4126
             foreach ($names as $name) {
                 $regex = '/^' . preg_quote($name) . '(_[a-z][a-z]_[A-Z][A-Z])?$/';
                 if (preg_grep($regex, $currentIndexes)) {
                     continue 2;
                 }
             }
             // the index doesn't exist, so create it
             // if we're multilingual and the field is internationalised, do it for every locale
             if (!CRM_Utils_System::isNull($locales) and isset($columns[$table][$field])) {
                 foreach ($locales as $locale) {
                     $queries[] = "CREATE INDEX {$createIndexPrefix}_{$field}_{$locale} ON {$table} ({$field}_{$locale})";
                 }
             } else {
                 $queries[] = "CREATE INDEX {$createIndexPrefix}_{$field} ON {$table} ({$field})";
             }
         }
     }
     // run the queries without i18n-rewriting
     $dao = new CRM_Core_DAO();
     foreach ($queries as $query) {
         $dao->query($query, false);
     }
 }
コード例 #14
0
ファイル: Schema.php プロジェクト: hguru/224Civi
 static function triggerInfo(&$info, $tableName = NULL)
 {
     // get the current supported locales
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if (empty($domain->locales)) {
         return;
     }
     $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
     $locale = array_pop($locales);
     // CRM-10027
     if (count($locales) == 0) {
         return;
     }
     $currentVer = CRM_Core_BAO_Domain::version(TRUE);
     if ($currentVer && CRM_Core_Config::isUpgradeMode()) {
         // take exact version so that proper schema structure file in invoked
         $latest = self::getLatestSchema($currentVer);
         require_once "CRM/Core/I18n/SchemaStructure_{$latest}.php";
         $class = "CRM_Core_I18n_SchemaStructure_{$latest}";
     } else {
         $class = 'CRM_Core_I18n_SchemaStructure';
     }
     $columns =& $class::columns();
     foreach ($columns as $table => $hash) {
         if ($tableName && $tableName != $table) {
             continue;
         }
         $trigger = array();
         foreach ($hash as $column => $_) {
             $trigger[] = "IF NEW.{$column}_{$locale} IS NOT NULL THEN";
             foreach ($locales as $old) {
                 $trigger[] = "IF NEW.{$column}_{$old} IS NULL THEN SET NEW.{$column}_{$old} = NEW.{$column}_{$locale}; END IF;";
             }
             foreach ($locales as $old) {
                 $trigger[] = "ELSEIF NEW.{$column}_{$old} IS NOT NULL THEN";
                 foreach (array_merge($locales, array($locale)) as $loc) {
                     if ($loc == $old) {
                         continue;
                     }
                     $trigger[] = "IF NEW.{$column}_{$loc} IS NULL THEN SET NEW.{$column}_{$loc} = NEW.{$column}_{$old}; END IF;";
                 }
             }
             $trigger[] = 'END IF;';
         }
         $sql = implode(' ', $trigger);
         $info[] = array('table' => array($table), 'when' => 'BEFORE', 'event' => array('UPDATE'), 'sql' => $sql);
     }
     // take care of the ON INSERT triggers
     foreach ($columns as $table => $hash) {
         $trigger = array();
         foreach ($hash as $column => $_) {
             $trigger[] = "IF NEW.{$column}_{$locale} IS NOT NULL THEN";
             foreach ($locales as $old) {
                 $trigger[] = "SET NEW.{$column}_{$old} = NEW.{$column}_{$locale};";
             }
             foreach ($locales as $old) {
                 $trigger[] = "ELSEIF NEW.{$column}_{$old} IS NOT NULL THEN";
                 foreach (array_merge($locales, array($locale)) as $loc) {
                     if ($loc == $old) {
                         continue;
                     }
                     $trigger[] = "SET NEW.{$column}_{$loc} = NEW.{$column}_{$old};";
                 }
             }
             $trigger[] = 'END IF;';
         }
         $sql = implode(' ', $trigger);
         $info[] = array('table' => array($table), 'when' => 'BEFORE', 'event' => array('INSERT'), 'sql' => $sql);
     }
 }
コード例 #15
0
ファイル: Setting.php プロジェクト: ksecor/civicrm
 /**
  * Function to retrieve the settings values from db
  *
  * @return array $defaults  
  * @static
  */
 static function retrieve(&$defaults)
 {
     require_once "CRM/Core/DAO/Domain.php";
     $domain = new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     if (CRM_Utils_Array::value('q', $_GET) == 'civicrm/upgrade') {
         $domain->selectAdd('config_backend');
     } else {
         $domain->selectAdd('config_backend, locales');
     }
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(true);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         // calculate month var
         $defaults['dateformatMonthVar'] = strstr($defaults['dateformatQfDate'], '%m') ? 'm' : (strstr($defaults['dateformatQfDate'], '%b') ? 'M' : (strstr($defaults['dateformatQfDate'], '%B') ? 'F' : null));
         //calculate month var for Date Time
         $defaults['datetimeformatMonthVar'] = strstr($defaults['dateformatQfDatetime'], '%m') ? 'm' : (strstr($defaults['dateformatQfDatetime'], '%b') ? 'M' : (strstr($defaults['dateformatQfDatetime'], '%B') ? 'F' : null));
         //calculate hour var for Date Time
         $defaults['datetimeformatHourVar'] = strstr($defaults['dateformatQfDatetime'], '%I') ? 'h' : (strstr($defaults['dateformatQfDatetime'], '%l') ? 'g' : null);
         // set proper monetary formatting, falling back to en_US and C (CRM-2782)
         setlocale(LC_MONETARY, $defaults['lcMonetary'] . '.utf8', $defaults['lcMonetary'], 'en_US.utf8', 'en_US', 'C');
         $skipVars = array('dsn', 'templateCompileDir', 'userFrameworkDSN', 'userFrameworkBaseURL', 'userFrameworkClass', 'userHookClass', 'userPermissionClass', 'userFrameworkURLVar', 'qfKey', 'gettextResourceDir', 'cleanURL');
         foreach ($skipVars as $skip) {
             if (array_key_exists($skip, $defaults)) {
                 unset($defaults[$skip]);
             }
         }
         // since language field won't be present before upgrade.
         if (CRM_Utils_Array::value('q', $_GET) == 'civicrm/upgrade') {
             return;
         }
         // are we in a multi-language setup?
         $multiLang = $domain->locales ? true : false;
         // set the current language
         $lcMessages = null;
         $session =& CRM_Core_Session::singleton();
         // on multi-lang sites based on request and civicrm_uf_match
         if ($multiLang) {
             require_once 'CRM/Utils/Request.php';
             $lcMessagesRequest = CRM_Utils_Request::retrieve('lcMessages', 'String', $this);
             $languageLimit = array();
             if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
                 $languageLimit = $defaults['languageLimit'];
             }
             if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
                 $lcMessages = $lcMessagesRequest;
             } else {
                 $lcMessagesRequest = null;
             }
             if (!$lcMessagesRequest) {
                 $lcMessagesSession = $session->get('lcMessages');
                 if (in_array($lcMessagesSession, array_keys($languageLimit))) {
                     $lcMessages = $lcMessagesSession;
                 } else {
                     $lcMessagesSession = null;
                 }
             }
             if ($lcMessagesRequest) {
                 require_once 'CRM/Core/DAO/UFMatch.php';
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(true)) {
                     $ufm->language = $lcMessages;
                     $ufm->save();
                 }
                 $session->set('lcMessages', $lcMessages);
             }
             if (!$lcMessages and $session->get('userID')) {
                 require_once 'CRM/Core/DAO/UFMatch.php';
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(true) && in_array($ufm->language, array_keys($languageLimit))) {
                     $lcMessages = $ufm->language;
                 }
                 $session->set('lcMessages', $lcMessages);
             }
         }
         // if unset, try to inherit the language from the hosting CMS
         if ($lcMessages === null) {
             require_once 'CRM/Utils/System.php';
             $lcMessages = CRM_Utils_System::getUFLocale();
             require_once 'CRM/Core/BAO/CustomOption.php';
             if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $domain->locales))) {
                 $lcMessages = null;
             }
         }
         if ($lcMessages) {
             // update config lcMessages - CRM-5027 fixed.
             $defaults['lcMessages'] = $lcMessages;
         } else {
             // if a single-lang site or the above didn't yield a result, use default
             $lcMessages = $defaults['lcMessages'];
         }
         // set suffix for table names - use views if more than one language
         global $dbLocale;
         $dbLocale = $multiLang ? "_{$lcMessages}" : '';
         // FIXME: an ugly hack to fix CRM-4041
         global $tsLocale;
         $tsLocale = $lcMessages;
     }
 }
コード例 #16
0
ファイル: Localization.php プロジェクト: nielosz/civicrm-core
 /**
  * @return array
  */
 public static function getDefaultLocaleOptions()
 {
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $locales = CRM_Core_I18n::languages();
     if ($domain->locales) {
         // for multi-lingual sites, populate default language drop-down with available languages
         $defaultLocaleOptions = array();
         foreach ($locales as $loc => $lang) {
             if (substr_count($domain->locales, $loc)) {
                 $defaultLocaleOptions[$loc] = $lang;
             }
         }
     } else {
         $defaultLocaleOptions = $locales;
     }
     return $defaultLocaleOptions;
 }
コード例 #17
0
ファイル: Component.php プロジェクト: kidaa30/yes
 /**
  * @param $dsn
  * @param string $fileName
  * @param bool $lineMode
  */
 public static function loadCaseSampleData($dsn, $fileName, $lineMode = FALSE)
 {
     $db =& DB::connect($dsn);
     if (PEAR::isError($db)) {
         die("Cannot open {$dsn}: " . $db->getMessage());
     }
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $multiLingual = (bool) $domain->locales;
     $smarty = CRM_Core_Smarty::singleton();
     $smarty->assign('multilingual', $multiLingual);
     $smarty->assign('locales', explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales));
     if (!$lineMode) {
         $string = $smarty->fetch($fileName);
         // change \r\n to fix windows issues
         $string = str_replace("\r\n", "\n", $string);
         //get rid of comments starting with # and --
         $string = preg_replace("/^#[^\n]*\$/m", "\n", $string);
         $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
         $queries = preg_split('/;$/m', $string);
         foreach ($queries as $query) {
             $query = trim($query);
             if (!empty($query)) {
                 $res =& $db->query($query);
                 if (PEAR::isError($res)) {
                     die("Cannot execute {$query}: " . $res->getMessage());
                 }
             }
         }
     } else {
         $fd = fopen($fileName, "r");
         while ($string = fgets($fd)) {
             $string = preg_replace("/^#[^\n]*\$/m", "\n", $string);
             $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
             $string = trim($string);
             if (!empty($string)) {
                 $res =& $db->query($string);
                 if (PEAR::isError($res)) {
                     die("Cannot execute {$string}: " . $res->getMessage());
                 }
             }
         }
     }
 }
コード例 #18
0
 /**
  * @param $rev
  */
 public function upgrade_4_2_2($rev)
 {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.2.2')), 'task_4_2_x_runSql', $rev);
     //create line items for memberships and participants for api/import
     self::convertContribution();
     // CRM-10937 Fix the title on civicrm_dedupe_rule_group
     $upgrade = new CRM_Upgrade_Form();
     if ($upgrade->multilingual) {
         // Check if the 'title' field exists
         $query = "SELECT column_name\n                  FROM information_schema.COLUMNS\n                 WHERE table_name = 'civicrm_dedupe_rule_group'\n                   AND table_schema = DATABASE()\n                   AND column_name = 'title'";
         $dao = CRM_Core_DAO::executeQuery($query);
         if (!$dao->N) {
             $domain = new CRM_Core_DAO_Domain();
             $domain->find(TRUE);
             if ($domain->locales) {
                 $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
                 $locale = array_shift($locales);
                 // Use the first language (they should all have the same value)
                 CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_dedupe_rule_group` CHANGE `title_{$locale}` `title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Label of the rule group'", $params, TRUE, NULL, FALSE, FALSE);
                 // Drop remaining the column for the remaining languages
                 foreach ($locales as $locale) {
                     CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_dedupe_rule_group` DROP `title_{$locale}`", $params, TRUE, NULL, FALSE, FALSE);
                 }
             }
         }
     }
 }
コード例 #19
0
 /**
  * Get all word-replacements in the form of an array.
  *
  * @param int $id
  *   Domain ID.
  *
  * @return array
  * @see civicrm_domain.locale_custom_strings
  */
 public static function getAllAsConfigArray($id)
 {
     $query = "\nSELECT find_word,replace_word,is_active,match_type\nFROM   civicrm_word_replacement\nWHERE  domain_id = %1\n";
     $params = array(1 => array($id, 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $params);
     $overrides = array();
     while ($dao->fetch()) {
         if ($dao->is_active == 1) {
             $overrides['enabled'][$dao->match_type][$dao->find_word] = $dao->replace_word;
         } else {
             $overrides['disabled'][$dao->match_type][$dao->find_word] = $dao->replace_word;
         }
     }
     $config = CRM_Core_Config::singleton();
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     // So. Weird. Some bizarre/probably-broken multi-lingual thing where
     // data isn't really stored in civicrm_word_replacements. Probably
     // shouldn't exist.
     $stringOverride = self::_getLocaleCustomStrings($id);
     $stringOverride[$config->lcMessages] = $overrides;
     return $stringOverride;
 }
コード例 #20
0
 public function postProcess()
 {
     $values = $this->exportValues();
     // FIXME: stupid QF not submitting unchecked checkboxen…
     if (!isset($values['inheritLocale'])) {
         $values['inheritLocale'] = 0;
     }
     //cache contact fields retaining localized titles
     //though we changed localization, so reseting cache.
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
     CRM_Core_BAO_Cache::deleteGroup('navigation');
     // we do this only to initialize monetary decimal point and thousand separator
     $config = CRM_Core_Config::singleton();
     // set default Currency Symbol
     $values['defaultCurrencySymbol'] = $config->defaultCurrencySymbol($values['defaultCurrency']);
     // save enabled currencies and defaul currency in option group 'currencies_enabled'
     // CRM-1496
     if (empty($values['currencyLimit'])) {
         $values['currencyLimit'] = array($values['defaultCurrency']);
     } elseif (!in_array($values['defaultCurrency'], $values['currencyLimit'])) {
         $values['currencyLimit'][] = $values['defaultCurrency'];
     }
     // sort so that when we display drop down, weights have right value
     sort($values['currencyLimit']);
     // get labels for all the currencies
     $options = array();
     for ($i = 0; $i < count($values['currencyLimit']); $i++) {
         $options[] = array('label' => $this->_currencySymbols[$values['currencyLimit'][$i]], 'value' => $values['currencyLimit'][$i], 'weight' => $i + 1, 'is_active' => 1, 'is_default' => $values['currencyLimit'][$i] == $values['defaultCurrency']);
     }
     $dontCare = NULL;
     CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare);
     // unset currencyLimit so we dont store there
     unset($values['currencyLimit']);
     // make the site multi-lang if requested
     if (!empty($values['makeMultilingual'])) {
         CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']);
         $values['languageLimit'][$values['lcMessages']] = 1;
         // make the site single-lang if requested
     } elseif (!empty($values['makeSinglelingual'])) {
         CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']);
         $values['languageLimit'] = '';
     }
     // add a new db locale if the requested language is not yet supported by the db
     if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) {
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(TRUE);
         if (!substr_count($domain->locales, $values['addLanguage'])) {
             CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']);
         }
         $values['languageLimit'][$values['addLanguage']] = 1;
     }
     // if we manipulated the language list, return to the localization admin screen
     $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values));
     // save all the settings
     parent::commonProcess($values);
     if ($return) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1'));
     }
 }
コード例 #21
0
ファイル: Schema.php プロジェクト: ksecor/civicrm
 /**
  * Switch database from multi-lang back to single (by dropping 
  * additional columns and views and retaining only the selected locale).
  *
  * @param $retain string  the locale to retain
  * @return void
  */
 function makeSinglelingual($retain)
 {
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(true);
     $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
     // break early if the db is already single-lang
     if (!$locales) {
         return;
     }
     // build the column-dropping SQL queries
     $columns =& CRM_Core_I18n_SchemaStructure::columns();
     $indices =& CRM_Core_I18n_SchemaStructure::indices();
     $queries = array();
     foreach ($columns as $table => $hash) {
         // drop old indices
         if (isset($indices[$table])) {
             foreach ($indices[$table] as $index) {
                 foreach ($locales as $loc) {
                     $queries[] = "DROP INDEX {$index['name']}_{$loc} ON {$table}";
                 }
             }
         }
         // drop triggers
         $queries[] = "DROP TRIGGER IF EXISTS {$table}_before_insert";
         $queries[] = "DROP TRIGGER IF EXISTS {$table}_before_update";
         // deal with columns
         foreach ($hash as $column => $type) {
             $queries[] = "ALTER TABLE {$table} ADD {$column} {$type}";
             $queries[] = "UPDATE {$table} SET {$column} = {$column}_{$retain}";
             foreach ($locales as $loc) {
                 $queries[] = "ALTER TABLE {$table} DROP {$column}_{$loc}";
             }
         }
         // drop views
         foreach ($locales as $loc) {
             $queries[] = "DROP VIEW {$table}_{$loc}";
         }
         // add original indices
         $queries = array_merge($queries, self::createIndexQueries(null, $table));
     }
     // execute the queries without i18n rewriting
     $dao = new CRM_Core_DAO();
     foreach ($queries as $query) {
         $dao->query($query, false);
     }
     // update civicrm_domain.locales
     $domain->locales = 'NULL';
     $domain->save();
 }
コード例 #22
0
ファイル: Step3.php プロジェクト: prashantgajare/civicrm-core
 function mailerPreferences()
 {
     $mailerValues = array();
     $mailerFields = array('outBound_option', 'smtpServer', 'smtpPort', 'smtpAuth', 'smtpUsername', 'smtpPassword', 'sendmail_path', 'sendmail_args');
     //get the mailer preferences from backend
     //store in civicrm_preferences and unset from backend.
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $backendValues = unserialize($domain->config_backend);
         foreach ($mailerFields as $field) {
             $mailerValues[$field] = CRM_Utils_Array::value($field, $backendValues);
             if (array_key_exists($field, $backendValues)) {
                 unset($backendValues[$field]);
             }
         }
         $domain->config_backend = serialize($backendValues);
         $domain->save();
         $sql = 'SELECT id, mailing_backend FROM civicrm_preferences';
         $mailingDomain = CRM_Core_DAO::executeQuery($sql);
         $mailingDomain->find(TRUE);
         $mailingDomain->mailing_backend = serialize($mailerValues);
         $mailingDomain->save();
     }
 }
コード例 #23
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $this->_numStrings = sizeof($params['old']);
     $enabled['exactMatch'] = $enabled['wildcardMatch'] = $disabled['exactMatch'] = $disabled['wildcardMatch'] = array();
     for ($i = 1; $i <= $this->_numStrings; $i++) {
         if (CRM_Utils_Array::value($i, $params['new']) && CRM_Utils_Array::value($i, $params['old'])) {
             if (isset($params['enabled']) && CRM_Utils_Array::value($i, $params['enabled'])) {
                 if (CRM_Utils_Array::value('cb', $params) && CRM_Utils_Array::value($i, $params['cb'])) {
                     $enabled['exactMatch'] += array($params['old'][$i] => $params['new'][$i]);
                 } else {
                     $enabled['wildcardMatch'] += array($params['old'][$i] => $params['new'][$i]);
                 }
             } else {
                 if (isset($params['cb']) && is_array($params['cb']) && array_key_exists($i, $params['cb'])) {
                     $disabled['exactMatch'] += array($params['old'][$i] => $params['new'][$i]);
                 } else {
                     $disabled['wildcardMatch'] += array($params['old'][$i] => $params['new'][$i]);
                 }
             }
         }
     }
     $overrides = array('enabled' => $enabled, 'disabled' => $disabled);
     $config = CRM_Core_Config::singleton();
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if ($domain->locales && $config->localeCustomStrings) {
         // for multilingual
         $addReplacements = $config->localeCustomStrings;
         $addReplacements[$config->lcMessages] = $overrides;
         $stringOverride = serialize($addReplacements);
     } else {
         // for single language
         $stringOverride = serialize(array($config->lcMessages => $overrides));
     }
     $params = array('locale_custom_strings' => $stringOverride);
     $id = CRM_Core_Config::domainID();
     $wordReplacementSettings = CRM_Core_BAO_Domain::edit($params, $id);
     if ($wordReplacementSettings) {
         //reset navigation
         CRM_Core_BAO_Navigation::resetNavigation();
         CRM_Core_Session::setStatus("Your Settings have been saved");
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/options/wordreplacements', "reset=1"));
     }
 }
コード例 #24
0
ファイル: FourFive.php プロジェクト: nielosz/civicrm-core
 /**
  * Migrate honoree information to uf_join.module_data as honoree columns (text and title) will be dropped
  * on DB upgrade
  *
  * @param CRM_Queue_TaskContext $ctx
  *
  * @return bool
  *   TRUE for success
  */
 public static function migrateHonoreeInfo(CRM_Queue_TaskContext $ctx)
 {
     $query = "ALTER TABLE `civicrm_uf_join`\n    ADD COLUMN `module_data` longtext COMMENT 'Json serialized array of data used by the ufjoin.module'";
     CRM_Core_DAO::executeQuery($query);
     $honorTypes = array_keys(CRM_Core_OptionGroup::values('honor_type'));
     $ufGroupDAO = new CRM_Core_DAO_UFGroup();
     $ufGroupDAO->name = 'new_individual';
     $ufGroupDAO->find(TRUE);
     $query = "SELECT * FROM civicrm_contribution_page";
     $dao = CRM_Core_DAO::executeQuery($query);
     if ($dao->N) {
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(TRUE);
         while ($dao->fetch()) {
             $honorParams = array('soft_credit' => array('soft_credit_types' => $honorTypes));
             if ($domain->locales) {
                 $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
                 foreach ($locales as $locale) {
                     $honor_block_title = "honor_block_title_{$locale}";
                     $honor_block_text = "honor_block_text_{$locale}";
                     $honorParams['soft_credit'] += array($locale => array('honor_block_title' => $dao->{$honor_block_title}, 'honor_block_text' => $dao->{$honor_block_text}));
                 }
             } else {
                 $honorParams['soft_credit'] += array('default' => array('honor_block_title' => $dao->honor_block_title, 'honor_block_text' => $dao->honor_block_text));
             }
             $ufJoinParam = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'is_active' => $dao->honor_block_is_active, 'entity_id' => $dao->id, 'uf_group_id' => $ufGroupDAO->id, 'module_data' => json_encode($honorParams));
             CRM_Core_BAO_UFJoin::create($ufJoinParam);
         }
     }
     return TRUE;
 }
コード例 #25
0
ファイル: FourSeven.php プロジェクト: nyimbi/civicrm-core
 /**
  * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped
  * on DB upgrade
  *
  * @param CRM_Queue_TaskContext $ctx
  *
  * @return bool
  *   TRUE for success
  */
 public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext $ctx)
 {
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     // fetch onBehalf entry in UFJoin table
     $ufGroupDAO = new CRM_Core_DAO_UFJoin();
     $ufGroupDAO->module = 'OnBehalf';
     $ufGroupDAO->find(TRUE);
     $forOrgColums = array();
     if ($domain->locales) {
         $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
         foreach ($locales as $locale) {
             $forOrgColums[] = "for_organization_{$locale}";
         }
     } else {
         $forOrgColums[] = "for_organization";
     }
     $query = "\n      SELECT " . implode(", ", $forOrgColums) . ", uj.id as join_id, uj.uf_group_id as uf_group_id\n      FROM civicrm_contribution_page cp\n       INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'";
     $dao = CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE);
     if ($dao->N) {
         while ($dao->fetch()) {
             $onBehalfParams['on_behalf'] = array('is_for_organization' => $dao->is_for_organization);
             if ($domain->locales) {
                 foreach ($locales as $locale) {
                     $for_organization = "for_organization_{$locale}";
                     $onBehalfParams['on_behalf'] += array($locale => array('for_organization' => $dao->{$for_organization}));
                 }
             } else {
                 $onBehalfParams['on_behalf'] += array('default' => array('for_organization' => $dao->for_organization));
             }
             $ufJoinParam = array('id' => $dao->join_id, 'module' => 'on_behalf', 'uf_group_id' => $dao->uf_group_id, 'module_data' => json_encode($onBehalfParams));
             CRM_Core_BAO_UFJoin::create($ufJoinParam);
         }
     }
     return TRUE;
 }
コード例 #26
0
 /**
  * Retrieve the settings values from db.
  *
  * @param $defaults
  *
  * @return array
  */
 public static function retrieve(&$defaults)
 {
     $domain = new CRM_Core_DAO_Domain();
     //we are initializing config, really can't use, CRM-7863
     $urlVar = 'q';
     if (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') {
         $urlVar = 'task';
     }
     if (CRM_Core_Config::isUpgradeMode()) {
         $domain->selectAdd('config_backend');
     } elseif (CRM_Utils_Array::value($urlVar, $_GET) == 'admin/modules/list/confirm') {
         $domain->selectAdd('config_backend', 'locales');
     } else {
         $domain->selectAdd('config_backend, locales, locale_custom_strings');
     }
     $domain->id = CRM_Core_Config::domainID();
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         if ($defaults === FALSE || !is_array($defaults)) {
             $defaults = array();
             return FALSE;
         }
         $skipVars = self::skipVars();
         foreach ($skipVars as $skip) {
             if (array_key_exists($skip, $defaults)) {
                 unset($defaults[$skip]);
             }
         }
         // check if there are any locale strings
         if ($domain->locale_custom_strings) {
             $defaults['localeCustomStrings'] = unserialize($domain->locale_custom_strings);
         } else {
             $defaults['localeCustomStrings'] = NULL;
         }
         // are we in a multi-language setup?
         $multiLang = $domain->locales ? TRUE : FALSE;
         // set the current language
         $lcMessages = NULL;
         $session = CRM_Core_Session::singleton();
         // on multi-lang sites based on request and civicrm_uf_match
         if ($multiLang) {
             $lcMessagesRequest = CRM_Utils_Request::retrieve('lcMessages', 'String', $this);
             $languageLimit = array();
             if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
                 $languageLimit = $defaults['languageLimit'];
             }
             if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
                 $lcMessages = $lcMessagesRequest;
                 //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
                 CRM_Core_BAO_Cache::deleteGroup('navigation');
             } else {
                 $lcMessagesRequest = NULL;
             }
             if (!$lcMessagesRequest) {
                 $lcMessagesSession = $session->get('lcMessages');
                 if (in_array($lcMessagesSession, array_keys($languageLimit))) {
                     $lcMessages = $lcMessagesSession;
                 } else {
                     $lcMessagesSession = NULL;
                 }
             }
             if ($lcMessagesRequest) {
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(TRUE)) {
                     $ufm->language = $lcMessages;
                     $ufm->save();
                 }
                 $session->set('lcMessages', $lcMessages);
             }
             if (!$lcMessages and $session->get('userID')) {
                 $ufm = new CRM_Core_DAO_UFMatch();
                 $ufm->contact_id = $session->get('userID');
                 if ($ufm->find(TRUE) && in_array($ufm->language, array_keys($languageLimit))) {
                     $lcMessages = $ufm->language;
                 }
                 $session->set('lcMessages', $lcMessages);
             }
         }
         global $dbLocale;
         // try to inherit the language from the hosting CMS
         if (!empty($defaults['inheritLocale'])) {
             // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set
             $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : '';
             $lcMessages = CRM_Utils_System::getUFLocale();
             if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales))) {
                 $lcMessages = NULL;
             }
         }
         if (empty($lcMessages)) {
             //CRM-11993 - if a single-lang site, use default
             $lcMessages = CRM_Utils_Array::value('lcMessages', $defaults);
         }
         // set suffix for table names - use views if more than one language
         $dbLocale = $multiLang ? "_{$lcMessages}" : '';
         // FIXME: an ugly hack to fix CRM-4041
         global $tsLocale;
         $tsLocale = $lcMessages;
         // FIXME: as bad aplace as any to fix CRM-5428
         // (to be moved to a sane location along with the above)
         if (function_exists('mb_internal_encoding')) {
             mb_internal_encoding('UTF-8');
         }
     }
     // dont add if its empty
     if (!empty($defaults)) {
         // retrieve directory and url preferences also
         CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($defaults);
         // Pickup enabled-components from settings table if found.
         $enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
         if (!empty($enableComponents)) {
             $defaults['enableComponents'] = $enableComponents;
             $components = CRM_Core_Component::getComponents();
             $enabledComponentIDs = array();
             foreach ($defaults['enableComponents'] as $name) {
                 $enabledComponentIDs[] = $components[$name]->componentID;
             }
             $defaults['enableComponentIDs'] = $enabledComponentIDs;
         }
     }
 }
コード例 #27
0
ファイル: ThreeZero.php プロジェクト: bhirsch/voipdev
 function upgrade($rev)
 {
     // fix CRM-5270: if civicrm_report_instance.description is localised,
     // recreate it based on the first locale’s description_xx_YY contents
     // and drop all the description_xx_YY columns
     if (!CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'description')) {
         require_once 'CRM/Core/DAO/Domain.php';
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(true);
         $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
         CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance ADD description VARCHAR(255)");
         CRM_Core_DAO::executeQuery("UPDATE civicrm_report_instance SET description = description_{$locales[0]}");
         CRM_Core_DAO::executeQuery("DROP TRIGGER civicrm_report_instance_before_insert");
         foreach ($locales as $locale) {
             CRM_Core_DAO::executeQuery("DROP VIEW civicrm_report_instance_{$locale}");
             CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance DROP description_{$locale}");
         }
     }
     //We execute some part of php after sql and then again sql
     //So using conditions for skipping some part of sql CRM-4575
     $upgrade =& new CRM_Upgrade_Form();
     //Run the SQL file (1)
     $upgrade->processSQL($rev);
     //replace  with ; in report instance
     $sql = "UPDATE civicrm_report_instance \n                       SET form_values = REPLACE(form_values,'#',';') ";
     CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     //delete unnecessary activities
     $bulkEmailID = CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name');
     if ($bulkEmailID) {
         $mailingActivityIds = array();
         $query = " \n            SELECT max( ca.id ) as aid, \n                   ca.source_record_id sid\n            FROM civicrm_activity ca\n            WHERE ca.activity_type_id = %1 \n            GROUP BY ca.source_record_id";
         $params = array(1 => array($bulkEmailID, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($query, $params);
         while ($dao->fetch()) {
             $updateQuery = "\n                UPDATE civicrm_activity_target cat, civicrm_activity ca \n                    SET cat.activity_id = {$dao->aid}  \n                WHERE ca.source_record_id IS NOT NULL   AND\n                      ca.activity_type_id = %1          AND \n                      ca.id <> {$dao->aid}              AND \n                      ca.source_record_id = {$dao->sid} AND \n                      ca.id = cat.activity_id";
             $updateParams = array(1 => array($bulkEmailID, 'Integer'));
             CRM_Core_DAO::executeQuery($updateQuery, $updateParams);
             $deleteQuery = " \n                DELETE ca.* \n                FROM civicrm_activity ca \n                WHERE ca.source_record_id IS NOT NULL  AND \n                      ca.activity_type_id = %1         AND \n                      ca.id <> {$dao->aid}             AND \n                      ca.source_record_id = {$dao->sid}";
             $deleteParams = array(1 => array($bulkEmailID, 'Integer'));
             CRM_Core_DAO::executeQuery($deleteQuery, $deleteParams);
         }
     }
     //CRM-4453
     //lets insert column in civicrm_aprticipant table
     $query = "\n        ALTER TABLE `civicrm_participant` \n            ADD `fee_currency` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '3 character string, value derived from config setting.' AFTER `discount_id`";
     CRM_Core_DAO::executeQuery($query);
     //get currency from contribution table if exists/default
     //insert currency when fee_amount != NULL or event is paid.
     $query = "\n        SELECT  civicrm_participant.id \n        FROM    civicrm_participant\n            LEFT JOIN  civicrm_event \n                   ON ( civicrm_participant.event_id = civicrm_event.id )\n        WHERE  civicrm_participant.fee_amount IS NOT NULL OR \n               civicrm_event.is_monetary = 1";
     $participant = CRM_Core_DAO::executeQuery($query);
     while ($participant->fetch()) {
         $query = "\n            SELECT civicrm_contribution.currency \n            FROM   civicrm_contribution, \n                   civicrm_participant_payment\n            WHERE  civicrm_contribution.id = civicrm_participant_payment.contribution_id AND  \n                   civicrm_participant_payment.participant_id = {$participant->id}";
         $currencyID = CRM_Core_DAO::singleValueQuery($query);
         if (!$currencyID) {
             $config =& CRM_Core_Config::singleton();
             $currencyID = $config->defaultCurrency;
         }
         //finally update participant record.
         CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Participant', $participant->id, 'fee_currency', $currencyID);
     }
     //CRM-4575
     //check whether {contact.name} is set in mailing labels
     require_once 'CRM/Core/BAO/Preferences.php';
     $mailingFormat = CRM_Core_BAO_Preferences::value('mailing_format');
     $addNewAddressee = true;
     if (strpos($mailingFormat, '{contact.contact_name}') === false) {
         $addNewAddressee = false;
     } else {
         //else compare individual name format with default individual addressee.
         $individualNameFormat = CRM_Core_BAO_Preferences::value('individual_name_format');
         $defaultAddressee = CRM_Core_OptionGroup::values('addressee', false, false, false, " AND v.filter = 1 AND v.is_default =  1", 'label');
         if (array_search($individualNameFormat, $defaultAddressee) !== false) {
             $addNewAddressee = false;
         }
     }
     require_once 'CRM/Utils/System.php';
     $docURL = CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', false, null, null, 'color: white; text-decoration: underline;');
     if ($addNewAddressee) {
         //otherwise insert new token in addressee and set as a default
         $addresseeGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'addressee', 'id', 'name');
         $optionValueParams = array('label' => $individualNameFormat, 'is_active' => 1, 'contactOptions' => 1, 'filter' => 1, 'is_default' => 1, 'reset_default_for' => array('filter' => "0, 1"));
         $action = CRM_Core_Action::ADD;
         $addresseeGroupParams = array('name' => 'addressee');
         $fieldValues = array('option_group_id' => $addresseeGroupId);
         $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
         $optionValueParams['weight'] = $weight;
         $addresseeToken = CRM_Core_OptionValue::addOptionValue($optionValueParams, $addresseeGroupParams, $action, $optionId = null);
         $afterUpgradeMessage = ts("During this upgrade, Postal Addressee values have been stored for each contact record using the system default format - %2.You will need to run the included command-line script to update your Individual contact records to use the \"Individual Name Format\" previously specified for your site %1", array(1 => $docURL, 2 => array_pop($defaultAddressee)));
     } else {
         $afterUpgradeMessage = ts("Email Greeting, Postal Greeting and Postal Addressee values have been stored for all contact records based on the system default formats. If you want to use a different format for any of these contact fields - you can run the provided command line script to update contacts to a different format %1 ", array(1 => $docURL));
     }
     //replace contact.contact_name with contact.addressee in civicrm_preference.mailing_format
     $updateQuery = "\n        UPDATE civicrm_preferences \n               SET `mailing_format` = \n                    replace(`mailing_format`, '{contact.contact_name}','{contact.addressee}')";
     CRM_Core_DAO::executeQuery($updateQuery);
     //drop column individual_name_format
     $alterQuery = "\n        ALTER TABLE `civicrm_preferences`\n              DROP `individual_name_format`";
     CRM_Core_DAO::executeQuery($alterQuery);
     //set status message for default greetings
     $template =& CRM_Core_Smarty::singleton();
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
 }
コード例 #28
0
 /**
  * Get or Set honor/on_behalf params for processing module_data or setting default values.
  *
  * @param array $params :
  * @param bool $setDefault : If yes then returns array to used for setting default value afterward
  * @param string $module : processing module_data for which module? e.g. soft_credit, on_behalf
  *
  * @return array|string
  */
 public static function formatModuleData($params, $setDefault = FALSE, $module)
 {
     $tsLocale = CRM_Core_I18n::getLocale();
     $config = CRM_Core_Config::singleton();
     $json = $jsonDecode = NULL;
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $moduleDataFormat = array('soft_credit' => array(1 => 'soft_credit_types', 'multilingual' => array('honor_block_title', 'honor_block_text')), 'on_behalf' => array(1 => 'is_for_organization', 'multilingual' => array('for_organization')));
     //When we are fetching the honor params respecting both multi and mono lingual state
     //and setting it to default param of Contribution Page's Main and Setting form
     if ($setDefault) {
         $jsonDecode = json_decode($params);
         $jsonDecode = (array) $jsonDecode->{$module};
         if (!$domain->locales && !empty($jsonDecode['default'])) {
             //monolingual state
             $jsonDecode += (array) $jsonDecode['default'];
             unset($jsonDecode['default']);
         } elseif (!empty($jsonDecode[$tsLocale])) {
             //multilingual state
             foreach ($jsonDecode[$tsLocale] as $column => $value) {
                 $jsonDecode[$column] = $value;
             }
             unset($jsonDecode[$tsLocale]);
         }
         return $jsonDecode;
     }
     //check and handle multilingual honoree params
     if (!$domain->locales) {
         //if in singlelingual state simply return the array format
         $json = array($module => NULL);
         foreach ($moduleDataFormat[$module] as $key => $attribute) {
             if ($key === 'multilingual') {
                 $json[$module]['default'] = array();
                 foreach ($attribute as $attr) {
                     $json[$module]['default'][$attr] = $params[$attr];
                 }
             } else {
                 $json[$module][$attribute] = $params[$attribute];
             }
         }
         $json = json_encode($json);
     } else {
         //if in multilingual state then retrieve the module_data against this contribution and
         //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
         $json = array($module => NULL);
         foreach ($moduleDataFormat[$module] as $key => $attribute) {
             if ($key === 'multilingual') {
                 $json[$module][$config->lcMessages] = array();
                 foreach ($attribute as $attr) {
                     $json[$module][$config->lcMessages][$attr] = $params[$attr];
                 }
             } else {
                 $json[$module][$attribute] = $params[$attribute];
             }
         }
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = $module;
         $ufJoinDAO->entity_id = $params['id'];
         $ufJoinDAO->find(TRUE);
         $jsonData = json_decode($ufJoinDAO->module_data);
         if ($jsonData) {
             $json[$module] = array_merge((array) $jsonData->{$module}, $json[$module]);
         }
         $json = json_encode($json);
     }
     return $json;
 }
コード例 #29
0
 static function createIndexes(&$tables, $createIndexPrefix = 'index', $substrLenghts = array())
 {
     $queries = array();
     require_once 'CRM/Core/DAO/Domain.php';
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
     // if we're multilingual, cache the information on internationalised fields
     static $columns = NULL;
     if (!CRM_Utils_System::isNull($locales) and $columns === NULL) {
         $columns = CRM_Core_I18n_SchemaStructure::columns();
     }
     foreach ($tables as $table => $fields) {
         $query = "SHOW INDEX FROM {$table}";
         $dao = CRM_Core_DAO::executeQuery($query);
         $currentIndexes = array();
         while ($dao->fetch()) {
             $currentIndexes[] = $dao->Key_name;
         }
         // now check for all fields if the index exists
         foreach ($fields as $field) {
             // handle indices over substrings, CRM-6245
             // $lengthName is appended to index name, $lengthSize is the field size modifier
             $lengthName = isset($substrLenghts[$table][$field]) ? "_{$substrLenghts[$table][$field]}" : '';
             $lengthSize = isset($substrLenghts[$table][$field]) ? "({$substrLenghts[$table][$field]})" : '';
             $names = array("index_{$field}{$lengthName}", "FK_{$table}_{$field}{$lengthName}", "UI_{$field}{$lengthName}", "{$createIndexPrefix}_{$field}{$lengthName}");
             // skip to the next $field if one of the above $names exists; handle multilingual for CRM-4126
             foreach ($names as $name) {
                 $regex = '/^' . preg_quote($name) . '(_[a-z][a-z]_[A-Z][A-Z])?$/';
                 if (preg_grep($regex, $currentIndexes)) {
                     continue 2;
                 }
             }
             // the index doesn't exist, so create it
             // if we're multilingual and the field is internationalised, do it for every locale
             if (!CRM_Utils_System::isNull($locales) and isset($columns[$table][$field])) {
                 foreach ($locales as $locale) {
                     $queries[] = "CREATE INDEX {$createIndexPrefix}_{$field}{$lengthName}_{$locale} ON {$table} ({$field}_{$locale}{$lengthSize})";
                 }
             } else {
                 $queries[] = "CREATE INDEX {$createIndexPrefix}_{$field}{$lengthName} ON {$table} ({$field}{$lengthSize})";
             }
         }
     }
     // run the queries without i18n-rewriting
     $dao = new CRM_Core_DAO();
     foreach ($queries as $query) {
         $dao->query($query, FALSE);
     }
 }
コード例 #30
0
 /**
  * Get or Set multilingually affected honor params for processing module_data or setting default values.
  *
  * @param string $params :
  * @param bool $setDefault : If yes then returns array to used for setting default value afterward
  *
  * @return array|string
  */
 public static function formatMultilingualHonorParams($params, $setDefault = FALSE)
 {
     $config = CRM_Core_Config::singleton();
     $sctJson = $sctJsonDecode = NULL;
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     //When we are fetching the honor params respecting both multi and mono lingual state
     //and setting it to default param of Contribution Page's Main and Setting form
     if ($setDefault) {
         $sctJsonDecode = json_decode($params);
         $sctJsonDecode = (array) $sctJsonDecode->soft_credit;
         if (!$domain->locales && !empty($sctJsonDecode['default'])) {
             //monolingual state
             $sctJsonDecode += (array) $sctJsonDecode['default'];
         } elseif (!empty($sctJsonDecode[$config->lcMessages])) {
             //multilingual state
             foreach ($sctJsonDecode[$config->lcMessages] as $column => $value) {
                 $sctJsonDecode[$column] = $value;
             }
             unset($sctJsonDecode[$config->lcMessages]);
         }
         return $sctJsonDecode;
     }
     //check and handle multilingual honoree params
     if (!$domain->locales) {
         //if in singlelingual state simply return the array format
         $sctJson = json_encode(array('soft_credit' => array('soft_credit_types' => $params['soft_credit_types'], 'default' => array('honor_block_title' => $params['honor_block_title'], 'honor_block_text' => $params['honor_block_text']))));
     } else {
         //if in multilingual state then retrieve the module_data against this contribution and
         //merge with earlier module_data json data to current so not to lose earlier multilingual module_data information
         $sctJson = array('soft_credit' => array('soft_credit_types' => $params['soft_credit_types'], $config->lcMessages => array('honor_block_title' => $params['honor_block_title'], 'honor_block_text' => $params['honor_block_text'])));
         $ufJoinDAO = new CRM_Core_DAO_UFJoin();
         $ufJoinDAO->module = 'soft_credit';
         $ufJoinDAO->entity_id = $params['id'];
         $ufJoinDAO->find(TRUE);
         $jsonData = json_decode($ufJoinDAO->module_data);
         if ($jsonData) {
             $sctJson['soft_credit'] = array_merge((array) $jsonData->soft_credit, $sctJson['soft_credit']);
         }
         $sctJson = json_encode($sctJson);
     }
     return $sctJson;
 }