public function setUp()
 {
     parent::setUp();
     $this->loadAllFixtures();
     CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
     CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign');
 }
Example #2
0
 /**
  * @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');
 }
 function upgrade_4_1_alpha1($rev)
 {
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviCase', $config->enableComponents)) {
         if (!CRM_Case_BAO_Case::createCaseViews()) {
             $template = CRM_Core_Smarty::singleton();
             $afterUpgradeMessage = '';
             if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
                 $afterUpgradeMessage .= "<br/><br/>";
             }
             $afterUpgradeMessage .= '<div class="crm-upgrade-case-views-error" style="background-color: #E43D2B; padding: 10px;">' . ts("There was a problem creating CiviCase database views. Please create the following views manually before using CiviCase:");
             $afterUpgradeMessage .= '<div class="crm-upgrade-case-views-query"><div>' . CRM_Case_BAO_Case::createCaseViewsQuery('upcoming') . '</div><div>' . CRM_Case_BAO_Case::createCaseViewsQuery('recent') . '</div>' . '</div></div>';
             $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
         }
     }
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
     $this->transferPreferencesToSettings();
     $this->createNewSettings();
     // now modify the config so that the directories are now stored in the settings table
     // CRM-8780
     $params = array();
     CRM_Core_BAO_ConfigSetting::add($params);
     // also reset navigation
     CRM_Core_BAO_Navigation::resetNavigation();
 }
Example #4
0
/**
 * Implementation of hook_civicrm_install
 */
function hrprofile_civicrm_install()
{
    $groups = CRM_Core_PseudoConstant::get('CRM_Core_BAO_UFField', 'uf_group_id', array('labelColumn' => 'name'));
    $profileId = array_search('hrstaffdir_listing', $groups);
    $path = array('url' => "civicrm/profile?reset=1&gid={$profileId}&force=1");
    $navigationPath = CRM_Core_BAO_Navigation::retrieve($path, $defaultpath);
    if ($profileId && $navigationPath) {
        $originalUrl = "civicrm/profile?reset=1&gid={$profileId}&force=1";
        $updatedUrl = "civicrm/profile/table?reset=1&gid={$profileId}&force=1";
        hrprofile_updateNavigation($originalUrl, $updatedUrl);
    } elseif ($profileId && !$navigationPath) {
        // add to navigation
        $navigationParams = array('label' => 'Directory', 'url' => "civicrm/profile/table?reset=1&gid={$profileId}&force=1", 'is_active' => 1);
        $navigation = CRM_Core_BAO_Navigation::add($navigationParams);
        CRM_Core_BAO_Navigation::resetNavigation();
        // set the profile as search view
        $params = array();
        CRM_Core_BAO_ConfigSetting::retrieve($params);
        if (!empty($params)) {
            $params['defaultSearchProfileID'] = $profileId;
            CRM_Core_BAO_ConfigSetting::create($params);
        }
    }
    return _hrprofile_civix_civicrm_install();
}
Example #5
0
 public function setUp()
 {
     parent::setUp();
     $this->tablesToTruncate = array('civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_case', 'civicrm_case_contact', 'civicrm_case_activity', 'civicrm_case_type', 'civicrm_activity_contact', 'civicrm_managed', 'civicrm_relationship', 'civicrm_relationship_type');
     $this->quickCleanup($this->tablesToTruncate);
     $this->loadAllFixtures();
     CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
 }
 function setDefaultValues()
 {
     if (!$this->_defaults) {
         parent::setDefaultValues();
         $config = CRM_Core_Config::singleton();
         list($this->_defaults['newBaseURL'], $this->_defaults['newBaseDir'], $this->_defaults['newSiteName']) = CRM_Core_BAO_ConfigSetting::getBestGuessSettings();
     }
     return $this->_defaults;
 }
Example #7
0
/**
 *
 * @package CRM
 * @copyright CiviCRM LLC (c) 2004-2016
 */
