function buildQuickForm()
 {
     require_once 'UK_Direct_Debit/Form/Main.php';
     // If no civicrm_sd, then create that table
     if (!CRM_Core_DAO::checkTableExists('civicrm_sd')) {
         $creatSql = "CREATE TABLE `civicrm_sd` (\n          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n          `start_date` datetime NOT NULL,\n          `frequency_unit` enum('day','week','month','year') CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT 'month',\n          `frequency_interval` int(10) unsigned DEFAULT NULL,\n\t\t\t\t\t`amount` decimal(20,2) DEFAULT NULL,\n          `transaction_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,\n          `contact_id` int(10) unsigned DEFAULT NULL,\n          `external_id` int(10) unsigned DEFAULT NULL,\n          `membership_id` int(10) unsigned DEFAULT NULL,\n          `member_count` int(10) unsigned DEFAULT NULL,\n          `payment_processor_id` varchar(255) DEFAULT NULL,\n          `payment_instrument_id` int(10) unsigned DEFAULT NULL,\n          `cycle_day` int(10) unsigned NOT NULL DEFAULT '1',\n          `contribution_status_id` int(10) DEFAULT '1',\n          `is_valid` int(4) NOT NULL DEFAULT '1',\n          `payerReference` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,\n\t  `recur_id` int(10) unsigned DEFAULT NULL,\n          PRIMARY KEY (`id`)\n         ) ENGINE=InnoDB AUTO_INCREMENT=350 DEFAULT CHARSET=latin1";
         CRM_Core_DAO::executeQuery($creatSql);
         $columnExists = CRM_Core_DAO::checkFieldExists('civicrm_contribution_recur', 'membership_id');
         if (!$columnExists) {
             $query = "\n          ALTER TABLE civicrm_contribution_recur\n          ADD membership_id int(10) unsigned AFTER contact_id,\n          ADD CONSTRAINT FK_civicrm_contribution_recur_membership_id\n          FOREIGN KEY(membership_id) REFERENCES civicrm_membership(id) ON DELETE CASCADE ON UPDATE RESTRICT";
             CRM_Core_DAO::executeQuery($query);
         }
     } else {
         $emptySql = "TRUNCATE TABLE `civicrm_sd`";
         CRM_Core_DAO::executeQuery($emptySql);
     }
     $smartDebitArray = self::getSmartDebitPayments(NULL);
     foreach ($smartDebitArray as $key => $smartDebitRecord) {
         if ($smartDebitRecord['current_state'] == 10 || $smartDebitRecord['current_state'] == 1 || $smartDebitRecord['current_state'] == 11) {
             $regularAmount = substr($smartDebitRecord['regular_amount'], 2);
             // Extract the number from reference_number
             $output = preg_match("/\\d+/", $smartDebitRecord['reference_number'], $results);
             if ($regularAmount && $results[0]) {
                 list($y, $m, $d) = explode('-', $smartDebitRecord['start_date']);
                 $sql = "INSERT INTO `civicrm_sd`(`start_date`, `frequency_unit`, `amount`, `transaction_id`, `external_id`, `payment_processor_id`, `payment_instrument_id`, `cycle_day`, `contribution_status_id`, `frequency_interval`, `payerReference`) VALUES (%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11)";
                 $params = array(1 => array($smartDebitRecord['start_date'], 'String'), 2 => array(self::translateSmartDebitFrequencyUnit($smartDebitRecord['frequency_type']), 'String'), 3 => array($regularAmount, 'Float'), 4 => array($smartDebitRecord['reference_number'], 'String'), 5 => array($results[0], 'Int'), 6 => array(self::getSmartDebitPaymentProcessorID(), 'Int'), 7 => array(5, 'Int'), 8 => array($d, 'Int'), 9 => array(5, 'Int'), 10 => array($smartDebitRecord['frequency_factor'], 'Int'), 11 => array($smartDebitRecord['payerReference'], 'String'));
                 CRM_Core_DAO::executeQuery($sql, $params);
             }
         }
     }
     if ($smartDebitArray) {
         CRM_Core_Session::setStatus('Smart debit data retreived successfully.', 'Success', 'info');
     }
 }
Example #2
0
 function verifyPreDBState(&$errorMessage)
 {
     $latestVer = CRM_Utils_System::version();
     $errorMessage = ts('Pre-condition failed for upgrade to %1.', array(1 => $latestVer));
     // check table, if the db is 3.1
     if (CRM_Core_DAO::checkTableExists('civicrm_acl_contact_cache')) {
         $errorMessage = ts("Database check failed - it looks like you have already upgraded to the latest version (v%1) of the database. OR If you think this message is wrong, it is very likely that this a partially upgraded db and you will need to reload the correct db on which upgrade was never tried.", array(1 => $latestVer));
         return false;
     }
     // check table-column, if the db is 3.1
     if (CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'date_format')) {
         $errorMessage = ts("Database check failed - it looks like you have already upgraded to the latest version (v%1) of the database. OR If you think this message is wrong, it is very likely that this a partially upgraded db and you will need to reload the correct db on which upgrade was never tried.", array(1 => $latestVer));
         return false;
     }
     //check previous version table e.g 3.0.*
     if (!CRM_Core_DAO::checkTableExists('civicrm_participant_status_type') || !CRM_Core_DAO::checkTableExists('civicrm_navigation')) {
         $errorMessage .= ' Few important tables were found missing.';
         return false;
     }
     // check fields which MUST be present if a proper 3.0.* db
     if (!CRM_Core_DAO::checkFieldExists('civicrm_relationship_type', 'label_a_b') || !CRM_Core_DAO::checkFieldExists('civicrm_mapping_field', 'im_provider_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'email_greeting_id')) {
         // db looks to have stuck somewhere between 2.2 & 3.0
         $errorMessage .= ' Few important fields were found missing in some of the tables.';
         return false;
     }
     return true;
 }
Example #3
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');
 }
Example #4
0
 function verifyPreDBState(&$errorMessage)
 {
     $errorMessage = ts('Pre-condition failed for upgrade to 2.1.2.');
     // check if the db is 2.2
     if (!CRM_Core_DAO::checkTableExists('civicrm_event_page') && CRM_Core_DAO::checkTableExists('civicrm_pcp_block') && CRM_Core_DAO::checkTableExists('civicrm_pcp') && CRM_Core_DAO::checkTableExists('civicrm_contribution_soft')) {
         $errorMessage = ts('Database check failed - it looks like you have already upgraded to the latest version (v2.2) of the database.');
         return false;
     }
     // check if the db is 2.2
     if (CRM_Core_DAO::checkFieldExists('civicrm_participant', 'registered_by_id') && CRM_Core_DAO::checkFieldExists('civicrm_event', 'intro_text') && CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_multiple_registrations') && CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'tellfriend_limit') && CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'supporter_profile_id') && CRM_Core_DAO::checkFieldExists('civicrm_pcp', 'status_id') && CRM_Core_DAO::checkFieldExists('civicrm_pcp', 'goal_amount') && CRM_Core_DAO::checkFieldExists('civicrm_contribution_soft', 'pcp_display_in_roll') && CRM_Core_DAO::checkFieldExists('civicrm_contribution_soft', 'amount')) {
         $errorMessage = ts('Database check failed - it looks like you have already upgraded to the latest version (v2.2) of the database.');
         return false;
     }
     if (!CRM_Core_DAO::checkTableExists('civicrm_cache') || !CRM_Core_DAO::checkTableExists('civicrm_group_contact_cache') || !CRM_Core_DAO::checkTableExists('civicrm_menu') || !CRM_Core_DAO::checkTableExists('civicrm_discount') || !CRM_Core_DAO::checkTableExists('civicrm_pledge') || !CRM_Core_DAO::checkTableExists('civicrm_pledge_block') || !CRM_Core_DAO::checkTableExists('civicrm_pledge_payment')) {
         $errorMessage .= ' Few important tables were found missing.';
         return false;
     }
     // check fields which MUST be present if a proper 2.1 db
     if (!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::checkFieldExists('civicrm_discount', 'option_group_id') || !CRM_Core_DAO::checkFieldExists('civicrm_discount', 'end_date') || !CRM_Core_DAO::checkFieldExists('civicrm_group_contact_cache', 'contact_id') || !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::checkFieldExists('civicrm_option_value', 'component_id') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'id') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'name')) {
         // db looks to have stuck somewhere between 2.0 & 2.1
         $errorMessage .= ' Few important fields were found missing in some of the tables.';
         return false;
     }
     return true;
 }