function run()
{
    session_start();
    require_once '../../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton();
    // this does not return on failure
    CRM_Utils_System::authenticateScript(TRUE);
    require_once 'CRM/Core/BAO/ConfigSetting.php';
    $moveStatus = CRM_Core_BAO_ConfigSetting::doSiteMove();
    echo $moveStatus . '<br />';
    echo ts("If no errors are displayed above, the site move steps have completed successfully. Please visit <a href=\"{$config->userFrameworkBaseURL}\">your moved site</a> and test the move.");
}
 public function testToggleComponent()
 {
     $origNames = array();
     foreach (CRM_Core_Component::getEnabledComponents() as $c) {
         $origNames[] = $c->name;
     }
     $this->assertTrue(!in_array('CiviCase', $origNames));
     $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
     $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
     $newNames = array();
     foreach (CRM_Core_Component::getEnabledComponents() as $c) {
         $newNames[] = $c->name;
     }
     $this->assertTrue(in_array('CiviCase', $newNames));
     $this->assertEquals(count($newNames), count($origNames) + 1);
 }
 public function postProcess()
 {
     if (!empty($_POST['_qf_UpdateConfigBackend_next_cleanup'])) {
         $config = CRM_Core_Config::singleton();
         // cleanup templates_c directory
         $config->cleanup(1, FALSE);
         // clear all caches
         CRM_Core_Config::clearDBCache();
         CRM_Utils_System::flushCache();
         parent::rebuildMenu();
         CRM_Core_BAO_WordReplacement::rebuild();
         CRM_Core_Session::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success");
     }
     if (!empty($_POST['_qf_UpdateConfigBackend_next_resetpaths'])) {
         $msg = CRM_Core_BAO_ConfigSetting::doSiteMove();
         CRM_Core_Session::setStatus($msg, ts("Success"), "success");
     }
     return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1'));
 }
 public function setUp()
 {
     parent::setUp();
     /** @var $hooks \CRM_Utils_Hook_UnitTests */
     $hooks = \CRM_Utils_Hook::singleton();
     $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes'));
     \CRM_Case_XMLRepository::singleton(TRUE);
     \CRM_Case_XMLProcessor::flushStaticCaches();
     // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types
     //. Using XML was causing breakage as id numbers were changing over time
     // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
     // state where tests could run afterwards without re-loading.
     $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array('name' => 'case_status', 'format.only_id' => 1));
     $optionValues = array('Medical evaluation' => 'Medical evaluation', 'Mental health evaluation' => "Mental health evaluation", 'Secure temporary housing' => 'Secure temporary housing', 'Long-term housing plan' => 'Long-term housing plan', 'ADC referral' => 'ADC referral', 'Income and benefits stabilization' => 'Income and benefits stabilization');
     foreach ($optionValues as $name => $label) {
         $activityTypes = $this->callAPISuccess('option_value', 'Create', array('option_group_id' => 2, 'name' => $name, 'label' => $label, 'component_id' => 7));
         // store for cleanup
         $this->optionValues[] = $activityTypes['id'];
     }
     // We used to be inconsistent about "HousingSupport" vs "housing_support".
     // Now, the rule is simply: use the "name" from "civicrm_case_type.name".
     $this->caseType = 'housing_support';
     $this->caseTypeId = 1;
     $this->tablesToTruncate = array('civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_case', 'civicrm_case_contact', 'civicrm_case_activity', 'civicrm_case_type', 'civicrm_activity_contact', 'civicrm_managed', 'civicrm_relationship', 'civicrm_relationship_type');
     $this->quickCleanup($this->tablesToTruncate);
     $this->loadAllFixtures();
     // enable the default custom templates for the case type xml files
     $this->customDirectories(array('template_path' => TRUE));
     // case is not enabled by default
     $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
     $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
     // create a logged in USER since the code references it for source_contact_id
     $this->createLoggedInUser();
     $session = CRM_Core_Session::singleton();
     $this->_loggedInUser = $session->get('userID');
     /// note that activityType options are cached by the FULL set of options you pass in
     // ie. because Activity api includes campaign in it's call cache is not flushed unless
     // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array
     CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
 }
Example #11
0
 /**
  * @return bool
  */
 public function populate()
 {
     \Civi\Test::schema()->truncateAll();
     \Civi\Test::schema()->setStrict(FALSE);
     $sqlDir = dirname(dirname(__DIR__)) . "/sql";
     $query2 = file_get_contents("{$sqlDir}/civicrm_data.mysql");
     $query3 = file_get_contents("{$sqlDir}/test_data.mysql");
     $query4 = file_get_contents("{$sqlDir}/test_data_second_domain.mysql");
     if (\Civi\Test::execute($query2) === FALSE) {
         throw new RuntimeException("Cannot load civicrm_data.mysql. Aborting.");
     }
     if (\Civi\Test::execute($query3) === FALSE) {
         throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
     }
     if (\Civi\Test::execute($query4) === FALSE) {
         throw new RuntimeException("Cannot load test_data.mysql. Aborting.");
     }
     unset($query, $query2, $query3);
     \Civi\Test::schema()->setStrict(TRUE);
     // Rebuild triggers
     civicrm_api('system', 'flush', array('version' => 3, 'triggers' => 1));
     \CRM_Core_BAO_ConfigSetting::setEnabledComponents(array('CiviEvent', 'CiviContribute', 'CiviMember', 'CiviMail', 'CiviReport', 'CiviPledge'));
     return TRUE;
 }
Example #12
0
 function verifyPreDBState(&$errorMessage)
 {
     $config = CRM_Core_Config::singleton();
     // Let's first update the 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';
         // update cms-version
         if ($config->userFramework == 'Joomla') {
             $defaults['userFrameworkVersion'] = '1.5';
             if (class_exists('JVersion')) {
                 $version = new JVersion();
                 $defaults['userFrameworkVersion'] = $version->getShortVersion();
             }
         } elseif ($config->userSystem->is_drupal) {
             $defaults['userFrameworkVersion'] = '6.3';
             if (defined('VERSION')) {
                 $defaults['userFrameworkVersion'] = VERSION;
             }
         }
         // serialise settings
         CRM_Core_BAO_ConfigSetting::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"), ts('Redundant Tables'), 'info');
     }
     // 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;
 }
Example #13
0
 /**
  * Set up function.
  *
  * Ensure CiviCase is enabled.
  */
 public function setUp()
 {
     parent::setUp();
     CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
 }