Example #5
0
 function verifyPreDBState(&$errorMessage)
 {
     // check if log file is writable
     $config = CRM_Core_Config::singleton();
     if (!is_writable($config->uploadDir . 'CiviCRM.log') && !is_writable($config->uploadDir . 'CiviCRM.log.' . md5($config->dsn . $config->userFrameworkResourceURL))) {
         $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.1.');
     $is21db = true;
     // abort if partial upgraded db found.
     if ($this->checkVersion('2.1.101') || $this->checkVersion('2.1.102') || $this->checkVersion('2.1.103')) {
         $errorMessage = ts('Corrupt / Partial Upgraded database found. Looks like upgrade wizard failed to complete all the required steps to convert your database to v2.2. Please fix any errors and start the upgrade process again with a clean v2.1 database.');
         return false;
     }
     // abort if already 2.2
     if ($this->checkVersion('2.2')) {
         $errorMessage = ts('Database check failed - looks like you have already upgraded to the latest version (v2.2) of the database.');
         return false;
     }
     // check if 2.1 version
     if (!$this->checkVersion('2.1.2') || !$this->checkVersion('2.1.3') || !$this->checkVersion('2.1.4')) {
         $is21db = false;
     }
     // check if 2.1 tables exists
     if (!CRM_Core_DAO::checkTableExists('civicrm_pledge') || !CRM_Core_DAO::checkTableExists('civicrm_cache') || !CRM_Core_DAO::checkTableExists('civicrm_group_contact_cache') || !CRM_Core_DAO::checkTableExists('civicrm_discount') || !CRM_Core_DAO::checkTableExists('civicrm_menu') || !CRM_Core_DAO::checkTableExists('civicrm_pledge') || !CRM_Core_DAO::checkTableExists('civicrm_pledge_block') || !CRM_Core_DAO::checkTableExists('civicrm_case_contact')) {
         // db is not 2.1
         $errorMessage .= ' Few 2.1 tables were found missing.';
         $is21db = false;
     }
     // check fields which MUST be present if a proper 2.1 db
     if ($is21db) {
         if (!CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'is_recur_interval') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'recur_frequency_unit') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'for_organization') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'is_for_organization') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution', 'is_pay_later') || !CRM_Core_DAO::checkFieldExists('civicrm_membership', 'is_pay_later') || !CRM_Core_DAO::checkFieldExists('civicrm_membership_status', 'is_reserved') || !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'is_pay_later') || !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'fee_amount') || !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'registered_by_id') || !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'discount_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'employer_id') || !CRM_Core_DAO::checkFieldExists('civicrm_domain', 'locales') || !CRM_Core_DAO::checkFieldExists('civicrm_mapping', 'mapping_type_id') || !CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'is_view') || !CRM_Core_DAO::checkFieldExists('civicrm_group', 'cache_date') || !CRM_Core_DAO::checkFieldExists('civicrm_group', 'parents') || !CRM_Core_DAO::checkFieldExists('civicrm_group', 'children') || !CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'editor_id') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_group', 'group_type') || !CRM_Core_DAO::checkFieldExists('civicrm_address', 'name') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_match', 'language')) {
             // db looks to have stuck somewhere between 2.1 & 2.2
             $errorMessage .= ' Few important fields were found missing in some of the tables.';
             $is21db = false;
         }
     }
     // check if the db is 2.2
     if (!CRM_Core_DAO::checkTableExists('civicrm_event_page') && CRM_Core_DAO::checkFieldExists('civicrm_participant', 'registered_by_id') && CRM_Core_DAO::checkFieldExists('civicrm_event', 'intro_text') && CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_multiple_registrations') && CRM_Core_DAO::checkTableExists('civicrm_pcp_block') && CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'tellfriend_limit') && CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'supporter_profile_id') && CRM_Core_DAO::checkTableExists('civicrm_pcp') && CRM_Core_DAO::checkFieldExists('civicrm_pcp', 'status_id') && CRM_Core_DAO::checkFieldExists('civicrm_pcp', 'goal_amount') && CRM_Core_DAO::checkTableExists('civicrm_contribution_soft') && CRM_Core_DAO::checkFieldExists('civicrm_contribution_soft', 'pcp_display_in_roll') && CRM_Core_DAO::checkFieldExists('civicrm_contribution_soft', 'amount')) {
         $errorMessage = ts('Database check failed - it looks like you have already upgraded to the latest version (v2.2) 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;
     }
     return true;
 }
 /**
  * Given an array of contributionIDs, add them to a batch
  *
  * @param array  $contributionIDs (reference ) the array of contribution ids to be added
  * @param int    $batchID - the batchID to be added to
  *
  * @return array             (total, added, notAdded) ids of contributions added to the batch
  * @access public
  * @static
  */
 static function addContributionToBatch($contributionIDs, $batchID)
 {
     $date = date('YmdHis');
     $contributionsAdded = array();
     $contributionsNotAdded = array();
     require_once "GiftAid/Utils/GiftAid.php";
     require_once "CRM/Contribute/BAO/Contribution.php";
     require_once 'CRM/Core/DAO/EntityBatch.php';
     require_once "CRM/Core/BAO/Address.php";
     require_once "CRM/Contact/BAO/Contact.php";
     require_once "CRM/Utils/Address.php";
     $charityColumnExists = CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_submission', 'charity');
     foreach ($contributionIDs as $contributionID) {
         $batchContribution =& new CRM_Core_DAO_EntityBatch();
         $batchContribution->entity_table = 'civicrm_contribution';
         $batchContribution->entity_id = $contributionID;
         // check if the selected contribution id already in a batch
         // if not, add to batchContribution else keep the count of contributions that are not added
         if ($batchContribution->find(true)) {
             $contributionsNotAdded[] = $contributionID;
             continue;
         }
         // get additional info
         // get contribution details from Contribution using contribution id
         $params = array('id' => $contributionID);
         CRM_Contribute_BAO_Contribution::retrieve($params, $contribution, $ids);
         $contactId = $contribution['contact_id'];
         // check if contribution is valid for gift aid
         if (GiftAid_Utils_GiftAid::isEligibleForGiftAid($contactId, $contribution['receive_date'], $contributionID)) {
             $batchContribution->batch_id = $batchID;
             $batchContribution->save();
             // get display name
             $displayName = CRM_Contact_BAO_Contact::displayName($contactId);
             // get Address & Postal Code from Address
             $params = array('contact_id' => $contactId, 'is_primary' => 1);
             $address = CRM_Core_BAO_Address::getValues($params);
             $address = $address[1];
             //adds all address lines to the report
             $fullFormatedAddress = CRM_Utils_Address::format($address);
             // get gift aid amount
             $giftAidAmount = self::_calculateGiftAidAmt($contribution['total_amount']);
             // FIXME: check if there is customTable method
             $query = "\nINSERT INTO civicrm_value_gift_aid_submission \n(entity_id, eligible_for_gift_aid, name, address, post_code, amount, gift_aid_amount) \nVALUES \n  ( %1, 1, %2, %3, %4, %5, %6 )\nON DUPLICATE KEY UPDATE \nname      = %2, \naddress   = %3,\npost_code = %4,\namount    = %5,\ngift_aid_amount = %6\n";
             $sqlParams = array(1 => array($contributionID, 'Integer'), 2 => array($displayName, 'String'), 3 => array($fullFormatedAddress, 'String'), 4 => array($address['postal_code'], 'String'), 5 => array($contribution['total_amount'], 'Money'), 6 => array($giftAidAmount, 'Money'));
             CRM_Core_DAO::executeQuery($query, $sqlParams);
             $contributionsAdded[] = $contributionID;
         } else {
             $contributionsNotAdded[] = $contributionID;
         }
     }
     if (!empty($contributionsAdded)) {
         // if there is any extra work required to be done for contributions that are batched,
         // should be done via hook
         GiftAid_Utils_Hook::batchContributions($batchID, $contributionsAdded);
     }
     return array(count($contributionIDs), count($contributionsAdded), count($contributionsNotAdded));
 }