Example #14
0
 /**
  * Initialize the config variables.
  *
  * @return void
  */
 private function _initVariables()
 {
     // retrieve serialised settings
     $variables = array();
     CRM_Core_BAO_ConfigSetting::retrieve($variables);
     // if settings are not available, go down the full path
     if (empty($variables)) {
         // Step 1. get system variables with their hardcoded defaults
         $variables = get_object_vars($this);
         // Step 2. get default values (with settings file overrides if
         // available - handled in CRM_Core_Config_Defaults)
         CRM_Core_Config_Defaults::setValues($variables);
         // retrieve directory and url preferences also
         CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($variables);
         // add component specific settings
         $this->componentRegistry->addConfig($this);
         // serialise settings
         $settings = $variables;
         CRM_Core_BAO_ConfigSetting::add($settings);
     }
     $urlArray = array('userFrameworkResourceURL', 'imageUploadURL');
     $dirArray = array('uploadDir', 'customFileUploadDir');
     foreach ($variables as $key => $value) {
         if (in_array($key, $urlArray)) {
             $value = CRM_Utils_File::addTrailingSlash($value, '/');
         } elseif (in_array($key, $dirArray)) {
             if ($value) {
                 $value = CRM_Utils_File::addTrailingSlash($value);
             }
             if (empty($value) || CRM_Utils_File::createDir($value, FALSE) === FALSE) {
                 // seems like we could not create the directories
                 // settings might have changed, lets suppress a message for now
                 // so we can make some more progress and let the user fix their settings
                 // for now we assign it to a know value
                 // CRM-4949
                 $value = $this->templateCompileDir;
                 $url = CRM_Utils_System::url('civicrm/admin/setting/path', 'reset=1');
                 CRM_Core_Session::setStatus(ts('%1 has an incorrect directory path. Please go to the <a href="%2">path setting page</a> and correct it.', array(1 => $key, 2 => $url)), ts('Check Settings'), 'alert');
             }
         } elseif ($key == 'lcMessages') {
             // reset the templateCompileDir to locale-specific and make sure it exists
             if (substr($this->templateCompileDir, -1 * strlen($value) - 1, -1) != $value) {
                 $this->templateCompileDir .= CRM_Utils_File::addTrailingSlash($value);
                 CRM_Utils_File::createDir($this->templateCompileDir);
                 CRM_Utils_File::restrictAccess($this->templateCompileDir);
             }
         }
         $this->{$key} = $value;
     }
     if ($this->userFrameworkResourceURL) {
         // we need to do this here so all blocks also load from an ssl server
         if (CRM_Utils_System::isSSL()) {
             CRM_Utils_System::mapConfigToSSL();
         }
         $rrb = parse_url($this->userFrameworkResourceURL);
         // don't use absolute path if resources are stored on a different server
         // CRM-4642
         $this->resourceBase = $this->userFrameworkResourceURL;
         if (isset($_SERVER['HTTP_HOST']) && isset($rrb['host'])) {
             $this->resourceBase = $rrb['host'] == $_SERVER['HTTP_HOST'] ? $rrb['path'] : $this->userFrameworkResourceURL;
         }
     }
     if (!$this->customFileUploadDir) {
         $this->customFileUploadDir = $this->uploadDir;
     }
     if ($this->geoProvider) {
         $this->geocodeMethod = 'CRM_Utils_Geocode_' . $this->geoProvider;
     } elseif ($this->mapProvider) {
         $this->geocodeMethod = 'CRM_Utils_Geocode_' . $this->mapProvider;
     }
     require_once str_replace('_', DIRECTORY_SEPARATOR, $this->userFrameworkClass) . '.php';
     $class = $this->userFrameworkClass;
     // redundant with _setUserFrameworkConfig
     $this->userSystem = new $class();
 }
Example #15
0
 /**
  *  Test setup for every test
  *
  *  Connect to the database, truncate the tables that will be used
  *  and redirect stdin to a temporary file
  */
 public function setUp()
 {
     $this->_entity = 'case';
     parent::setUp();
     // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types
     //. Using XML was causing breakage as id numbers were changing over time
     // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
     // state where tests could run afterwards without re-loading.
     $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array('name' => 'case_status', 'format.only_id' => 1));
     $this->caseTypeGroup = $this->callAPISuccess('option_group', 'get', array('name' => 'case_type', 'format.only_id' => 1));
     $caseTypes = $this->callAPISuccess('option_value', 'Create', array('option_group_id' => $this->caseTypeGroup, 'name' => 'housing_support', 'label' => "Housing Support", 'sequential' => 1, 'description' => 'Help homeless individuals obtain temporary and long-term housing'));
     $this->caseTypeId = $caseTypes['values'][0]['value'];
     $this->optionValues[] = $caseTypes['id'];
     $optionValues = array('Medical evaluation' => 'Medical evaluation', 'Mental health evaluation' => "Mental health evaluation", 'Secure temporary housing' => 'Secure temporary housing', 'Long-term housing plan' => 'Long-term housing plan', 'ADC referral' => 'ADC referral', 'Income and benefits stabilization' => 'Income and benefits stabilization');
     foreach ($optionValues as $name => $label) {
         $activityTypes = $this->callAPISuccess('option_value', 'Create', array('option_group_id' => 2, 'name' => $name, 'label' => $label, 'component_id' => 7));
         // store for cleanup
         $this->optionValues[] = $activityTypes['id'];
     }
     $tablesToTruncate = array('civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_case', 'civicrm_case_contact', 'civicrm_case_activity', 'civicrm_activity_contact', 'civicrm_relationship', 'civicrm_relationship_type');
     $this->quickCleanup($tablesToTruncate);
     $activityTypes = $this->callAPISuccess('option_value', 'get', array('option_group_id' => 2, 'name' => 'Follow Up', 'label' => 'Follow Up', 'sequential' => 1));
     $this->followup_activity_type_value = $activityTypes['values'][0]['value'];
     //  Insert a row in civicrm_contact creating contact 17
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml'));
     //Create relationship types
     $relTypeParams = array('name_a_b' => 'Case Coordinator is', 'label_a_b' => 'Case Coordinator is', 'name_b_a' => 'Case Coordinator', 'label_b_a' => 'Case Coordinator', 'description' => 'Case Coordinator', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1);
     $this->relationshipTypeCreate($relTypeParams);
     $relTypeParams = array('name_a_b' => 'Homeless Services Coordinator is', 'label_a_b' => 'Homeless Services Coordinator is', 'name_b_a' => 'Homeless Services Coordinator', 'label_b_a' => 'Homeless Services Coordinator', 'description' => 'Homeless Services Coordinator', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1);
     $this->relationshipTypeCreate($relTypeParams);
     $relTypeParams = array('name_a_b' => 'Health Services Coordinator is', 'label_a_b' => 'Health Services Coordinator is', 'name_b_a' => 'Health Services Coordinator', 'label_b_a' => 'Health Services Coordinator', 'description' => 'Health Services Coordinator', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1);
     $this->relationshipTypeCreate($relTypeParams);
     $relTypeParams = array('name_a_b' => 'Senior Services Coordinator is', 'label_a_b' => 'Senior Services Coordinator is', 'name_b_a' => 'Senior Services Coordinator', 'label_b_a' => 'Senior Services Coordinator', 'description' => 'Senior Services Coordinator', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1);
     $this->relationshipTypeCreate($relTypeParams);
     $relTypeParams = array('name_a_b' => 'Benefits Specialist is', 'label_a_b' => 'Benefits Specialist is', 'name_b_a' => 'Benefits Specialist', 'label_b_a' => 'Benefits Specialist', 'description' => 'Benefits Specialist', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1);
     $this->relationshipTypeCreate($relTypeParams);
     // enable the default custom templates for the case type xml files
     $this->customDirectories(array('template_path' => TRUE));
     // case is not enabled by default
     $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
     $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
     $this->_params = array('case_type_id' => $this->caseTypeId, 'subject' => 'Test case', 'contact_id' => 17);
     // create a logged in USER since the code references it for source_contact_id
     $this->createLoggedInUser();
     $session = CRM_Core_Session::singleton();
     $this->_loggedInUser = $session->get('userID');
     /// note that activityType options are cached by the FULL set of options you pass in
     // ie. because Activity api includes campaign in it's call cache is not flushed unless
     // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array
     CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
 }
 /**
  * @param array $params
  *   - mailerBatchLimit
  *   - mailerJobSize
  *   - mailerJobsMax
  *   - mailThrottleTime
  */
 protected function setSettings($params)
 {
     // FIXME: These settings are not available via Setting API.
     // When they become available, use that instead.
     CRM_Core_BAO_ConfigSetting::create($params);
 }