Example #7
0
 /**
  * Add column to table on install
  */
 public function install()
 {
     if (CRM_Core_DAO::checkTableExists('civicrm_contact_segment')) {
         if (!CRM_Core_DAO::checkFieldExists('civicrm_contact_segment', 'is_main')) {
             CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_contact_segment\n          ADD COLUMN is_main TINYINT(3) NULL DEFAULT 0 AFTER is_active");
         }
     } else {
         throw new Exception('This extension requires table civicrm_contact_segment
   (extension org.civicoop.contactsegment), could not find this table!');
     }
 }
Example #8
0
 function verifyPostDBState(&$errorMessage)
 {
     // check if civicrm_event_page tables droped
     if (CRM_Core_DAO::checkTableExists('civicrm_event_page')) {
         $errorMessage .= '  civicrm_event_page table is not droped.';
         return false;
     }
     // check fields which MUST be present civicrm_event
     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')) {
         $errorMessage .= ' Few important fields were found missing in civicrm_event table.';
         return false;
     }
     $errorMessage = ts('Post-condition failed for upgrade step %1.', array(1 => '2'));
     return $this->checkVersion('2.1.102');
 }
Example #9
0
 function verifyPostDBState(&$errorMessage)
 {
     if (!CRM_Core_DAO::checkTableExists('civicrm_cache') || !CRM_Core_DAO::checkTableExists('civicrm_discount') || !CRM_Core_DAO::checkTableExists('civicrm_group_contact_cache') || !CRM_Core_DAO::checkTableExists('civicrm_menu')) {
         // db is not 2.1
         $errorMessage .= ' Few 2.1 tables were found missing.';
         return false;
     }
     // check fields which MUST be present if a proper 2.1 db
     if (!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::checkFieldExists('civicrm_discount', 'option_group_id') || !CRM_Core_DAO::checkFieldExists('civicrm_discount', 'end_date') || !CRM_Core_DAO::checkFieldExists('civicrm_group_contact_cache', 'contact_id') || !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'path_arguments') || !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'is_exposed') || !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'page_type')) {
         // db looks to have stuck somewhere between 2.0 & 2.1
         $errorMessage .= ' Few important fields were found missing in some of the tables.';
         return false;
     }
     $errorMessage = ts('Post-condition failed for upgrade step %1.', array(1 => '1'));
     return $this->checkVersion('2.03');
 }
Example #10
0
 function verifyPreDBState(&$errorMessage)
 {
     $errorMessage = ts('Pre-condition failed for upgrade step %1.', array(1 => '2'));
     if (!CRM_Core_DAO::checkTableExists('civicrm_cache') || !CRM_Core_DAO::checkTableExists('civicrm_group_contact_cache') || !CRM_Core_DAO::checkTableExists('civicrm_menu') || !CRM_Core_DAO::checkTableExists('civicrm_discount') || !CRM_Core_DAO::checkTableExists('civicrm_pledge') || !CRM_Core_DAO::checkTableExists('civicrm_pledge_block') || !CRM_Core_DAO::checkTableExists('civicrm_pledge_payment')) {
         return false;
     }
     // check fields which MUST be present if a proper 2.1 db
     if (!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::checkFieldExists('civicrm_discount', 'option_group_id') || !CRM_Core_DAO::checkFieldExists('civicrm_discount', 'end_date') || !CRM_Core_DAO::checkFieldExists('civicrm_group_contact_cache', 'contact_id') || !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::checkFieldExists('civicrm_option_value', 'component_id') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'id') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'name')) {
         // db looks to have stuck somewhere between 2.0 & 2.1
         $errorMessage .= ' Few important fields were found missing in some of the tables.';
         return false;
     }
     if ($this->checkVersion('2.03')) {
         $this->setVersion($this->latestVersion);
     } else {
         return false;
     }
     return $this->checkVersion($this->latestVersion);
 }
 function verifyPostDBState(&$errorMessage)
 {
     // check if Option Group & Option Values tables exists
     if (!CRM_Core_DAO::checkTableExists('civicrm_option_group') || !CRM_Core_DAO::checkTableExists('civicrm_option_value')) {
         $errorMessage .= '  option group or option value table is missing.';
         return FALSE;
     }
     // check fields which MUST be present civicrm_option_group & civicrm_option_value
     if (!CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'id') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'name') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'label') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'description') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'is_reserved') || !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'is_active')) {
         $errorMessage .= ' Few important fields were found missing in civicrm_option_group table.';
         return FALSE;
     }
     if (!CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'id') || !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'option_group_id') || !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'name') || !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'label') || !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'description') || !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'component_id') || !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'is_active')) {
         $errorMessage .= ' Few important fields were found missing in civicrm_option_value table.';
         return FALSE;
     }
     $errorMessage = ts('Post-condition failed for upgrade step %1.', array(1 => '1'));
     return $this->checkVersion('2.02');
 }
Example #12
0
 function verifyPreDBState(&$errorMessage)
 {
     $latestVer = CRM_Utils_System::version();
     $errorMessage = ts('Pre-condition failed for upgrade to %1.', array(1 => $latestVer));
     // check tables and table-columns, if the db is already 3.1
     if (CRM_Core_DAO::checkTableExists('civicrm_acl_contact_cache') || CRM_Core_DAO::checkTableExists('civicrm_contact_type') || CRM_Core_DAO::checkTableExists('civicrm_dashboard') || CRM_Core_DAO::checkTableExists('civicrm_dashboard_contact') || CRM_Core_DAO::checkFieldExists('civicrm_country', 'is_province_abbreviated') || CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'date_format') || CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'time_format') || CRM_Core_DAO::checkFieldExists('civicrm_mail_settings', 'domain_id') || CRM_Core_DAO::checkFieldExists('civicrm_msg_template', 'workflow_id') || CRM_Core_DAO::checkFieldExists('civicrm_msg_template', 'is_default') || CRM_Core_DAO::checkFieldExists('civicrm_msg_template', 'is_reserved') || CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'domain_id') || CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'contact_autocomplete_options') || CRM_Core_DAO::checkFieldExists('civicrm_preferences_date', 'date_format') || CRM_Core_DAO::checkFieldExists('civicrm_preferences_date', 'time_format') || CRM_Core_DAO::checkFieldExists('civicrm_price_set', 'domain_id') || CRM_Core_DAO::checkFieldExists('civicrm_price_set', 'extends') || CRM_Core_DAO::checkFieldExists('civicrm_relationship_type', 'contact_sub_type_a') || CRM_Core_DAO::checkFieldExists('civicrm_relationship_type', 'contact_sub_type_b') || CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'domain_id')) {
         $errorMessage = ts("Database check failed - it looks like you have already upgraded to the latest version (v%1) of the database. OR If you think this message is wrong, it is very likely that this a partially upgraded database and you will need to reload the correct database from backup on which upgrade was never tried.", array(1 => $latestVer));
         return false;
     }
     //check previous version tables e.g 3.0.*
     if (!CRM_Core_DAO::checkTableExists('civicrm_participant_status_type') || !CRM_Core_DAO::checkTableExists('civicrm_navigation')) {
         $errorMessage .= ' Few important tables were found missing.';
         return false;
     }
     // check fields which MUST be present if a proper 3.0.* db
     if (!CRM_Core_DAO::checkFieldExists('civicrm_contact', 'email_greeting_id') || !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'created_id') || !CRM_Core_DAO::checkFieldExists('civicrm_custom_group', 'created_date') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_template') || !CRM_Core_DAO::checkFieldExists('civicrm_event', 'created_id') || !CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'created_date') || !CRM_Core_DAO::checkFieldExists('civicrm_mapping_field', 'im_provider_id') || !CRM_Core_DAO::checkFieldExists('civicrm_membership_type', 'domain_id') || !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'domain_id') || !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'fee_currency') || !CRM_Core_DAO::checkFieldExists('civicrm_payment_processor', 'domain_id') || !CRM_Core_DAO::checkFieldExists('civicrm_payment_processor_type', 'payment_type') || !CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'domain_id') || !CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'navigation') || !CRM_Core_DAO::checkFieldExists('civicrm_relationship_type', 'label_a_b') || !CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'navigation_id') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_field', 'is_reserved') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_group', 'created_id') || !CRM_Core_DAO::checkFieldExists('civicrm_uf_match', 'domain_id')) {
         // db looks to have stuck somewhere between 3.0 & 3.1
         $errorMessage .= ' Few important fields were found missing in some of the tables.';
         return false;
     }
     return true;
 }