Example #17
0
 public function testEnableComponentInvalid()
 {
     $config = CRM_Core_Config::singleton(TRUE, TRUE);
     $result = CRM_Core_BAO_ConfigSetting::enableComponent('CiviFake');
     $this->assertFalse($result);
 }
 /**
  * @return array
  */
 public static function custom_data_entities()
 {
     $entities = CRM_Core_BAO_CustomQuery::$extendsMap;
     $enabledComponents = Civi::settings()->get('enable_components');
     $customDataEntities = array();
     $invalidEntities = array('Individual', 'Organization', 'Household');
     $entitiesToFix = array('Case', 'Relationship');
     foreach ($entities as $entityName => $entity) {
         if (!in_array($entityName, $invalidEntities) && !in_array($entityName, $entitiesToFix)) {
             if (!empty(self::$componentMap[$entityName]) && empty($enabledComponents[self::$componentMap[$entityName]])) {
                 CRM_Core_BAO_ConfigSetting::enableComponent(self::$componentMap[$entityName]);
             }
             $customDataEntities[] = array($entityName);
         }
     }
     return $customDataEntities;
 }
Example #19
0
 /**
  * @param $rev
  */
 public function upgrade_4_4_1($rev)
 {
     $config = CRM_Core_Config::singleton();
     // CRM-13327 upgrade handling for the newly added name badges
     $ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'name_badge', 'id', 'name');
     $nameBadges = array_flip(array_values(CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('name_badge')));
     unset($nameBadges['Avery 5395']);
     if (!empty($nameBadges)) {
         $dimension = '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":4,"metric":"mm","lMargin":6,"tMargin":19,"SpaceX":0,"SpaceY":0,"width":100,"height":65,"lPadding":0,"tPadding":0}';
         $query = "UPDATE civicrm_option_value\n        SET value = '{$dimension}'\n        WHERE option_group_id = %1 AND name = 'Fattorini Name Badge 100x65'";
         CRM_Core_DAO::executeQuery($query, array(1 => array($ogID, 'Integer')));
     } else {
         $dimensions = array(1 => '{"paper-size":"a4","orientation":"landscape","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":1,"metric":"mm","lMargin":25,"tMargin":27,"SpaceX":0,"SpaceY":35,"width":106,"height":150,"lPadding":5,"tPadding":5}', 2 => '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":4,"metric":"mm","lMargin":6,"tMargin":19,"SpaceX":0,"SpaceY":0,"width":100,"height":65,"lPadding":0,"tPadding":0}', 3 => '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":2,"metric":"mm","lMargin":10,"tMargin":28,"SpaceX":0,"SpaceY":0,"width":96,"height":121,"lPadding":5,"tPadding":5}');
         $insertStatements = array(1 => "({$ogID}, %1, '{$dimensions[1]}', %1, NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL)", 2 => "({$ogID}, %2, '{$dimensions[2]}', %2, NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL)", 3 => "({$ogID}, %3, '{$dimensions[3]}', %3, NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL)");
         $queryParams = array(1 => array('A6 Badge Portrait 150x106', 'String'), 2 => array('Fattorini Name Badge 100x65', 'String'), 3 => array('Hanging Badge 3-3/4" x 4-3"/4', 'String'));
         foreach ($insertStatements as $values) {
             $query = 'INSERT INTO civicrm_option_value (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`) VALUES' . $values;
             CRM_Core_DAO::executeQuery($query, $queryParams);
         }
     }
     // CRM-12578 - Prior to this version a CSS file under drupal would disable core css
     if (!empty($config->customCSSURL) && strpos($config->userFramework, 'Drupal') === 0) {
         // The new setting doesn't exist yet - need to create it first
         $sql = '
     INSERT INTO civicrm_setting (group_name, name , value , domain_id , is_domain , created_date)
     VALUES (%1, %2, %3, %4, %5, now())';
         CRM_Core_DAO::executeQuery($sql, array(1 => array(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'String'), 2 => array('disable_core_css', 'String'), 3 => array(serialize(1), 'String'), 4 => array(CRM_Core_Config::domainID(), 'Positive'), 5 => array(1, 'Int')));
         Civi::service('settings_manager')->flush();
     }
     // CRM-13701 - Fix $config->timeInputFormat
     $sql = "\n      SELECT time_format\n      FROM   civicrm_preferences_date\n      WHERE  time_format IS NOT NULL\n      AND    time_format <> ''\n      LIMIT  1\n    ";
     $timeInputFormat = CRM_Core_DAO::singleValueQuery($sql);
     if ($timeInputFormat && $timeInputFormat != $config->timeInputFormat) {
         $params = array('timeInputFormat' => $timeInputFormat);
         CRM_Core_BAO_ConfigSetting::add($params);
     }
     // CRM-13698 - add 'Available' and 'No-show' activity statuses
     $insertStatus = array();
     $nsinc = $avinc = $inc = 0;
     if (!CRM_Core_OptionGroup::getValue('activity_status', 'Available', 'name')) {
         $insertStatus[] = "(%1, 'Available', %2, 'Available',  NULL, 0, NULL, %3, 0, 0, 1, NULL, NULL)";
         $avinc = $inc = 1;
     }
     if (!CRM_Core_OptionGroup::getValue('activity_status', 'No_show', 'name')) {
         $insertStatus[] = "(%1, 'No-show', %4, 'No_show',  NULL, 0, NULL, %5, 0, 0, 1, NULL, NULL)";
         $nsinc = $inc + 1;
     }
     if (!empty($insertStatus)) {
         $acOptionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_status', 'id', 'name');
         $maxVal = CRM_Core_DAO::singleValueQuery("SELECT MAX(ROUND(op.value)) FROM civicrm_option_value op WHERE op.option_group_id  = {$acOptionGroupID}");
         $maxWeight = CRM_Core_DAO::singleValueQuery("SELECT MAX(weight) FROM civicrm_option_value WHERE option_group_id = {$acOptionGroupID}");
         $p[1] = array($acOptionGroupID, 'Integer');
         if ($avinc) {
             $p[2] = array($avinc + $maxVal, 'Integer');
             $p[3] = array($avinc + $maxWeight, 'Integer');
         }
         if ($nsinc) {
             $p[4] = array($nsinc + $maxVal, 'Integer');
             $p[5] = array($nsinc + $maxWeight, 'Integer');
         }
         $insertStatus = implode(',', $insertStatus);
         $sql = "\nINSERT INTO\n   civicrm_option_value (`option_group_id`, label, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`)\nVALUES {$insertStatus}";
         CRM_Core_DAO::executeQuery($sql, $p);
     }
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.1')), 'runSql', $rev);
     $this->addTask('Patch word-replacement schema', 'wordReplacements_patch', $rev);
 }
 /**
 * Function to process the form
 *
 * @access public
 * @return None
 */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $config = CRM_Core_Config::singleton();
     $configParams = array();
     require_once 'CRM/Event/PseudoConstant.php';
     $event_type = CRM_Event_PseudoConstant::eventType();
     $colorevents = $event_type;
     foreach ($event_type as $k => $v) {
         $v = str_replace(" ", "_", $v);
         $evnt_color = 'eventcolor_' . $k;
         $eventname = 'eventtype_' . $k;
         if (!empty($params[$evnt_color]) && !empty($params[$eventname])) {
             $configParams[$v] = $params[$evnt_color];
             $configParams[$eventname] = $params[$eventname];
         } else {
             $configParams[$v] = '3366CC';
             $configParams[$eventname] = 0;
         }
         $event_type[$k] = $v;
     }
     foreach ($event_type as $k => $v) {
         $evnt_key = 'eventtype_' . $k;
         if (!array_key_exists($evnt_key, $params)) {
             unset($event_type[$k]);
         }
     }
     $configParams['civicrm_events_event_types'] = $event_type;
     if (isset($params['event_calendar_title'])) {
         $configParams['civicrm_event_calendar_title'] = $params['event_calendar_title'];
     } else {
         $configParams['civicrm_event_calendar_title'] = 'Event Calendar';
     }
     if (isset($params['show_past_event']) && $params['show_past_event'] == 1) {
         $configParams['civicrm_events_event_past'] = $params['show_past_event'];
     } else {
         $configParams['civicrm_events_event_past'] = 0;
     }
     if (isset($params['show_end_date']) && $params['show_end_date'] == 1) {
         $configParams['civicrm_events_event_end_date'] = $params['show_end_date'];
     } else {
         $configParams['civicrm_events_event_end_date'] = 0;
     }
     if (isset($params['event_is_public']) && $params['event_is_public'] == 1) {
         $configParams['civicrm_events_event_is_public'] = $params['event_is_public'];
     } else {
         $configParams['civicrm_events_event_is_public'] = 0;
     }
     if (isset($params['events_event_month']) && $params['events_event_month'] == 1) {
         $configParams['civicrm_events_event_months'] = $params['show_event_from_month'];
     } else {
         $configParams['civicrm_events_event_months'] = 0;
     }
     if (isset($params['show_event_from_month'])) {
         $configParams['show_event_from_month'] = $params['show_event_from_month'];
     } else {
         $configParams['show_event_from_month'] = '';
     }
     CRM_Core_BAO_ConfigSetting::create($configParams);
     CRM_Core_Session::setStatus(" ", ts('The value has been saved.'), "success");
 }