Example #13
0
 /**
  * Load all explicit settings that apply to this domain or contact.
  *
  * @return $this
  */
 public function loadValues()
 {
     // Note: Don't use DAO child classes. They require fields() which require
     // translations -- which are keyed off settings!
     $this->values = array();
     $this->combined = NULL;
     // Ordinarily, we just load values from `civicrm_setting`. But upgrades require care.
     // In v4.0 and earlier, all values were stored in `civicrm_domain.config_backend`.
     // In v4.1-v4.6, values were split between `civicrm_domain` and `civicrm_setting`.
     // In v4.7+, all values are stored in `civicrm_setting`.
     // Whenever a value is available in civicrm_setting, it will take precedence.
     $isUpgradeMode = \CRM_Core_Config::isUpgradeMode();
     if ($isUpgradeMode && empty($this->contactId) && \CRM_Core_DAO::checkFieldExists('civicrm_domain', 'config_backend', FALSE)) {
         $config_backend = \CRM_Core_DAO::singleValueQuery('SELECT config_backend FROM civicrm_domain WHERE id = %1', array(1 => array($this->domainId, 'Positive')));
         $oldSettings = \CRM_Upgrade_Incremental_php_FourSeven::convertBackendToSettings($this->domainId, $config_backend);
         \CRM_Utils_Array::extend($this->values, $oldSettings);
     }
     // Normal case. Aside: Short-circuit prevents unnecessary query.
     if (!$isUpgradeMode || \CRM_Core_DAO::checkTableExists('civicrm_setting')) {
         $dao = \CRM_Core_DAO::executeQuery($this->createQuery()->toSQL());
         while ($dao->fetch()) {
             $this->values[$dao->name] = $dao->value !== NULL ? unserialize($dao->value) : NULL;
         }
     }
     return $this;
 }
Example #14
0
 static function get($path)
 {
     // return null if menu rebuild
     $config =& CRM_Core_Config::singleton();
     $params = array();
     $args = explode('/', $path);
     $elements = array();
     while (!empty($args)) {
         $string = implode('/', $args);
         $string = CRM_Core_DAO::escapeString($string);
         $elements[] = "'{$string}'";
         array_pop($args);
     }
     $queryString = implode(', ', $elements);
     $domainID = CRM_Core_Config::domainID();
     $domainWhereClause = " AND domain_id = {$domainID} ";
     if ($path == 'civicrm/upgrade' && !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'domain_id')) {
         //domain_id wouldn't be available for earlier version of
         //3.0 and therefore can't be used as part of query for
         //upgrade case
         $domainWhereClause = "";
     }
     $query = "\n( \n  SELECT * \n  FROM     civicrm_menu \n  WHERE    path in ( {$queryString} )\n           {$domainWhereClause}\n  ORDER BY length(path) DESC\n  LIMIT    1 \n)\n";
     if ($path != 'navigation') {
         $query .= "\nUNION ( \n  SELECT *\n  FROM   civicrm_menu \n  WHERE  path IN ( 'navigation' )\n         {$domainWhereClause}\n)\n";
     }
     require_once "CRM/Core/DAO/Menu.php";
     $menu =& new CRM_Core_DAO_Menu();
     $menu->query($query);
     self::$_menuCache = array();
     $menuPath = null;
     while ($menu->fetch()) {
         self::$_menuCache[$menu->path] = array();
         CRM_Core_DAO::storeValues($menu, self::$_menuCache[$menu->path]);
         foreach (self::$_serializedElements as $element) {
             self::$_menuCache[$menu->path][$element] = unserialize($menu->{$element});
             if (strpos($path, $menu->path) !== false) {
                 $menuPath =& self::$_menuCache[$menu->path];
             }
         }
     }
     // *FIXME* : hack for 2.1 -> 2.2 upgrades.
     if ($path == 'civicrm/upgrade') {
         $menuPath['page_callback'] = 'CRM_Upgrade_Page_Upgrade';
         $menuPath['access_arguments'][0][] = 'administer CiviCRM';
         $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu');
     }
     $i18n =& CRM_Core_I18n::singleton();
     $i18n->localizeTitles($menuPath);
     return $menuPath;
 }
Example #15
0
 /**
  * Retrieve the settings values from db.
  *
  * @param $defaults
  *
  * @return array
  */
 public static function retrieve(&$defaults)
 {
     $domain = new CRM_Core_DAO_Domain();
     $isUpgrade = CRM_Core_Config::isUpgradeMode();
     //we are initializing config, really can't use, CRM-7863
     $urlVar = 'q';
     if (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') {
         $urlVar = 'task';
     }
     if ($isUpgrade && CRM_Core_DAO::checkFieldExists('civicrm_domain', 'config_backend')) {
         $domain->selectAdd('config_backend');
     } else {
         $domain->selectAdd('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]);
             }
         }
     }
     if (!$isUpgrade) {
         CRM_Core_BAO_ConfigSetting::applyLocale(Civi::settings($domain->id), $domain->locales);
     }
 }
 function create_recur(&$params)
 {
     foreach (array('contact_id', 'recur_frequency_interval', 'amount', 'recur_start_date', 'recur_next_payment_date', 'recur_frequency_unit', 'payment_processor_id', 'payment_instrument_id', 'trxn_id', 'cycle_day') as $required) {
         if (!isset($params[$required]) || empty($params[$required])) {
             throw new InvalidArgumentException("Missing params[{$required}]");
         }
     }
     $contribution_status_id = 5;
     // In Progress
     if (!($params['current_state'] == 10 || $params['current_state'] == 1)) {
         $contribution_status_id = 3;
     }
     // Create contribution recur record
     $recurParams = array('version' => 3, 'contact_id' => $params['contact_id'], 'frequency_interval' => $params['recur_frequency_interval'], 'amount' => $params['amount'], 'contribution_status_id' => $contribution_status_id, 'start_date' => $params['recur_start_date'], 'next_sched_contribution' => $params['recur_next_payment_date'], 'auto_renew' => '1', 'currency' => 'GBP', 'frequency_unit' => $params['recur_frequency_unit'], 'payment_processor_id' => $params['payment_processor_id'], 'payment_instrument_id' => $params['payment_instrument_id'], 'contribution_type_id' => '2', 'trxn_id' => $params['trxn_id'], 'create_date' => $params['recur_start_date'], 'cycle_day' => $params['cycle_day']);
     //print('About to call recurr create\n');
     //print_r($params);
     $recurResult = civicrm_api("ContributionRecur", "create", $recurParams);
     $params['contribution_recur_id'] = $recurResult['id'];
     // // Populate the membership id on create recur
     if ($params['contribution_recur_id'] && $params['membership_id']) {
         $columnExists = CRM_Core_DAO::checkFieldExists('civicrm_contribution_recur', 'membership_id');
         if ($columnExists) {
             $query = "\n                UPDATE civicrm_contribution_recur\n                SET membership_id = %1\n                WHERE id = %2 ";
             $query_params = array(1 => array($params['membership_id'], 'Int'), 2 => array($params['contribution_recur_id'], 'Int'));
             $dao = CRM_Core_DAO::executeQuery($query, $query_params);
         }
     }
     //print_r($recurResult);
 }
Example #17
0
 /**
  * Synchronize the object with the UF Match entry. Can be called stand-alone from
  * the drupalUsers script
  *
  * @param Object  $user    the drupal user object
  * @param string  $userKey the id of the user from the uf object
  * @param string  $uniqId    the OpenID of the user
  * @param string  $uf      the name of the user framework
  * @param integer $status  returns the status if user created or already exits (used for CMS sync)
  *
  * @return the ufmatch object that was found or created
  * @access public
  * @static
  */
 static function &synchronizeUFMatch(&$user, $userKey, $uniqId, $uf, $status = null, $ctype = null, $isLogin = false)
 {
     // validate that uniqId is a valid url. it will either be
     // an OpenID (which should always be a valid url) or a
     // http://uf_username/ construction (so that it can
     // be used as an OpenID in the future)
     require_once 'CRM/Utils/Rule.php';
     if ($uf == 'Standalone') {
         if (!CRM_Utils_Rule::url($uniqId)) {
             return $status ? null : false;
         }
     } else {
         if (!CRM_Utils_Rule::email($uniqId)) {
             return $status ? null : false;
         }
     }
     $newContact = false;
     // make sure that a contact id exists for this user id
     $ufmatch =& new CRM_Core_DAO_UFMatch();
     if (CRM_Core_DAO::checkFieldExists('civicrm_uf_match', 'domain_id')) {
         // FIXME: if() condition check was required especially for upgrade cases (2.2.x -> 3.0.x),
         // where folks if happen to logout, would encounter a column not found fatal error
         $ufmatch->domain_id = CRM_Core_Config::domainID();
     }
     $ufmatch->uf_id = $userKey;
     if (!$ufmatch->find(true)) {
         require_once 'CRM/Core/Transaction.php';
         $transaction = new CRM_Core_Transaction();
         if (!empty($_POST) && !$isLogin) {
             $params = $_POST;
             $params['email'] = $uniqId;
             require_once 'CRM/Dedupe/Finder.php';
             $dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
             $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
             if (!empty($ids) && defined('CIVICRM_UNIQ_EMAIL_PER_SITE') && CIVICRM_UNIQ_EMAIL_PER_SITE) {
                 // restrict dupeIds to ones that belong to current domain/site.
                 require_once 'CRM/Core/BAO/Domain.php';
                 $siteContacts = CRM_Core_BAO_Domain::getContactList();
                 foreach ($ids as $index => $dupeId) {
                     if (!in_array($dupeId, $siteContacts)) {
                         unset($ids[$index]);
                     }
                 }
                 $ids = array_values($ids);
                 //re-index the array
             }
             if (!empty($ids)) {
                 $dao = new CRM_Core_DAO();
                 $dao->contact_id = $ids[0];
             }
         } else {
             require_once 'CRM/Contact/BAO/Contact.php';
             if ($uf == 'Standalone') {
                 $dao =& CRM_Contact_BAO_Contact::matchContactOnOpenId($uniqId, $ctype);
             } else {
                 $dao =& CRM_Contact_BAO_Contact::matchContactOnEmail($uniqId, $ctype);
             }
         }
         if ($dao) {
             //print "Found contact with uniqId $uniqId<br/>";
             $ufmatch->contact_id = $dao->contact_id;
             $ufmatch->uf_name = $uniqId;
         } else {
             if ($uf == 'Drupal') {
                 $mail = 'mail';
             } else {
                 $mail = 'email';
             }
             if (is_Object($user)) {
                 $params = array('email-Primary' => $user->{$mail});
             }
             if ($ctype == 'Organization') {
                 $params['organization_name'] = $uniqId;
             } else {
                 if ($ctype == 'Household') {
                     $params['household_name'] = $uniqId;
                 }
             }
             if (!$ctype) {
                 $ctype = "Individual";
             }
             $params['contact_type'] = $ctype;
             // extract first / middle / last name
             // for joomla
             if ($uf == 'Joomla' && $user->name) {
                 require_once 'CRM/Utils/String.php';
                 CRM_Utils_String::extractName($user->name, $params);
             }
             if ($uf == 'Standalone') {
                 $params['openid-Primary'] = $uniqId;
                 //need to delete below code once profile is
                 //exposed on signup page
                 if (!empty($user->first_name) || !empty($user->last_name)) {
                     $params['first_name'] = $user->first_name;
                     $params['last_name'] = $user->last_name;
                 } elseif (!empty($user->name)) {
                     require_once 'CRM/Utils/String.php';
                     CRM_Utils_String::extractName($user->name, $params);
                 }
             }
             $contactId = CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray);
             $ufmatch->contact_id = $contactId;
             $ufmatch->uf_name = $uniqId;
         }
         // check that there are not two CMS IDs matching the same CiviCRM contact - this happens when a civicrm
         // user has two e-mails and there is a cms match for each of them
         // the gets rid of the nasty fata error but still reports the error
         $sql = "\nSELECT uf_id\nFROM   civicrm_uf_match\nWHERE  ( contact_id = %1\nOR     uf_name      = %2\nOR     uf_id        = %3 )\nAND    domain_id    = %4\n";
         $params = array(1 => array($ufmatch->contact_id, 'Integer'), 2 => array($ufmatch->uf_name, 'String'), 3 => array($ufmatch->uf_id, 'Integer'), 4 => array($ufmatch->domain_id, 'Integer'));
         require_once 'CRM/Core/DAO.php';
         $conflict = CRM_Core_DAO::singleValueQuery($sql, $params);
         if (!$conflict) {
             $ufmatch->save();
             $ufmatch->free();
             $newContact = true;
             $transaction->commit();
         } else {
             $msg = ts("Contact ID %1 is a match for %2 user %3 but has already been matched to %4", array(1 => $ufmatch->contact_id, 2 => $uf, 3 => $ufmatch->uf_id, 4 => $conflict));
             unset($conflict);
         }
     }
     if ($status) {
         return $newContact;
     } else {
         return $ufmatch;
     }
 }
Example #18
0
 /**
  * Synchronize the object with the UF Match entry. Can be called stand-alone from
  * the drupalUsers script
  *
  * @param Object  $user    the drupal user object
  * @param string  $userKey the id of the user from the uf object
  * @param string  $uniqId    the OpenID of the user
  * @param string  $uf      the name of the user framework
  * @param integer $status  returns the status if user created or already exits (used for CMS sync)
  *
  * @return the ufmatch object that was found or created
  * @access public
  * @static
  */
 static function &synchronizeUFMatch(&$user, $userKey, $uniqId, $uf, $status = null, $ctype = null)
 {
     // validate that uniqId is a valid url. it will either be
     // an OpenID (which should always be a valid url) or a
     // http://uf_username/ construction (so that it can
     // be used as an OpenID in the future)
     require_once 'CRM/Utils/Rule.php';
     if ($uf == 'Standalone') {
         if (!CRM_Utils_Rule::url($uniqId)) {
             return $status ? null : false;
         }
     } else {
         if (!CRM_Utils_Rule::email($uniqId)) {
             return $status ? null : false;
         }
     }
     $newContact = false;
     // make sure that a contact id exists for this user id
     $ufmatch =& new CRM_Core_DAO_UFMatch();
     if (CRM_Core_DAO::checkFieldExists('civicrm_uf_match', 'domain_id')) {
         // FIXME: if() condition check was required especially for upgrade cases (2.2.x -> 3.0.x),
         // where folks if happen to logout, would encounter a column not found fatal error
         $ufmatch->domain_id = CRM_Core_Config::domainID();
     }
     $ufmatch->uf_id = $userKey;
     if (!$ufmatch->find(true)) {
         require_once 'CRM/Core/Transaction.php';
         $transaction = new CRM_Core_Transaction();
         if (!empty($_POST)) {
             $params = $_POST;
             $params['email'] = $uniqId;
             require_once 'CRM/Dedupe/Finder.php';
             $dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
             $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
             if (!empty($ids)) {
                 $dao = new CRM_Core_DAO();
                 $dao->contact_id = $ids[0];
             }
         } else {
             require_once 'CRM/Contact/BAO/Contact.php';
             if ($uf == 'Standalone') {
                 $dao =& CRM_Contact_BAO_Contact::matchContactOnOpenId($uniqId, $ctype);
             } else {
                 $dao =& CRM_Contact_BAO_Contact::matchContactOnEmail($uniqId, $ctype);
             }
         }
         if ($dao) {
             //print "Found contact with uniqId $uniqId<br/>";
             $ufmatch->contact_id = $dao->contact_id;
             $ufmatch->uf_name = $uniqId;
         } else {
             if ($uf == 'Drupal') {
                 $mail = 'mail';
             } else {
                 $mail = 'email';
             }
             if (is_Object($user)) {
                 $params = array('email-Primary' => $user->{$mail});
             }
             if ($ctype == 'Organization') {
                 $params['organization_name'] = $uniqId;
             } else {
                 if ($ctype == 'Household') {
                     $params['household_name'] = $uniqId;
                 }
             }
             if (!$ctype) {
                 $ctype = "Individual";
             }
             $params['contact_type'] = $ctype;
             // extract first / middle / last name
             // for joomla
             if ($uf == 'Joomla' && $user->name) {
                 require_once 'CRM/Utils/String.php';
                 CRM_Utils_String::extractName($user->name, $params);
             }
             if ($uf == 'Standalone') {
                 $params['openid-Primary'] = $uniqId;
                 //need to delete below code once profile is
                 //exposed on signup page
                 if (!empty($user->first_name) || !empty($user->last_name)) {
                     $params['first_name'] = $user->first_name;
                     $params['last_name'] = $user->last_name;
                 } elseif (!empty($user->name)) {
                     require_once 'CRM/Utils/String.php';
                     CRM_Utils_String::extractName($user->name, $params);
                 }
             }
             $contactId = CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray);
             $ufmatch->contact_id = $contactId;
             $ufmatch->uf_name = $uniqId;
         }
         $ufmatch->save();
         $ufmatch->free();
         $newContact = true;
         $transaction->commit();
     }
     if ($status) {
         return $newContact;
     } else {
         return $ufmatch;
     }
 }