Example #21
0
 /**
  * Common Process.
  *
  * @todo Document what I do.
  *
  * @param array $params
  */
 public function commonProcess(&$params)
 {
     // save autocomplete search options
     if (!empty($params['autocompleteContactSearch'])) {
         $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['autocompleteContactSearch'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         CRM_Core_BAO_Setting::setItem($value, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_autocomplete_options');
         unset($params['autocompleteContactSearch']);
     }
     // save autocomplete contact reference options
     if (!empty($params['autocompleteContactReference'])) {
         $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['autocompleteContactReference'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         CRM_Core_BAO_Setting::setItem($value, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_reference_options');
         unset($params['autocompleteContactReference']);
     }
     // save components to be enabled
     if (array_key_exists('enableComponents', $params)) {
         civicrm_api3('setting', 'create', array('enable_components' => $params['enableComponents']));
         unset($params['enableComponents']);
     }
     // save checksum timeout
     if (!empty($params['checksumTimeout'])) {
         CRM_Core_BAO_Setting::setItem($params['checksumTimeout'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'checksum_timeout');
     }
     // update time for date formats when global time is changed
     if (!empty($params['timeInputFormat'])) {
         $query = "\nUPDATE civicrm_preferences_date\nSET    time_format = %1\nWHERE  time_format IS NOT NULL\nAND    time_format <> ''\n";
         $sqlParams = array(1 => array($params['timeInputFormat'], 'String'));
         CRM_Core_DAO::executeQuery($query, $sqlParams);
     }
     // verify ssl peer option
     if (isset($params['verifySSL'])) {
         CRM_Core_BAO_Setting::setItem($params['verifySSL'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
         unset($params['verifySSL']);
     }
     // force secure URLs
     if (isset($params['enableSSL'])) {
         CRM_Core_BAO_Setting::setItem($params['enableSSL'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL');
         unset($params['enableSSL']);
     }
     $settings = array_intersect_key($params, $this->_settings);
     $result = civicrm_api('setting', 'create', $settings + array('version' => 3));
     foreach ($settings as $setting => $settingGroup) {
         //@todo array_diff this
         unset($params[$setting]);
     }
     CRM_Core_BAO_ConfigSetting::create($params);
     CRM_Core_Config::clearDBCache();
     CRM_Utils_System::flushCache();
     CRM_Core_Resources::singleton()->resetCacheCode();
     CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success");
 }
 /**
  * Perform an incremental upgrade
  *
  * @param $rev string, the revision to which we are upgrading (Note: When processing a series of upgrades, this is the immediate upgrade - not the final)
  */
 static function upgrade_2_2_7($rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
     $sql = "UPDATE civicrm_report_instance \n                       SET form_values = REPLACE(form_values,'#',';') ";
     CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     // make report component enabled by default
     $domain = new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     $domain->selectAdd('config_backend');
     $domain->find(TRUE);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         if (is_array($defaults['enableComponents'])) {
             $compId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_component WHERE name = 'CiviReport'");
             if ($compId) {
                 $defaults['enableComponents'][] = 'CiviReport';
                 $defaults['enableComponentIDs'][] = $compId;
                 CRM_Core_BAO_ConfigSetting::add($defaults);
             }
         }
     }
 }
Example #23
0
 /**
  * Common Process.
  *
  * @todo Document what I do.
  *
  * @param array $params
  */
 public function commonProcess(&$params)
 {
     // save autocomplete search options
     if (!empty($params['autocompleteContactSearch'])) {
         $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['autocompleteContactSearch'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         CRM_Core_BAO_Setting::setItem($value, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_autocomplete_options');
         unset($params['autocompleteContactSearch']);
     }
     // save autocomplete contact reference options
     if (!empty($params['autocompleteContactReference'])) {
         $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['autocompleteContactReference'])) . CRM_Core_DAO::VALUE_SEPARATOR;
         CRM_Core_BAO_Setting::setItem($value, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_reference_options');
         unset($params['autocompleteContactReference']);
     }
     // save components to be enabled
     if (array_key_exists('enableComponents', $params)) {
         civicrm_api3('setting', 'create', array('enable_components' => $params['enableComponents']));
         unset($params['enableComponents']);
     }
     // save checksum timeout
     if (!empty($params['checksumTimeout'])) {
         CRM_Core_BAO_Setting::setItem($params['checksumTimeout'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'checksum_timeout');
     }
     // verify ssl peer option
     if (isset($params['verifySSL'])) {
         CRM_Core_BAO_Setting::setItem($params['verifySSL'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
         unset($params['verifySSL']);
     }
     // force secure URLs
     if (isset($params['enableSSL'])) {
         CRM_Core_BAO_Setting::setItem($params['enableSSL'], CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL');
         unset($params['enableSSL']);
     }
     $settings = array_intersect_key($params, $this->_settings);
     $result = civicrm_api('setting', 'create', $settings + array('version' => 3));
     foreach ($settings as $setting => $settingGroup) {
         //@todo array_diff this
         unset($params[$setting]);
     }
     if (!empty($result['error_message'])) {
         CRM_Core_Session::setStatus($result['error_message'], ts('Save Failed'), 'error');
     }
     CRM_Core_BAO_ConfigSetting::create($params);
     CRM_Core_Config::clearDBCache();
     CRM_Utils_System::flushCache();
     CRM_Core_Resources::singleton()->resetCacheCode();
     CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success");
 }
 /**
  * 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');
     } else {
         $domain->selectAdd('config_backend, locales');
     }
     $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]);
             }
         }
         CRM_Core_BAO_ConfigSetting::applyLocale(Civi::settings($domain->id), $domain->locales);
     }
 }
Example #25
0
 /**
  * Common Process.
  *
  * @todo Document what I do.
  *
  * @param array $params
  */
 public function commonProcess(&$params)
 {
     // save autocomplete search options
     if (!empty($params['contact_autocomplete_options'])) {
         Civi::settings()->set('contact_autocomplete_options', CRM_Utils_Array::implodePadded(array_keys($params['contact_autocomplete_options'])));
         unset($params['contact_autocomplete_options']);
     }
     // save autocomplete contact reference options
     if (!empty($params['contact_reference_options'])) {
         Civi::settings()->set('contact_reference_options', CRM_Utils_Array::implodePadded(array_keys($params['contact_reference_options'])));
         unset($params['contact_reference_options']);
     }
     // save components to be enabled
     if (array_key_exists('enableComponents', $params)) {
         civicrm_api3('setting', 'create', array('enable_components' => $params['enableComponents']));
         unset($params['enableComponents']);
     }
     // verify ssl peer option
     if (isset($params['verifySSL'])) {
         Civi::settings()->set('verifySSL', $params['verifySSL']);
         unset($params['verifySSL']);
     }
     // force secure URLs
     if (isset($params['enableSSL'])) {
         Civi::settings()->set('enableSSL', $params['enableSSL']);
         unset($params['enableSSL']);
     }
     $settings = array_intersect_key($params, $this->_settings);
     $result = civicrm_api('setting', 'create', $settings + array('version' => 3));
     foreach ($settings as $setting => $settingGroup) {
         //@todo array_diff this
         unset($params[$setting]);
     }
     if (!empty($result['error_message'])) {
         CRM_Core_Session::setStatus($result['error_message'], ts('Save Failed'), 'error');
     }
     //CRM_Core_BAO_ConfigSetting::create($params);
     $params = CRM_Core_BAO_ConfigSetting::filterSkipVars($params);
     if (!empty($params)) {
         CRM_Core_Error::fatal('Unrecognized setting. This may be a config field which has not been properly migrated to a setting. (' . implode(', ', array_keys($params)) . ')');
     }
     CRM_Core_Config::clearDBCache();
     CRM_Utils_System::flushCache();
     CRM_Core_Resources::singleton()->resetCacheCode();
     CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success");
 }
Example #26
0
 /**
  * Enable CiviCampaign Component.
  */
 public function enableCiviCampaign()
 {
     CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign');
     // force reload of config object
     $config = CRM_Core_Config::singleton(TRUE, TRUE);
     //flush cache by calling with reset
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
 }
Example #27
0
 /**
  * Store multiple items in the setting table. Note that this will also store config keys
  * the storage is determined by the metdata and is affected by
  *  'name' setting's name
  *  'prefetch' = store in config
  *  'config_only' = don't store in settings
  *  'config_key' = the config key is different to the settings key - e.g. debug where there was a conflict
  *  'legacy_key' = rename from config or setting with this name
  *
  * _setItem() is the common logic shared by setItem() and setItems().
  *
  * @param array $params
  *   (required) An api formatted array of keys and values.
  * @param null $domains
  *
  * @throws api_Exception
  * @domains array an array of domains to get settings for. Default is the current domain
  * @return array
  */
 public static function setItems(&$params, $domains = NULL)
 {
     $originalDomain = CRM_Core_Config::domainID();
     if (empty($domains)) {
         $domains[] = $originalDomain;
     }
     $reloadConfig = FALSE;
     $fields = $config_keys = array();
     $fieldsToSet = self::validateSettingsInput($params, $fields);
     foreach ($fieldsToSet as $settingField => &$settingValue) {
         self::validateSetting($settingValue, $fields['values'][$settingField]);
     }
     foreach ($domains as $domainID) {
         if ($domainID != CRM_Core_Config::domainID()) {
             $reloadConfig = TRUE;
             CRM_Core_BAO_Domain::setDomain($domainID);
         }
         $result[$domainID] = array();
         foreach ($fieldsToSet as $name => $value) {
             if (empty($fields['values'][$name]['config_only'])) {
                 CRM_Core_BAO_Setting::_setItem($fields['values'][$name], $value, $fields['values'][$name]['group_name'], $name, CRM_Utils_Array::value('component_id', $params), CRM_Utils_Array::value('contact_id', $params), CRM_Utils_Array::value('created_id', $params), $domainID);
             }
             if (!empty($fields['values'][$name]['prefetch'])) {
                 if (!empty($fields['values'][$name]['config_key'])) {
                     $name = $fields['values'][$name]['config_key'];
                 }
                 $config_keys[$name] = $value;
             }
             $result[$domainID][$name] = $value;
         }
         if ($reloadConfig) {
             CRM_Core_Config::singleton($reloadConfig, $reloadConfig);
         }
         if (!empty($config_keys)) {
             CRM_Core_BAO_ConfigSetting::create($config_keys);
         }
         if ($reloadConfig) {
             CRM_Core_BAO_Domain::resetDomain();
         }
     }
     return $result;
 }
Example #28
0
 public static function doFinish()
 {
     $upgrade = new CRM_Upgrade_Form();
     list($ignore, $latestVer) = $upgrade->getUpgradeVersions();
     // Seems extraneous in context, but we'll preserve old behavior
     $upgrade->setVersion($latestVer);
     // lets rebuild the config array in case we've made a few changes in the
     // code base
     // this also helps us always store the latest version of civi in the DB
     $params = array();
     CRM_Core_BAO_ConfigSetting::add($params);
     // CRM-12804 comment-51411 : add any missing settings
     // at the end of upgrade
     CRM_Core_BAO_Setting::updateSettingsFromMetaData();
     // cleanup caches CRM-8739
     $config = CRM_Core_Config::singleton();
     $config->cleanupCaches(1);
     // Rebuild all triggers and re-enable logging if needed
     $logging = new CRM_Logging_Schema();
     $logging->fixSchemaDifferences();
     //CRM-16257 update Config.IDS.ini might be an old copy
     CRM_Core_IDS::createConfigFile(TRUE);
 }
Example #29
0
 /**
  * Singleton function used to manage this object.
  *
  * @param bool $loadFromDB
  *   whether to load from the database.
  * @param bool $force
  *   whether to force a reconstruction.
  *
  * @return CRM_Core_Config
  */
 public static function &singleton($loadFromDB = TRUE, $force = FALSE)
 {
     if (self::$_singleton === NULL || $force) {
         $GLOBALS['civicrm_default_error_scope'] = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'handle'));
         $errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'simpleHandler'));
         if (defined('E_DEPRECATED')) {
             error_reporting(error_reporting() & ~E_DEPRECATED);
         }
         self::$_singleton = new CRM_Core_Config();
         \Civi\Core\Container::boot($loadFromDB);
         if ($loadFromDB && self::$_singleton->dsn) {
             $domain = \CRM_Core_BAO_Domain::getDomain();
             \CRM_Core_BAO_ConfigSetting::applyLocale(\Civi::settings($domain->id), $domain->locales);
             unset($errorScope);
             CRM_Utils_Hook::config(self::$_singleton);
             self::$_singleton->authenticate();
             // Extreme backward compat: $config binds to active domain at moment of setup.
             self::$_singleton->getSettings();
             Civi::service('settings_manager')->useDefaults();
             self::$_singleton->handleFirstRun();
         }
     }
     return self::$_singleton;
 }
Example #30
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     // flush caches so we reload details for future requests
     // CRM-11967
     CRM_Utils_System::flushCache();
     $formValues = $this->controller->exportValues($this->_name);
     $buttonName = $this->controller->getButtonName();
     // check if test button
     if ($buttonName == $this->_testButtonName) {
         if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED) {
             CRM_Core_Session::setStatus(ts('You have selected "Disable Outbound Email". A test email can not be sent.'), ts("Email Disabled"), "error");
         } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB) {
             CRM_Core_Session::setStatus(ts('You have selected "Redirect to Database". A test email can not be sent.'), ts("Email Disabled"), "error");
         } else {
             $session = CRM_Core_Session::singleton();
             $userID = $session->get('userID');
             list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID);
             //get the default domain email address.CRM-4250
             list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
             if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
                 $fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1');
                 CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
             }
             if (!$toEmail) {
                 CRM_Core_Error::statusBounce(ts('Cannot send a test email because your user record does not have a valid email address.'));
             }
             if (!trim($toDisplayName)) {
                 $toDisplayName = $toEmail;
             }
             $to = '"' . $toDisplayName . '"' . "<{$toEmail}>";
             $from = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
             $testMailStatusMsg = ts('Sending test email. FROM: %1 TO: %2.<br />', array(1 => $domainEmailAddress, 2 => $toEmail));
             $params = array();
             if ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
                 $subject = "Test for SMTP settings";
                 $message = "SMTP settings are correct.";
                 $params['host'] = $formValues['smtpServer'];
                 $params['port'] = $formValues['smtpPort'];
                 if ($formValues['smtpAuth']) {
                     $params['username'] = $formValues['smtpUsername'];
                     $params['password'] = $formValues['smtpPassword'];
                     $params['auth'] = TRUE;
                 } else {
                     $params['auth'] = FALSE;
                 }
                 // set the localhost value, CRM-3153, CRM-9332
                 $params['localhost'] = $_SERVER['SERVER_NAME'];
                 // also set the timeout value, lets set it to 30 seconds
                 // CRM-7510, CRM-9332
                 $params['timeout'] = 30;
                 $mailerName = 'smtp';
             } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SENDMAIL) {
                 $subject = "Test for Sendmail settings";
                 $message = "Sendmail settings are correct.";
                 $params['sendmail_path'] = $formValues['sendmail_path'];
                 $params['sendmail_args'] = $formValues['sendmail_args'];
                 $mailerName = 'sendmail';
             } elseif ($formValues['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MAIL) {
                 $subject = "Test for PHP mail settings";
                 $message = "mail settings are correct.";
                 $mailerName = 'mail';
             }
             $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
             $mailer = Mail::factory($mailerName, $params);
             $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
             $result = $mailer->send($toEmail, $headers, $message);
             unset($errorScope);
             if (!is_a($result, 'PEAR_Error')) {
                 CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', array(1 => strtoupper($mailerName))), ts("Mail Sent"), "success");
             } else {
                 $message = CRM_Utils_Mail::errorMessage($mailer, $result);
                 CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', array(1 => strtoupper($mailerName))) . $message, ts("Mail Not Sent"), "error");
             }
         }
     }
     $mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     if (!empty($mailingBackend)) {
         CRM_Core_BAO_ConfigSetting::formatParams($formValues, $mailingBackend);
     }
     // if password is present, encrypt it
     if (!empty($formValues['smtpPassword'])) {
         $formValues['smtpPassword'] = CRM_Utils_Crypt::encrypt($formValues['smtpPassword']);
     }
     CRM_Core_BAO_Setting::setItem($formValues, CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
 }