Example #19
0
 function upgrade_2_2_beta1($rev)
 {
     if (!CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'notify_email')) {
         $template =& CRM_Core_Smarty::singleton();
         $template->assign('notifyAbsent', true);
     }
     $upgrade =& new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
 }
Example #20
0
 /**
  * @param $rev
  */
 public function upgrade_4_1_1($rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->assign('addDedupeEmail', !CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'dedupe_email'));
     $sql = "SELECT id FROM civicrm_worldregion LIMIT 1";
     $upgrade->assign('worldRegionEmpty', !CRM_Core_DAO::singleValueQuery($sql));
     $upgrade->processSQL($rev);
 }
Example #21
0
 /**
  * Update the DB record for this setting.
  *
  * @param string $name
  *   The simple name of the setting.
  * @param mixed $value
  *   The new value of the setting.
  */
 protected function setDb($name, $value)
 {
     if (\CRM_Core_BAO_Setting::isUpgradeFromPreFourOneAlpha1()) {
         // civicrm_setting table is not going to be present.
         return;
     }
     $fields = array();
     $fieldsToSet = \CRM_Core_BAO_Setting::validateSettingsInput(array($name => $value), $fields);
     //We haven't traditionally validated inputs to setItem, so this breaks things.
     //foreach ($fieldsToSet as $settingField => &$settingValue) {
     //  self::validateSetting($settingValue, $fields['values'][$settingField]);
     //}
     $metadata = $fields['values'][$name];
     $dao = new \CRM_Core_DAO_Setting();
     $dao->name = $name;
     $dao->domain_id = $this->domainId;
     if ($this->contactId) {
         $dao->contact_id = $this->contactId;
         $dao->is_domain = 0;
     } else {
         $dao->is_domain = 1;
     }
     $dao->find(TRUE);
     if (isset($metadata['on_change'])) {
         foreach ($metadata['on_change'] as $callback) {
             call_user_func(\Civi\Core\Resolver::singleton()->get($callback), unserialize($dao->value), $value, $metadata, $this->domainId);
         }
     }
     if (!is_array($value) && \CRM_Utils_System::isNull($value)) {
         $dao->value = 'null';
     } else {
         $dao->value = serialize($value);
     }
     if (!isset(\Civi::$statics[__CLASS__]['upgradeMode'])) {
         \Civi::$statics[__CLASS__]['upgradeMode'] = \CRM_Core_Config::isUpgradeMode();
     }
     if (\Civi::$statics[__CLASS__]['upgradeMode'] && \CRM_Core_DAO::checkFieldExists('civicrm_setting', 'group_name')) {
         $dao->group_name = 'placeholder';
     }
     $dao->created_date = \CRM_Utils_Time::getTime('YmdHis');
     $session = \CRM_Core_Session::singleton();
     if (\CRM_Contact_BAO_Contact_Utils::isContactId($session->get('userID'))) {
         $dao->created_id = $session->get('userID');
     }
     if ($dao->id) {
         $dao->save();
     } else {
         // Cannot use $dao->save(); in upgrade mode (eg WP + Civi 4.4=>4.7), the DAO will refuse
         // to save the field `group_name`, which is required in older schema.
         \CRM_Core_DAO::executeQuery(\CRM_Utils_SQL_Insert::dao($dao)->toSQL());
     }
     $dao->free();
 }
Example #22
0
 /**
  * @param $rev
  */
 public function upgrade_3_4_alpha3($rev)
 {
     // CRM-7681, update report instance criteria.
     $modifiedReportIds = array('contact/summary', 'contact/detail', 'event/participantListing', 'member/summary', 'pledge/summary', 'pledge/pbnp', 'member/detail', 'member/lapse', 'grant/detail', 'contribute/bookkeeping', 'contribute/lybunt', 'contribute/summary', 'contribute/repeat', 'contribute/detail', 'contribute/organizationSummary', 'contribute/sybunt', 'contribute/householdSummary', 'contact/relationship', 'contact/currentEmployer', 'case/demographics', 'walklist', 'case/detail', 'contact/log', 'activitySummary', 'case/timespent', 'case/summary');
     $instances = CRM_Core_DAO::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')");
     while ($instances->fetch()) {
         $formValues = unserialize($instances->form_values);
         // replace display_name fields by sort_name
         if (!empty($formValues['fields']) && isset($formValues['fields']['display_name'])) {
             $formValues['fields']['sort_name'] = $formValues['fields']['display_name'];
             unset($formValues['fields']['display_name']);
         }
         // replace display_name filters by sort_name
         if (isset($formValues['display_name_op'])) {
             $formValues['sort_name_op'] = $formValues['display_name_op'];
             unset($formValues['display_name_op']);
         }
         if (isset($formValues['display_name_value'])) {
             $formValues['sort_name_value'] = $formValues['display_name_value'];
             unset($formValues['display_name_value']);
         }
         // for report id 'contact/log' replace field
         // display_name_touched by sort_name_touched
         if ($instances->report_id == 'contact/log' && isset($formValues['fields']['display_name_touched'])) {
             $formValues['fields']['sort_name_touched'] = $formValues['fields']['display_name_touched'];
             unset($formValues['fields']['display_name_touched']);
         }
         // for report id 'contact/relationship' replace field
         // display_name_a by sort_name_a and display_name_b by sort_name_b
         if ($instances->report_id == 'contact/relationship') {
             if (isset($formValues['fields']['display_name_a'])) {
                 $formValues['fields']['sort_name_a'] = $formValues['fields']['display_name_a'];
                 unset($formValues['fields']['display_name_a']);
             }
             if (isset($formValues['fields']['display_name_b'])) {
                 $formValues['fields']['sort_name_b'] = $formValues['fields']['display_name_b'];
                 unset($formValues['fields']['display_name_b']);
             }
         }
         // save updated instance criteria
         $dao = new CRM_Report_DAO_ReportInstance();
         $dao->id = $instances->id;
         $dao->form_values = serialize($formValues);
         $dao->save();
         $dao->free();
     }
     // Handled for typo in 3.3.2.mysql.tpl, rename column visibilty to
     // visibility in table civicrm_mailing
     $renameColumnVisibility = CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'visibilty');
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->assign('renameColumnVisibility', $renameColumnVisibility);
     $upgrade->processSQL($rev);
 }
 public function task_4_3_alpha1_checkDBConstraints()
 {
     //checking whether the foreign key exists before dropping it CRM-11260
     $config = CRM_Core_Config::singleton();
     $dbUf = DB::parseDSN($config->dsn);
     $tables = array('autorenewal_msg_id' => array('tableName' => 'civicrm_membership_type', 'fkey' => 'FK_civicrm_membership_autorenewal_msg_id'), 'to_account_id' => array('tableName' => 'civicrm_financial_trxn', 'constraintName' => 'civicrm_financial_trxn_ibfk_2'), 'from_account_id' => array('tableName' => 'civicrm_financial_trxn', 'constraintName' => 'civicrm_financial_trxn_ibfk_1'), 'contribution_type_id' => array('tableName' => 'civicrm_contribution_recur', 'fkey' => 'FK_civicrm_contribution_recur_contribution_type_id'));
     $query = "\nSELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS\nWHERE table_name = 'civicrm_contribution_recur'\nAND constraint_name = 'FK_civicrm_contribution_recur_contribution_type_id'\nAND TABLE_SCHEMA = %1\n";
     $params = array(1 => array($dbUf['database'], 'String'));
     $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, FALSE);
     foreach ($tables as $columnName => $value) {
         if ($value['tableName'] == 'civicrm_membership_type' || $value['tableName'] == 'civicrm_contribution_recur') {
             $foreignKeyExists = CRM_Core_DAO::checkConstraintExists($value['tableName'], $value['fkey']);
             $fKey = $value['fkey'];
         } else {
             $foreignKeyExists = CRM_Core_DAO::checkFKConstraintInFormat($value['tableName'], $columnName);
             $fKey = "`FK_{$value['tableName']}_{$columnName}`";
         }
         if ($foreignKeyExists || $value['tableName'] == 'civicrm_financial_trxn') {
             if ($value['tableName'] != 'civicrm_contribution_recur' || $value['tableName'] == 'civicrm_contribution_recur' && $dao->N) {
                 $constraintName = $foreignKeyExists ? $fKey : $value['constraintName'];
                 $query = "ALTER TABLE {$value['tableName']} DROP FOREIGN KEY {$constraintName}";
                 CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, FALSE);
             }
             $query = "ALTER TABLE {$value['tableName']} DROP INDEX {$fKey}";
             CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, FALSE);
         }
     }
     // check if column contact_id is present or not in civicrm_financial_account
     $fieldExists = CRM_Core_DAO::checkFieldExists('civicrm_financial_account', 'contact_id', FALSE);
     if (!$fieldExists) {
         $query = "\nALTER TABLE civicrm_financial_account\n  ADD contact_id int(10) unsigned DEFAULT NULL COMMENT 'Version identifier of financial_type' AFTER name,\n  ADD CONSTRAINT FK_civicrm_financial_account_contact_id FOREIGN KEY (contact_id) REFERENCES civicrm_contact(id);\n";
         CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, FALSE);
     }
 }
Example #24
0
 /**
  * Add a new locale to a multi-lang db, setting
  * its values to the current default locale.
  *
  * @param $locale string  the new locale to add
  * @param $source string  the locale to copy from
  *
  * @return void
  */
 static function addLocale($locale, $source)
 {
     // get the current supported locales
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
     // break early if the locale is already supported
     if (in_array($locale, $locales)) {
         return;
     }
     $dao = new CRM_Core_DAO();
     // build the required SQL queries
     $columns = CRM_Core_I18n_SchemaStructure::columns();
     $indices = CRM_Core_I18n_SchemaStructure::indices();
     $queries = array();
     foreach ($columns as $table => $hash) {
         // add new columns
         foreach ($hash as $column => $type) {
             // CRM-7854: skip existing columns
             if (CRM_Core_DAO::checkFieldExists($table, "{$column}_{$locale}", FALSE)) {
                 continue;
             }
             $queries[] = "ALTER TABLE {$table} ADD {$column}_{$locale} {$type}";
             $queries[] = "UPDATE {$table} SET {$column}_{$locale} = {$column}_{$source}";
         }
         // add view
         $queries[] = self::createViewQuery($locale, $table, $dao);
         // add new indices
         $queries = array_merge($queries, array_values(self::createIndexQueries($locale, $table)));
     }
     // execute the queries without i18n rewriting
     foreach ($queries as $query) {
         $dao->query($query, FALSE);
     }
     // update civicrm_domain.locales
     $locales[] = $locale;
     $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, $locales);
     $domain->save();
     // invoke the meta trigger creation call
     CRM_Core_DAO::triggerRebuild();
 }
Example #25
0
 /**
  * Function to create navigation for CiviCRM Admin Menu
  * 
  * @param int $contactID contact id
  *
  * @return string $navigation returns navigation html
  * @static
  */
 static function createNavigation($contactID)
 {
     if (!$contactID || !CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'navigation')) {
         return;
     }
     $config =& CRM_Core_Config::singleton();
     // For Joomla front end user, there is no need to create
     // navigation menu items, CRM-5349
     if ($config->userFramework == 'Joomla' && $config->userFrameworkFrontend) {
         return "<!-- {$config->lcMessages} -->";
     }
     $navParams = array('contact_id' => $contactID);
     if (CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'domain_id')) {
         // FIXME: if() condition check was required especially for upgrade
         // cases (2.2.x -> 3.0.x), CRM-5203
         $navParams['domain_id'] = CRM_Core_Config::domainID();
     }
     CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_Preferences', $navParams, $navParams);
     $navigation = array_key_exists('navigation', $navParams) ? $navParams['navigation'] : false;
     // FIXME: hack for CRM-5027: we need to prepend the navigation string with
     // (HTML-commented-out) locale info so that we rebuild menu on locale changes
     if (!$navigation or substr($navigation, 0, 14) != "<!-- {$config->lcMessages} -->") {
         //retrieve navigation if it's not cached.
         require_once 'CRM/Core/BAO/Navigation.php';
         $navigation = self::buildNavigation();
         //add additional navigation items
         $logoutURL = CRM_Utils_System::url('civicrm/logout', 'reset=1');
         $appendSring = "<li id=\"menu-logout\" class=\"menumain\"><a href=\"{$logoutURL}\">" . ts('Logout') . "</a></li>";
         $homeURL = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
         if ($config->userFramework == 'Drupal' && function_exists('module_exists') && module_exists('admin_menu')) {
             $prepandString = "<li class=\"menumain\">" . ts('Home') . "<ul id=\"civicrm-home\"><li><a href=\"{$homeURL}\">" . ts('CiviCRM Home') . "</a></li><li><a href=\"#\" onclick=\"cj.Menu.closeAll( );cj('#civicrm-menu').toggle( );\">" . ts('Drupal Menu') . "</a></li></ul></li>";
         } else {
             $prepandString = "<li class=\"menumain\"><a href=\"{$homeURL}\" title=\"" . ts('CiviCRM Home') . "\">" . ts('Home') . "</a></li>";
         }
         // prepend the navigation with locale info for CRM-5027
         $navigation = "<!-- {$config->lcMessages} -->" . $prepandString . $navigation . $appendSring;
         // before inserting check if contact id exists in db
         // this is to handle wierd case when contact id is in session but not in db
         require_once 'CRM/Contact/DAO/Contact.php';
         $contact =& new CRM_Contact_DAO_Contact();
         $contact->id = $contactID;
         if ($contact->find(true)) {
             // save in preference table for this particular user
             require_once 'CRM/Core/DAO/Preferences.php';
             $preference =& new CRM_Core_DAO_Preferences();
             $preference->contact_id = $contactID;
             $preference->domain_id = CRM_Core_Config::domainID();
             $preference->find(true);
             $preference->navigation = $navigation;
             $preference->save();
         }
     }
     return $navigation;
 }
Example #26
0
 static function _insertDeclaration($params, $endTimestamp)
 {
     static $charityColumnExists = null;
     $charityClause = '';
     if ($charityColumnExists === NULL) {
         $charityColumnExists = CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_declaration', 'charity');
     }
     if (!CRM_Utils_Array::value('charity', $params)) {
         $charityColumnExists = false;
     }
     if ($charityColumnExists) {
         $charityCol = ', charity';
         $charityVal = ', %8';
     }
     // Insert
     $sql = "\n        INSERT INTO civicrm_value_gift_aid_declaration (entity_id, eligible_for_gift_aid, start_date, end_date, reason_ended, source, notes {$charityCol})\n        VALUES (%1, %2, %3, %4, %5, %6, %7 {$charityVal})";
     $queryParams = array(1 => array($params['entity_id'], 'Integer'), 2 => array($params['eligible_for_gift_aid'], 'Integer'), 3 => array(CRM_Utils_Date::isoToMysql($params['start_date']), 'Timestamp'), 4 => array($endTimestamp ? date('YmdHis', $endTimestamp) : '', 'Timestamp'), 5 => array(CRM_Utils_Array::value('reason_ended', $params, ''), 'String'), 6 => array(CRM_Utils_Array::value('source', $params, ''), 'String'), 7 => array(CRM_Utils_Array::value('notes', $params, ''), 'String'));
     if ($charityColumnExists) {
         $queryParams[8] = array(CRM_Utils_Array::value('charity', $params, ''), 'String');
     }
     $dao = CRM_Core_DAO::executeQuery($sql, $queryParams);
 }
Example #27
0
 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);
 }
 /**
  * Given an array of contributionIDs, add them to a batch
  *
  * @param array $contributionIDs (reference ) the array of contribution ids to be added
  * @param int   $batchID         - the batchID to be added to
  *
  * @return array             (total, added, notAdded) ids of contributions added to the batch
  * @access public
  * @static
  */
 public static function addContributionToBatch($contributionIDs, $batchID)
 {
     $date = date('YmdHis');
     $contributionsAdded = array();
     $contributionsNotAdded = array();
     require_once "CRM/Civigiftaid/Utils/GiftAid.php";
     require_once "CRM/Contribute/BAO/Contribution.php";
     require_once 'CRM/Batch/DAO/EntityBatch.php';
     require_once "CRM/Core/BAO/Address.php";
     require_once "CRM/Contact/BAO/Contact.php";
     require_once "CRM/Utils/Address.php";
     // Get the batch name
     require_once 'CRM/Batch/DAO/Batch.php';
     $batch = new CRM_Batch_DAO_Batch();
     $batch->id = $batchID;
     $batch->find(TRUE);
     $batchName = $batch->title;
     $batchNameGroup = civicrm_api('OptionGroup', 'getsingle', array('version' => 3, 'sequential' => 1, 'name' => 'giftaid_batch_name'));
     if ($batchNameGroup['id']) {
         $groupId = $batchNameGroup['id'];
         $params = array('version' => 3, 'sequential' => 1, 'option_group_id' => $groupId, 'value' => $batchName, 'label' => $batchName);
         $result = civicrm_api('OptionValue', 'create', $params);
     }
     $charityColumnExists = CRM_Core_DAO::checkFieldExists('civicrm_value_gift_aid_submission', 'charity');
     foreach ($contributionIDs as $contributionID) {
         //$batchContribution =& new CRM_Core_DAO_EntityBatch( );
         $batchContribution =& new CRM_Batch_DAO_EntityBatch();
         $batchContribution->entity_table = 'civicrm_contribution';
         $batchContribution->entity_id = $contributionID;
         // check if the selected contribution id already in a batch
         // if not, add to batchContribution else keep the count of contributions that are not added
         if ($batchContribution->find(TRUE)) {
             $contributionsNotAdded[] = $contributionID;
             continue;
         }
         // get additional info
         // get contribution details from Contribution using contribution id
         $params = array('id' => $contributionID);
         CRM_Contribute_BAO_Contribution::retrieve($params, $contribution, $ids);
         $contactId = $contribution['contact_id'];
         // check if contribution is valid for gift aid
         if (CRM_Civigiftaid_Utils_GiftAid::isEligibleForGiftAid($contactId, $contribution['receive_date'], $contributionID) and $contribution['contribution_status_id'] == 1) {
             $batchContribution->batch_id = $batchID;
             $batchContribution->save();
             $giftAidableContribAmt = self::getGiftAidableContribAmt($contribution['total_amount'], $contributionID);
             // get gift aid amount
             $giftAidAmount = static::calculateGiftAidAmt($giftAidableContribAmt);
             // FIXME: check if there is customTable method
             $query = "\n                          INSERT INTO civicrm_value_gift_aid_submission\n                          (entity_id, eligible_for_gift_aid, gift_aid_amount , amount , batch_name)\n                          VALUES\n                            ( %1, 1, %2, %3 , %4 )\n                          ON DUPLICATE KEY UPDATE\n                          gift_aid_amount = %2 ,\n                          amount = %3 ,\n                          batch_name = %4\n                          ";
             $sqlParams = array(1 => array($contributionID, 'Integer'), 2 => array($giftAidAmount, 'Money'), 3 => array($contribution['total_amount'], 'Money'), 4 => array($batchName, 'String'));
             CRM_Core_DAO::executeQuery($query, $sqlParams);
             $contributionsAdded[] = $contributionID;
         } else {
             $contributionsNotAdded[] = $contributionID;
         }
     }
     if (!empty($contributionsAdded)) {
         // if there is any extra work required to be done for contributions that are batched,
         // should be done via hook
         CRM_Civigiftaid_Utils_Hook::batchContributions($batchID, $contributionsAdded);
     }
     return array(count($contributionIDs), count($contributionsAdded), count($contributionsNotAdded));
 }
Example #29
0
 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;
 }
Example #30
0
 static function get($path)
 {
     // return null if menu rebuild
     $config = CRM_Core_Config::singleton();
     $params = array();
     $args = explode('/', $path);
     $elements = array();
     while (!empty($args)) {
         $string = implode('/', $args);
         $string = CRM_Core_DAO::escapeString($string);
         $elements[] = "'{$string}'";
         array_pop($args);
     }
     $queryString = implode(', ', $elements);
     $domainID = CRM_Core_Config::domainID();
     $domainWhereClause = " AND domain_id = {$domainID} ";
     if ($config->isUpgradeMode() && !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'domain_id')) {
         //domain_id wouldn't be available for earlier version of
         //3.0 and therefore can't be used as part of query for
         //upgrade case
         $domainWhereClause = "";
     }
     $query = "\n(\n  SELECT *\n  FROM     civicrm_menu\n  WHERE    path in ( {$queryString} )\n           {$domainWhereClause}\n  ORDER BY length(path) DESC\n  LIMIT    1\n)\n";
     if ($path != 'navigation') {
         $query .= "\nUNION (\n  SELECT *\n  FROM   civicrm_menu\n  WHERE  path IN ( 'navigation' )\n         {$domainWhereClause}\n)\n";
     }
     $menu = new CRM_Core_DAO_Menu();
     $menu->query($query);
     self::$_menuCache = array();
     $menuPath = NULL;
     while ($menu->fetch()) {
         self::$_menuCache[$menu->path] = array();
         CRM_Core_DAO::storeValues($menu, self::$_menuCache[$menu->path]);
         foreach (self::$_serializedElements as $element) {
             self::$_menuCache[$menu->path][$element] = unserialize($menu->{$element});
             if (strpos($path, $menu->path) !== FALSE) {
                 $menuPath =& self::$_menuCache[$menu->path];
             }
         }
     }
     if (strstr($path, 'report/instance')) {
         $args = explode('/', $path);
         if (is_numeric(end($args))) {
             $menuPath['path'] .= '/' . end($args);
         }
     }
     // *FIXME* : hack for 2.1 -> 2.2 upgrades.
     if ($path == 'civicrm/upgrade') {
         $menuPath['page_callback'] = 'CRM_Upgrade_Page_Upgrade';
         $menuPath['access_arguments'][0][] = 'administer CiviCRM';
         $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu');
     }
     // *FIXME* : hack for 4.1 -> 4.2 upgrades.
     if (preg_match('/^civicrm\\/(upgrade\\/)?queue\\//', $path)) {
         CRM_Queue_Menu::alter($path, $menuPath);
     }
     // Part of upgrade framework but not run inside main upgrade because it deletes data
     // Once we have another example of a 'cleanup' we should generalize the clause below so it grabs string
     // which follows upgrade/ and checks for existence of a function in Cleanup class.
     if ($path == 'civicrm/upgrade/cleanup425') {
         $menuPath['page_callback'] = array('CRM_Upgrade_Page_Cleanup', 'cleanup425');
         $menuPath['access_arguments'][0][] = 'administer CiviCRM';
         $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu');
     }
     if (!empty($menuPath)) {
         $i18n = CRM_Core_I18n::singleton();
         $i18n->localizeTitles($menuPath);
     }
     return $menuPath;
 }