From e418776ce767f5d0ce5d613fe2840ded976fbd08 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 6 Jan 2015 13:21:24 -0800 Subject: [PATCH] INFRA-132 - CRM/Upgrade - phpcbf (plus fixup) --- CRM/Upgrade/Form.php | 15 +- CRM/Upgrade/Headless.php | 4 +- CRM/Upgrade/Incremental/php/FourFive.php | 6 +- CRM/Upgrade/Incremental/php/FourFour.php | 60 +- CRM/Upgrade/Incremental/php/FourOne.php | 2 - CRM/Upgrade/Incremental/php/FourSix.php | 4 +- CRM/Upgrade/Incremental/php/FourTwo.php | 45 +- CRM/Upgrade/Incremental/php/ThreeFour.php | 6 +- CRM/Upgrade/Incremental/php/ThreeThree.php | 19 +- CRM/Upgrade/Page/Cleanup.php | 5 +- CRM/Upgrade/Snapshot/V4p2/Price/BAO/Field.php | 37 +- .../Snapshot/V4p2/Price/BAO/FieldValue.php | 3 +- .../Snapshot/V4p2/Price/BAO/LineItem.php | 7 +- CRM/Upgrade/Snapshot/V4p2/Price/BAO/Set.php | 604 +++++++++--------- 14 files changed, 416 insertions(+), 401 deletions(-) diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 05f578c7d8..406fc40e98 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -102,7 +102,7 @@ class CRM_Upgrade_Form extends CRM_Core_Form { function __construct($state = NULL, $action = CRM_Core_Action::NONE, $method = 'post', - $name = NULL + $name = NULL ) { $this->_config = CRM_Core_Config::singleton(); @@ -364,7 +364,6 @@ SET version = '$version' /* '2.2.alpha3', '2.2.0', '2.2.2', '2.1.alpha1', '2.1.3'); */ - usort($revList, 'version_compare'); return $revList; } @@ -441,7 +440,7 @@ SET version = '$version' */ public function getUpgradeVersions() { $latestVer = CRM_Utils_System::version(); - $currentVer = CRM_Core_BAO_Domain::version(true); + $currentVer = CRM_Core_BAO_Domain::version(TRUE); if (!$currentVer) { CRM_Core_Error::fatal(ts('Version information missing in civicrm database.')); } @@ -511,7 +510,7 @@ SET version = '$version' array(1 => $latestVer)); } - if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024*self::MINIMUM_THREAD_STACK)) { + if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024 * self::MINIMUM_THREAD_STACK)) { $error = ts('CiviCRM %1 requires MySQL thread stack >= %2k', array( 1 => $latestVer, 2 => self::MINIMUM_THREAD_STACK @@ -646,7 +645,7 @@ SET version = '$version' * * @return bool */ - public static function doIncrementalUpgradeStep(CRM_Queue_TaskContext$ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile) { + public static function doIncrementalUpgradeStep(CRM_Queue_TaskContext $ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile) { $upgrade = new CRM_Upgrade_Form(); $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev); @@ -767,10 +766,10 @@ SET version = '$version' version_compare($rev, '3.2.alpha1') > 0 ) { $versionObject = $this->incrementalPhpObject($rev); - if (is_callable(array( + if (is_callable(array( $versionObject, 'setPreUpgradeMessage'))) { - $versionObject->setPreUpgradeMessage($preUpgradeMessage, $rev, $currentVer); - } + $versionObject->setPreUpgradeMessage($preUpgradeMessage, $rev, $currentVer); + } } } } diff --git a/CRM/Upgrade/Headless.php b/CRM/Upgrade/Headless.php index e5815d5705..a56de4a8be 100644 --- a/CRM/Upgrade/Headless.php +++ b/CRM/Upgrade/Headless.php @@ -70,8 +70,8 @@ class CRM_Upgrade_Headless { $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']); CRM_Core_Error::debug_log_message($errorMessage); if ($enablePrint) { - print($errorMessage); - } + print ($errorMessage); + } throw $queueResult['exception']; // FIXME test } diff --git a/CRM/Upgrade/Incremental/php/FourFive.php b/CRM/Upgrade/Incremental/php/FourFive.php index c184955ffa..3ef5a1ac8e 100644 --- a/CRM/Upgrade/Incremental/php/FourFive.php +++ b/CRM/Upgrade/Incremental/php/FourFive.php @@ -255,7 +255,7 @@ DROP KEY `{$dao->CONSTRAINT_NAME}`"; public static function migrateHonoreeInfo(CRM_Queue_TaskContext $ctx) { $query = "ALTER TABLE `civicrm_uf_join` ADD COLUMN `module_data` longtext COMMENT 'Json serialized array of data used by the ufjoin.module'"; - CRM_Core_DAO::executeQuery($query); + CRM_Core_DAO::executeQuery($query); $honorTypes = array_keys(CRM_Core_OptionGroup::values('honor_type')); $ufGroupDAO = new CRM_Core_DAO_UFGroup(); @@ -273,8 +273,8 @@ DROP KEY `{$dao->CONSTRAINT_NAME}`"; if ($domain->locales) { $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); foreach ($locales as $locale) { - $honor_block_title = "honor_block_title_{$locale}"; - $honor_block_text = "honor_block_text_{$locale}"; + $honor_block_title = "honor_block_title_{$locale}"; + $honor_block_text = "honor_block_text_{$locale}"; $honorParams['soft_credit'] += array( $locale => array( 'honor_block_title' => $dao->$honor_block_title, diff --git a/CRM/Upgrade/Incremental/php/FourFour.php b/CRM/Upgrade/Incremental/php/FourFour.php index 18e7a6800e..4bd43d2ef0 100644 --- a/CRM/Upgrade/Incremental/php/FourFour.php +++ b/CRM/Upgrade/Incremental/php/FourFour.php @@ -106,7 +106,7 @@ WHERE ceft.entity_table = 'civicrm_contribution' AND cft.payment_instrument_id I } } if ($rev == '4.4.6'){ - $postUpgradeMessage .= '

'. ts('Your contact image urls have been upgraded. If your contact image urls did not follow the standard format for image Urls they have not been upgraded. Please check the log to see image urls that were not upgraded.'); + $postUpgradeMessage .= '

'. ts('Your contact image urls have been upgraded. If your contact image urls did not follow the standard format for image Urls they have not been upgraded. Please check the log to see image urls that were not upgraded.'); } } @@ -234,12 +234,12 @@ WHERE ceft.entity_table = 'civicrm_contribution' AND cft.payment_instrument_id I $p[1] = array($acOptionGroupID, 'Integer'); if ($avinc) { - $p[2] = array($avinc+$maxVal, 'Integer'); - $p[3] = array($avinc+$maxWeight, 'Integer'); + $p[2] = array($avinc + $maxVal, 'Integer'); + $p[3] = array($avinc + $maxWeight, 'Integer'); } if ($nsinc) { - $p[4] = array($nsinc+$maxVal, 'Integer'); - $p[5] = array($nsinc+$maxWeight, 'Integer'); + $p[4] = array($nsinc + $maxVal, 'Integer'); + $p[5] = array($nsinc + $maxWeight, 'Integer'); } $insertStatus = implode(',', $insertStatus); @@ -275,13 +275,13 @@ VALUES {$insertStatus}"; {$fkConstraint} "; // CRM-14036 : delete entries of un-mapped contacts - CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac + CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac LEFT JOIN civicrm_contact c ON c.id = ac.contact_id WHERE c.id IS NULL; "); - // delete entries of un-mapped activities - CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac + // delete entries of un-mapped activities + CRM_Core_DAO::executeQuery("DELETE ac FROM civicrm_activity_contact ac LEFT JOIN civicrm_activity a ON a.id = ac.activity_id WHERE a.id IS NULL; @@ -329,7 +329,6 @@ ALTER TABLE civicrm_dashboard // CRM-13998 : missing alter statements for civicrm_report_instance $this->addTask(ts('Confirm civicrm_report_instance sql table for upgrades'), 'updateReportInstanceTable'); - return TRUE; } @@ -384,24 +383,24 @@ ALTER TABLE civicrm_dashboard $imageURL = $dao->image_url; $baseurl = CIVICRM_UF_BASEURL; $baselen = strlen($baseurl); - if (substr($imageURL, 0, $baselen)==$baseurl){ + if (substr($imageURL, 0, $baselen) == $baseurl){ $photo = basename($dao->image_url); $config = CRM_Core_Config::singleton(); $fullpath = $config->customFileUploadDir.$photo; - if (file_exists($fullpath)){ - // For anyone who upgraded 4.4.6 release (eg 4.4.0=>4.4.6), the $newImageUrl incorrectly used backend URLs. - // For anyone who skipped 4.4.6 (eg 4.4.0=>4.4.7), the $newImageUrl correctly uses frontend URLs - self::setContactImageUrl($dao->id, + if (file_exists($fullpath)){ + // For anyone who upgraded 4.4.6 release (eg 4.4.0=>4.4.6), the $newImageUrl incorrectly used backend URLs. + // For anyone who skipped 4.4.6 (eg 4.4.0=>4.4.7), the $newImageUrl correctly uses frontend URLs + self::setContactImageUrl($dao->id, CRM_Utils_System::url('civicrm/contact/imagefile', 'photo='.$photo, TRUE, NULL, TRUE, TRUE)); - } - else{ - $failures[$dao->id] = $dao->image_url; - } } else{ - $failures[$dao->id] = $dao->image_url; + $failures[$dao->id] = $dao->image_url; } } + else{ + $failures[$dao->id] = $dao->image_url; + } + } CRM_Core_Error::debug_var('imageUrlsNotUpgraded', $failures); return TRUE; } @@ -552,7 +551,7 @@ WHERE option_group_id = {$optionGroupID} AND value IN ($ovValues)"; } if (!$assigneeID || !$sourceID || !$targetID ) { - $insert = " + $insert = " INSERT INTO civicrm_option_value (option_group_id, label, value, name, weight, is_reserved, is_active) VALUES @@ -582,7 +581,6 @@ CREATE TABLE IF NOT EXISTS civicrm_activity_contact ( $dao = CRM_Core_DAO::executeQuery($query); - $query = " INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id) SELECT activity_id, target_contact_id, {$targetID} as record_type_id @@ -604,21 +602,21 @@ WHERE source_contact_id IS NOT NULL"; $dao = CRM_Core_DAO::executeQuery($query); - $query = "DROP TABLE civicrm_activity_target"; - $dao = CRM_Core_DAO::executeQuery($query); + $query = "DROP TABLE civicrm_activity_target"; + $dao = CRM_Core_DAO::executeQuery($query); - $query = "DROP TABLE civicrm_activity_assignment"; - $dao = CRM_Core_DAO::executeQuery($query); + $query = "DROP TABLE civicrm_activity_assignment"; + $dao = CRM_Core_DAO::executeQuery($query); - $query = "ALTER TABLE civicrm_activity + $query = "ALTER TABLE civicrm_activity DROP FOREIGN KEY FK_civicrm_activity_source_contact_id"; - $dao = CRM_Core_DAO::executeQuery($query); + $dao = CRM_Core_DAO::executeQuery($query); - $query = "ALTER TABLE civicrm_activity DROP COLUMN source_contact_id"; - $dao = CRM_Core_DAO::executeQuery($query); + $query = "ALTER TABLE civicrm_activity DROP COLUMN source_contact_id"; + $dao = CRM_Core_DAO::executeQuery($query); - return TRUE; + return TRUE; } /** @@ -745,7 +743,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` ( foreach ($localeCustomArray as $localCustomData) { // Traverse status array "enabled" "disabled" foreach ($localCustomData as $status => $matchTypes) { - $params["is_active"] = ($status == "enabled")?TRUE:FALSE; + $params["is_active"] = ($status == "enabled") ? TRUE : FALSE; // Traverse Match Type array "wildcardMatch" "exactMatch" foreach ($matchTypes as $matchType => $words) { $params["match_type"] = $matchType; diff --git a/CRM/Upgrade/Incremental/php/FourOne.php b/CRM/Upgrade/Incremental/php/FourOne.php index d6fb34a6b2..f11c4d2652 100644 --- a/CRM/Upgrade/Incremental/php/FourOne.php +++ b/CRM/Upgrade/Incremental/php/FourOne.php @@ -105,7 +105,6 @@ class CRM_Upgrade_Incremental_php_FourOne { $upgrade = new CRM_Upgrade_Form(); $upgrade->processSQL($rev); - $this->transferPreferencesToSettings(); $this->createNewSettings(); @@ -144,7 +143,6 @@ class CRM_Upgrade_Incremental_php_FourOne { ), ); - $userColumnNames = array( self::NAVIGATION_NAME => array( 'navigation', diff --git a/CRM/Upgrade/Incremental/php/FourSix.php b/CRM/Upgrade/Incremental/php/FourSix.php index 1b28b7e31c..084aadd7df 100644 --- a/CRM/Upgrade/Incremental/php/FourSix.php +++ b/CRM/Upgrade/Incremental/php/FourSix.php @@ -69,9 +69,9 @@ class CRM_Upgrade_Incremental_php_FourSix { * @return void */ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { - if ($rev == '4.6.alpha1') { + if ($rev == '4.6.alpha1') { $postUpgradeMessage .= '

' . ts('Default versions of the following System Workflow Message Templates have been modified to handle new functionality:
  • Events - Registration Confirmation and Receipt (on-line)
  • Events - Registration Confirmation and Receipt (off-line)
  • Contributions - Receipt (on-line)
  • Contributions - Receipt (off-line)
  • Memberships - Receipt (on-line)
  • Memberships - Signup and Renewal Receipts (off-line)
If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).'); - } + } } diff --git a/CRM/Upgrade/Incremental/php/FourTwo.php b/CRM/Upgrade/Incremental/php/FourTwo.php index d4725328ff..c03f54d178 100644 --- a/CRM/Upgrade/Incremental/php/FourTwo.php +++ b/CRM/Upgrade/Incremental/php/FourTwo.php @@ -61,7 +61,7 @@ class CRM_Upgrade_Incremental_php_FourTwo { */ public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { if ($rev == '4.2.alpha1') { - $tables = array('civicrm_contribution_page','civicrm_event','civicrm_group','civicrm_contact'); + $tables = array('civicrm_contribution_page', 'civicrm_event', 'civicrm_group', 'civicrm_contact'); if (!CRM_Core_DAO::schemaRequiresRebuilding($tables)){ $errors = ts("The upgrade has identified some schema integrity issues in the database. It seems some of your constraints are missing. You will have to rebuild your schema before re-trying the upgrade. Please refer to %1.", array(1 => CRM_Utils_System::docURL2("Ensuring Schema Integrity on Upgrades", FALSE, "Ensuring Schema Integrity on Upgrades", NULL, NULL, "wiki"))); CRM_Core_Error::fatal($errors); @@ -97,12 +97,12 @@ ORDER BY mp.contribution_id, mp.membership_id"; $invalidDataMessage .= "{$invalidData->end_date}"; $invalidDataMessage .= "" . CRM_Utils_Array::value($invalidData->status_id, $membershipStatus) . ""; $invalidDataMessage .= ""; - } + } $invalidDataMessage .= "

" . ts('If you have reviewed the cleanup script documentation on the wiki and you are ready to run the cleanup now - click here.', array(1 => CRM_Utils_System::url('civicrm/upgrade/cleanup425', 'reset=1'))) . "

"; CRM_Core_Error::fatal($invalidDataMessage); return FALSE; - } } + } if ($rev == '4.2.beta2') { // note: error conditions are also checked in upgrade_4_2_beta2() @@ -140,7 +140,7 @@ INNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id AND cps.name <>'de $errors = ts("We found unexpected data values from an older version of CiviCRM in your database. The upgrade can not be run until this condition is corrected.

Details: One or more rows are present in the civicrm_option_group with name like 'civicrm_price_field.amount.%'. Check here for information on diagnosing and correcting this problem.", array(1 => 'http://forum.civicrm.org/index.php/topic,27744.msg118748.html#msg118748')); CRM_Core_Error::fatal($errors); return FALSE; - } + } } } @@ -160,11 +160,11 @@ INNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id AND cps.name <>'de $postUpgradeMessage .= '
' . ts('Please configure the Extension Resource URL.', array( 1 => CRM_Utils_System::url('civicrm/admin/setting/url', 'reset=1') )); - } + } } if ($rev == '4.2.7') { $postUpgradeMessage .= '
' . ts('If you have configured a report instance to allow anonymous access, you will need to reset the permission to Everyone for that instance (under the Report Settings pane).'); - } + } } /** @@ -174,12 +174,13 @@ INNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id AND cps.name <>'de //checking whether the foreign key exists before dropping it //drop foreign key queries of CRM-9850 $params = array(); - $tables = array('civicrm_contribution_page' =>'FK_civicrm_contribution_page_payment_processor_id', + $tables = array( + 'civicrm_contribution_page' => 'FK_civicrm_contribution_page_payment_processor_id', 'civicrm_event' => 'FK_civicrm_event_payment_processor_id', 'civicrm_group' => 'FK_civicrm_group_saved_search_id', ); foreach($tables as $tableName => $fKey){ - $foreignKeyExists = CRM_Core_DAO::checkConstraintExists($tableName,$fKey); + $foreignKeyExists = CRM_Core_DAO::checkConstraintExists($tableName, $fKey); if ($foreignKeyExists){ CRM_Core_DAO::executeQuery("ALTER TABLE {$tableName} DROP FOREIGN KEY {$fKey}", $params, TRUE, NULL, FALSE, FALSE); CRM_Core_DAO::executeQuery("ALTER TABLE {$tableName} DROP INDEX {$fKey}", $params, TRUE, NULL, FALSE, FALSE); @@ -411,7 +412,7 @@ WHERE name LIKE '%.amount.%' "; while ($dao->fetch()) { $addTo = explode('.', $dao->name); if (!empty($addTo[2])) { - $options = array ('optionGroup' => $dao->name); + $options = array('optionGroup' => $dao->name); self::createPriceSet($daoName, $addTo, $options); } CRM_Core_OptionGroup::deleteAssoc($dao->name); @@ -428,7 +429,8 @@ WHERE cpse.price_set_id IS NULL"; $addTo = array('civicrm_contribution_page'); while ($dao->fetch()) { $addTo[2] = $dao->contribution_page_id; - $options = array ('otherAmount' =>$dao->is_allow_other_amount, + $options = array( + 'otherAmount' => $dao->is_allow_other_amount, 'membership' => $dao->membership_block_id ); self::createPriceSet($daoName, $addTo, $options); } @@ -440,21 +442,21 @@ WHERE cpse.price_set_id IS NULL"; * (Queue Task Callback) */ public static function task_4_2_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { - $upgrade = new CRM_Upgrade_Form(); - $upgrade->processSQL($rev); + $upgrade = new CRM_Upgrade_Form(); + $upgrade->processSQL($rev); - // now rebuild all the triggers - // CRM-9716 - // FIXME // CRM_Core_DAO::triggerRebuild(); + // now rebuild all the triggers + // CRM-9716 + // FIXME // CRM_Core_DAO::triggerRebuild(); - return TRUE; + return TRUE; } /** * * create price sets */ - public static function createPriceSet($daoName, $addTo, $options = array()) { + public static function createPriceSet($daoName, $addTo, $options = array()) { $query = "SELECT title FROM {$addTo[0]} where id =%1"; $setParams['title'] = CRM_Core_DAO::singleValueQuery($query, array(1 => array($addTo[2], 'Integer')) @@ -471,8 +473,9 @@ WHERE cpse.price_set_id IS NULL"; $optionValue = array(); if (!empty($options['optionGroup'])) { CRM_Core_OptionGroup::getAssoc($options['optionGroup'], $optionValue); - if (empty($optionValue)) + if (empty($optionValue)) { return; + } } elseif (empty($options['otherAmount']) && empty($options['membership'])) { //CRM-12273 @@ -480,11 +483,11 @@ WHERE cpse.price_set_id IS NULL"; return; } - if (! CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_BAO_Set', $pageTitle, 'id', 'name', true)) { + if (! CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_BAO_Set', $pageTitle, 'id', 'name', TRUE)) { $setParams['name'] = $pageTitle; } else { - $timeSec = explode(".", microtime(true)); + $timeSec = explode(".", microtime(TRUE)); $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['extends'] = $daoName[$addTo[0]][1]; @@ -950,7 +953,7 @@ VALUES $contribStatus = CRM_Utils_Array::value($dao->contribution_status_id, $contributionStatus); $processedRecords[] = array($dao->contact_id, $dao->contribution_id, $contribStatus, $dao->membership_id, $memType, $dao->start_date, $dao->end_date, $memStatus, $status); -} + } } if ( !empty($processedRecords) ) { diff --git a/CRM/Upgrade/Incremental/php/ThreeFour.php b/CRM/Upgrade/Incremental/php/ThreeFour.php index 29db710fbf..9afb3c7f3c 100644 --- a/CRM/Upgrade/Incremental/php/ThreeFour.php +++ b/CRM/Upgrade/Incremental/php/ThreeFour.php @@ -313,7 +313,8 @@ FROM civicrm_option_value v, WHERE v.option_group_id = g.id AND g.name = %1 AND g.is_active = 1 - AND v.name = %2", array(1 => array('activity_type', 'String'), + AND v.name = %2", array( + 1 => array('activity_type', 'String'), 2 => array('Bulk Email', 'String'), )); @@ -352,7 +353,8 @@ INSERT INTO civicrm_uf_join VALUES (1, 'OnBehalf', 'civicrm_contribution_page', %1, 1, %2)"; - $params = array(1 => array($pages->id, 'Integer'), + $params = array( + 1 => array($pages->id, 'Integer'), 2 => array($onBehalfProfileId, 'Integer'), ); CRM_Core_DAO::executeQuery($query, $params); diff --git a/CRM/Upgrade/Incremental/php/ThreeThree.php b/CRM/Upgrade/Incremental/php/ThreeThree.php index f7a56beb17..654bda1c13 100644 --- a/CRM/Upgrade/Incremental/php/ThreeThree.php +++ b/CRM/Upgrade/Incremental/php/ThreeThree.php @@ -67,7 +67,8 @@ class CRM_Upgrade_Incremental_php_ThreeThree { while ($customField->fetch()) { $name = CRM_Utils_String::munge($customField->label, '_', 64); $fldCnt = CRM_Core_DAO::singleValueQuery($customFldCntQuery, - array(1 => array($name, 'String'), + array( + 1 => array($name, 'String'), 2 => array($customField->id, 'Integer'), ), TRUE, FALSE ); @@ -79,7 +80,8 @@ Update `civicrm_custom_field` SET `name` = %1 WHERE id = %2 "; - $customFieldParams = array(1 => array($name, 'String'), + $customFieldParams = array( + 1 => array($name, 'String'), 2 => array($customField->id, 'Integer'), ); CRM_Core_DAO::executeQuery($customFieldQuery, $customFieldParams, TRUE, NULL, FALSE, FALSE); @@ -94,7 +96,8 @@ WHERE id = %2 while ($customGroup->fetch()) { $name = CRM_Utils_String::munge($customGroup->title, '_', 64); $grpCnt = CRM_Core_DAO::singleValueQuery($customGrpCntQuery, - array(1 => array($name, 'String'), + array( + 1 => array($name, 'String'), 2 => array($customGroup->id, 'Integer'), ) ); @@ -113,7 +116,8 @@ WHERE id = %2 while ($ufGroup->fetch()) { $name = CRM_Utils_String::munge($ufGroup->title, '_', 64); $ufGrpCnt = CRM_Core_DAO::singleValueQuery($ufGrpCntQuery, - array(1 => array($name, 'String'), + array( + 1 => array($name, 'String'), 2 => array($ufGroup->id, 'Integer'), ) ); @@ -148,7 +152,6 @@ WHERE id = %2 $updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;"; CRM_Core_DAO::executeQuery($updateLineItem1); - $priceFieldDAO = new CRM_Price_DAO_PriceField(); $priceFieldDAO->find(); $ids = array(); @@ -217,7 +220,8 @@ WHERE id = %2 // update civicrm_line_item for price_field_value_id. // Used query to avoid line by line update. if ($labelFound || $priceFound) { - $lineItemParams = array(1 => array($fieldValueDAO->id, 'Integer'), + $lineItemParams = array( + 1 => array($fieldValueDAO->id, 'Integer'), 2 => array($opValueDAO->label, 'String'), ); $updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2"; @@ -262,7 +266,8 @@ WHERE id = %2 $mainLineItem->find(TRUE); while ($mainLineItem->fetch()) { $dupeLineItem = new CRM_Price_BAO_LineItem(); - foreach ($fields as $fld) $dupeLineItem->$fld = $mainLineItem->$fld; + foreach ($fields as $fld) { $dupeLineItem->$fld = $mainLineItem->$fld; + } $dupeLineItem->find(TRUE); $dupeLineItem->addWhere("id != $mainLineItem->id"); while ($dupeLineItem->fetch()) { diff --git a/CRM/Upgrade/Page/Cleanup.php b/CRM/Upgrade/Page/Cleanup.php index 094c8cf369..8325c3f633 100644 --- a/CRM/Upgrade/Page/Cleanup.php +++ b/CRM/Upgrade/Page/Cleanup.php @@ -41,8 +41,9 @@ class CRM_Upgrade_Page_Cleanup extends CRM_Core_Page { $preMessage = !empty($rows) ? ts('The following records have been processed. Membership records with action = Un-linked have been disconnected from the listed contribution record:') : ts('Could not find any records to process.'); $template->assign('preMessage', $preMessage); - $postMessage = ts('You can click here to try running the 4.2 upgrade script again. (Review upgrade documentation)', - array(1 => CRM_Utils_System::url('civicrm/upgrade', 'reset=1'), + $postMessage = ts('You can click here to try running the 4.2 upgrade script again. (Review upgrade documentation)', + array( + 1 => CRM_Utils_System::url('civicrm/upgrade', 'reset=1'), 2 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Installation+and+Upgrades')); $template->assign('postMessage', $postMessage); diff --git a/CRM/Upgrade/Snapshot/V4p2/Price/BAO/Field.php b/CRM/Upgrade/Snapshot/V4p2/Price/BAO/Field.php index 21108dc984..bb1e2f8fde 100644 --- a/CRM/Upgrade/Snapshot/V4p2/Price/BAO/Field.php +++ b/CRM/Upgrade/Snapshot/V4p2/Price/BAO/Field.php @@ -143,7 +143,8 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field extends CRM_Upgrade_Snapshot_V4p if ($opId = CRM_Utils_Array::value($index, $opIds)) { $optionsIds['id'] = $opId; } - else $optionsIds['id'] = NULL; + else { $optionsIds['id'] = NULL; + } } CRM_Upgrade_Snapshot_V4p2_Price_BAO_FieldValue::create($options, $optionsIds); } @@ -222,8 +223,8 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field extends CRM_Upgrade_Snapshot_V4p $elementName, $fieldId, $inactiveNeeded, - $useRequired = TRUE, - $label = NULL, + $useRequired = TRUE, + $label = NULL, $fieldOptions = NULL, $freezeOptions = array() ) { @@ -243,11 +244,11 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field extends CRM_Upgrade_Snapshot_V4p $currencyName = $config->defaultCurrency; if (!isset($label)) { - $label = (property_exists($qf,'_membershipBlock') && !empty($qf->_membershipBlock['is_separate_payment']) && $field->name == 'contribution_amount' && empty($otherAmount['is_allow_other_amount'])) ? ts('Additional Contribution') : $field->label; + $label = (property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock['is_separate_payment']) && $field->name == 'contribution_amount' && empty($otherAmount['is_allow_other_amount'])) ? ts('Additional Contribution') : $field->label; } if ($field->name == 'contribution_amount') { - $qf->_contributionAmount = 1; + $qf->_contributionAmount = 1; } if (isset($qf->_online) && $qf->_online) { @@ -270,17 +271,17 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field extends CRM_Upgrade_Snapshot_V4p $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value)); $extra = array(); - if (property_exists($qf,'_quickConfig') && $qf->_quickConfig && property_exists($qf,'_contributionAmount') && $qf->_contributionAmount) { + if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && property_exists($qf, '_contributionAmount') && $qf->_contributionAmount) { $qf->assign('priceset', $elementName); $extra = array('onclick' => 'useAmountOther();'); } // if seperate membership payment is used with quick config priceset then change the other amount label - if (property_exists($qf,'_membershipBlock') && !empty($qf->_membershipBlock['is_separate_payment']) && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf,'_contributionAmount')) { - $label = ts('Additional Contribution'); - $useRequired = 0; + if (property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock['is_separate_payment']) && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf, '_contributionAmount')) { + $label = ts('Additional Contribution'); + $useRequired = 0; } elseif (!empty($fieldOptions[$optionKey]['label'])) { //check for label. - $label = $fieldOptions[$optionKey]['label']; + $label = $fieldOptions[$optionKey]['label']; } if ($field->is_display_amounts) { @@ -290,7 +291,8 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field extends CRM_Upgrade_Snapshot_V4p $element = &$qf->add('text', $elementName, $label, array_merge($extra, - array('price' => json_encode(array($optionKey, $priceVal)), + array( + 'price' => json_encode(array($optionKey, $priceVal)), 'size' => '4', ) ), @@ -317,7 +319,7 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field extends CRM_Upgrade_Snapshot_V4p case 'Radio': $choice = array(); - if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && property_exists($qf,'_contributionAmount') && $qf->_contributionAmount) { + if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && property_exists($qf, '_contributionAmount') && $qf->_contributionAmount) { $qf->assign('contriPriceset', $elementName); } @@ -329,17 +331,19 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field extends CRM_Upgrade_Snapshot_V4p $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value)); - $extra = array('price' => json_encode(array($elementName, $priceVal)), + $extra = array( + 'price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName, ); if (property_exists($qf, '_quickConfig') && $qf->_quickConfig && $field->name == 'contribution_amount') { $extra += array('onclick' => 'clearAmountOther();'); } elseif (property_exists($qf, '_quickConfig') && $qf->_quickConfig && $field->name == 'membership_amount') { - $extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", + $extra += array( + 'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id'], ); - $qf->assign('membershipFieldID',$field->id); + $qf->assign('membershipFieldID', $field->id); } $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra); @@ -429,7 +433,8 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field extends CRM_Upgrade_Snapshot_V4p $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]); } $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'], - array('price' => json_encode(array($opt['id'], $priceVal)), + array( + 'price' => json_encode(array($opt['id'], $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName, ) diff --git a/CRM/Upgrade/Snapshot/V4p2/Price/BAO/FieldValue.php b/CRM/Upgrade/Snapshot/V4p2/Price/BAO/FieldValue.php index 2346c90a16..9eee0fe704 100644 --- a/CRM/Upgrade/Snapshot/V4p2/Price/BAO/FieldValue.php +++ b/CRM/Upgrade/Snapshot/V4p2/Price/BAO/FieldValue.php @@ -86,7 +86,8 @@ class CRM_Upgrade_Snapshot_V4p2_Price_BAO_FieldValue extends CRM_Upgrade_Snapsho } if ($id = CRM_Utils_Array::value('id', $ids)) { - if (isset($params['name']))unset($params['name']); + if (isset($params['name'])) { unset($params['name']); + } $oldWeight = NULL; if ($id) { diff --git a/CRM/Upgrade/Snapshot/V4p2/Price/BAO/LineItem.php b/CRM/Upgrade/Snapshot/V4p2/Price/BAO/LineItem.php index 1f485c7be9..5c6b580849 100644 --- a/CRM/Upgrade/Snapshot/V4p2/Price/BAO/LineItem.php +++ b/CRM/Upgrade/Snapshot/V4p2/Price/BAO/LineItem.php @@ -182,7 +182,7 @@ WHERE %2.id = %1"; * to the price set used for particular event * @param array $values * Reference to the values array(. - this is + this is * lineItem array) * * @return void @@ -266,8 +266,9 @@ WHERE %2.id = %1"; * @param array $otherParams */ public static function syncLineItems($entityId, $entityTable = 'civicrm_contribution', $amount, $otherParams = NULL) { - if (!$entityId || CRM_Utils_System::isNull($amount)) + if (!$entityId || CRM_Utils_System::isNull($amount)) { return; + } $from = " civicrm_line_item li LEFT JOIN civicrm_price_field pf ON pf.id = li.price_field_id @@ -296,7 +297,7 @@ LEFT JOIN civicrm_price_field_value cpfv ON cpfv.price_field_id = pf.id and cpfv $set .= " ,li.label = %4, li.price_field_value_id = cpfv.id "; $where .= " AND cpse.entity_table = 'civicrm_event' AND cpse.entity_id = %5 "; - $amount = empty($amount) ? 0: $amount; + $amount = empty($amount) ? 0 : $amount; $params += array( 4 => array($otherParams['fee_label'], 'String'), 5 => array($otherParams['event_id'], 'String'), diff --git a/CRM/Upgrade/Snapshot/V4p2/Price/BAO/Set.php b/CRM/Upgrade/Snapshot/V4p2/Price/BAO/Set.php index d124af498a..c9b9f16c0a 100644 --- a/CRM/Upgrade/Snapshot/V4p2/Price/BAO/Set.php +++ b/CRM/Upgrade/Snapshot/V4p2/Price/BAO/Set.php @@ -124,13 +124,12 @@ WHERE ps.name = '{$entityName}' $dao = CRM_Core_DAO::executeQuery($sql); $defaultPriceSet = array(); while ($dao->fetch()) { - $defaultPriceSet[$dao->priceFieldValueID]['setID'] = $dao->setID; - $defaultPriceSet[$dao->priceFieldValueID]['priceFieldID'] = $dao->priceFieldID; - $defaultPriceSet[$dao->priceFieldValueID]['name'] = $dao->name; - $defaultPriceSet[$dao->priceFieldValueID]['label'] = $dao->label; + $defaultPriceSet[$dao->priceFieldValueID]['setID'] = $dao->setID; + $defaultPriceSet[$dao->priceFieldValueID]['priceFieldID'] = $dao->priceFieldID; + $defaultPriceSet[$dao->priceFieldValueID]['name'] = $dao->name; + $defaultPriceSet[$dao->priceFieldValueID]['label'] = $dao->label; } - return $defaultPriceSet; } @@ -176,7 +175,7 @@ WHERE price_set_id = %1"; return $tables; } if (empty($forms)) { - $queryString = " + $queryString = " SELECT cli.entity_table, cli.entity_id FROM civicrm_line_item cli LEFT JOIN civicrm_price_field cpf ON cli.price_field_id = cpf.id @@ -360,7 +359,8 @@ WHERE ct.id = cp.contribution_type_id AND if ($isQuickConfig) { $sql .= " AND ps.is_quick_config = 0 "; } - $params = array(1 => array($entityTable, 'String'), + $params = array( + 1 => array($entityTable, 'String'), 2 => array($entityId, 'Integer'), ); if ($usedFor) { @@ -681,22 +681,22 @@ WHERE id = %1"; if ($params["price_{$id}"] <= 0) { continue; } - $params["price_{$id}"] = array($params["price_{$id}"] => 1); - $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]); - $optionLabel = CRM_Utils_Array::value('label', $field['options'][$optionValueId]); - $params['amount_priceset_level_radio'] = array(); - $params['amount_priceset_level_radio'][$optionValueId] = $optionLabel; - if (isset($radioLevel)) { - $radioLevel = array_merge($radioLevel, + $params["price_{$id}"] = array($params["price_{$id}"] => 1); + $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]); + $optionLabel = CRM_Utils_Array::value('label', $field['options'][$optionValueId]); + $params['amount_priceset_level_radio'] = array(); + $params['amount_priceset_level_radio'][$optionValueId] = $optionLabel; + if (isset($radioLevel)) { + $radioLevel = array_merge($radioLevel, array_keys($params['amount_priceset_level_radio']) - ); - } - else { - $radioLevel = array_keys($params['amount_priceset_level_radio']); - } - CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem); - $totalPrice += $lineItem[$optionValueId]['line_total']; - break; + ); + } + else { + $radioLevel = array_keys($params['amount_priceset_level_radio']); + } + CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem); + $totalPrice += $lineItem[$optionValueId]['line_total']; + break; case 'Select': $params["price_{$id}"] = array($params["price_{$id}"] => 1); @@ -705,36 +705,37 @@ WHERE id = %1"; $params['amount_priceset_level_select'] = array(); $params['amount_priceset_level_select'][CRM_Utils_Array::key(1, $params["price_{$id}"])] = $optionLabel; if (isset($selectLevel)) { - $selectLevel = array_merge($selectLevel, array_keys($params['amount_priceset_level_select'])); - } - else { - $selectLevel = array_keys($params['amount_priceset_level_select']); - } - CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem); - $totalPrice += $lineItem[$optionValueId]['line_total']; - break; - case 'CheckBox': - $params['amount_priceset_level_checkbox'] = $optionIds = array(); - foreach ($params["price_{$id}"] as $optionId => $option) { - $optionIds[] = $optionId; - $optionLabel = $field['options'][$optionId]['label']; - $params['amount_priceset_level_checkbox']["{$field['options'][$optionId]['id']}"] = $optionLabel; - if (isset($checkboxLevel)) { - $checkboxLevel = array_unique(array_merge( - $checkboxLevel, - array_keys($params['amount_priceset_level_checkbox']) - ) - ); - } - else { - $checkboxLevel = array_keys($params['amount_priceset_level_checkbox']); - } - } - CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem); - foreach ($optionIds as $optionId) { - $totalPrice += $lineItem[$optionId]['line_total']; - } - break; + $selectLevel = array_merge($selectLevel, array_keys($params['amount_priceset_level_select'])); + } + else { + $selectLevel = array_keys($params['amount_priceset_level_select']); + } + CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem); + $totalPrice += $lineItem[$optionValueId]['line_total']; + break; + + case 'CheckBox': + $params['amount_priceset_level_checkbox'] = $optionIds = array(); + foreach ($params["price_{$id}"] as $optionId => $option) { + $optionIds[] = $optionId; + $optionLabel = $field['options'][$optionId]['label']; + $params['amount_priceset_level_checkbox']["{$field['options'][$optionId]['id']}"] = $optionLabel; + if (isset($checkboxLevel)) { + $checkboxLevel = array_unique(array_merge( + $checkboxLevel, + array_keys($params['amount_priceset_level_checkbox']) + ) + ); + } + else { + $checkboxLevel = array_keys($params['amount_priceset_level_checkbox']); + } + } + CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem); + foreach ($optionIds as $optionId) { + $totalPrice += $lineItem[$optionId]['line_total']; + } + break; } } @@ -767,106 +768,106 @@ WHERE id = %1"; * * @return void */ -static function buildPriceSet(&$form) { -$priceSetId = $form->get('priceSetId'); -$userid = $form->getVar('_userID'); -if (!$priceSetId) { - return; -} + static function buildPriceSet(&$form) { + $priceSetId = $form->get('priceSetId'); + $userid = $form->getVar('_userID'); + if (!$priceSetId) { + return; + } -$validFieldsOnly = TRUE; -$className = CRM_Utils_System::getClassName($form); -if (in_array($className, array( + $validFieldsOnly = TRUE; + $className = CRM_Utils_System::getClassName($form); + if (in_array($className, array( 'CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) { -$validFieldsOnly = FALSE; -} + $validFieldsOnly = FALSE; + } -$priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly); -$form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); -$form->_quickConfig = $quickConfig = 0; -if (CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $priceSetId, 'is_quick_config')) { - $quickConfig = 1; -} + $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly); + $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); + $form->_quickConfig = $quickConfig = 0; + if (CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $priceSetId, 'is_quick_config')) { + $quickConfig = 1; + } -$form->assign('quickConfig', $quickConfig); -if ($className == "CRM_Contribute_Form_Contribution_Main") { -$form->_quickConfig = $quickConfig; -} -$form->assign('priceSet', $form->_priceSet); + $form->assign('quickConfig', $quickConfig); + if ($className == "CRM_Contribute_Form_Contribution_Main") { + $form->_quickConfig = $quickConfig; + } + $form->assign('priceSet', $form->_priceSet); -$component = 'contribution'; -if ($className == 'CRM_Member_Form_Membership') { -$component = 'membership'; -} + $component = 'contribution'; + if ($className == 'CRM_Member_Form_Membership') { + $component = 'membership'; + } -if ($className == 'CRM_Contribute_Form_Contribution_Main') { -$feeBlock = &$form->_values['fee']; -if (!empty($form->_useForMember)) { -$component = 'membership'; -} -} -else { -$feeBlock = &$form->_priceSet['fields']; -} + if ($className == 'CRM_Contribute_Form_Contribution_Main') { + $feeBlock = &$form->_values['fee']; + if (!empty($form->_useForMember)) { + $component = 'membership'; + } + } + else { + $feeBlock = &$form->_priceSet['fields']; + } -// call the hook. -CRM_Utils_Hook::buildAmount($component, $form, $feeBlock); + // call the hook. + CRM_Utils_Hook::buildAmount($component, $form, $feeBlock); -foreach ($feeBlock as $field) { -if (CRM_Utils_Array::value('visibility', $field) == 'public' || + foreach ($feeBlock as $field) { + if (CRM_Utils_Array::value('visibility', $field) == 'public' || !$validFieldsOnly ) { -$options = CRM_Utils_Array::value('options', $field); -if ($className == 'CRM_Contribute_Form_Contribution_Main' && $component = 'membership') { -$checklifetime = self::checkCurrentMembership($options, $userid); -if ($checklifetime) { -$form->assign('ispricelifetime', TRUE); -} -} -if (!is_array($options)) { - continue; -} -CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field::addQuickFormElement($form, -'price_' . $field['id'], -$field['id'], -FALSE, -CRM_Utils_Array::value('is_required', $field, FALSE), -NULL, -$options -); -} -} -} + $options = CRM_Utils_Array::value('options', $field); + if ($className == 'CRM_Contribute_Form_Contribution_Main' && $component = 'membership') { + $checklifetime = self::checkCurrentMembership($options, $userid); + if ($checklifetime) { + $form->assign('ispricelifetime', TRUE); + } + } + if (!is_array($options)) { + continue; + } + CRM_Upgrade_Snapshot_V4p2_Price_BAO_Field::addQuickFormElement($form, + 'price_' . $field['id'], + $field['id'], + FALSE, + CRM_Utils_Array::value('is_required', $field, FALSE), + NULL, + $options + ); + } + } + } -/** - * check the current Membership - * having end date null. - */ -static function checkCurrentMembership(&$options, $userid) { -if (!$userid || empty($options)) { -return; -} -static $_contact_memberships = array(); -$checklifetime = FALSE; -foreach ($options as $key => $value) { -if (!empty($value['membership_type_id'])) { -if (!isset($_contact_memberships[$userid][$value['membership_type_id']])) { -$_contact_memberships[$userid][$value['membership_type_id']] = CRM_Member_BAO_Membership::getContactMembership($userid, $value['membership_type_id'], FALSE); -} -$currentMembership = $_contact_memberships[$userid][$value['membership_type_id']]; -if (!empty($currentMembership) && empty($currentMembership['end_date'])) { -unset($options[$key]); -$checklifetime = TRUE; -} -} -} -if ($checklifetime) { -return TRUE; -} -else { -return FALSE; -} -} + /** + * check the current Membership + * having end date null. + */ + static function checkCurrentMembership(&$options, $userid) { + if (!$userid || empty($options)) { + return; + } + static $_contact_memberships = array(); + $checklifetime = FALSE; + foreach ($options as $key => $value) { + if (!empty($value['membership_type_id'])) { + if (!isset($_contact_memberships[$userid][$value['membership_type_id']])) { + $_contact_memberships[$userid][$value['membership_type_id']] = CRM_Member_BAO_Membership::getContactMembership($userid, $value['membership_type_id'], FALSE); + } + $currentMembership = $_contact_memberships[$userid][$value['membership_type_id']]; + if (!empty($currentMembership) && empty($currentMembership['end_date'])) { + unset($options[$key]); + $checklifetime = TRUE; + } + } + } + if ($checklifetime) { + return TRUE; + } + else { + return FALSE; + } + } /** * Set daefult the price set fields. @@ -876,92 +877,93 @@ return FALSE; * * @return array $defaults */ -static function setDefaultPriceSet(&$form, &$defaults) { -if (!isset($form->_priceSet) || empty($form->_priceSet['fields'])) { -return $defaults; -} + static function setDefaultPriceSet(&$form, &$defaults) { + if (!isset($form->_priceSet) || empty($form->_priceSet['fields'])) { + return $defaults; + } -foreach ($form->_priceSet['fields'] as $key => $val) { -foreach ($val['options'] as $keys => $values) { -if ($values['is_default']) { -if ($val['html_type'] == 'CheckBox') { -$defaults["price_{$key}"][$keys] = 1; -} -else { -$defaults["price_{$key}"] = $keys; -} -} -} -} -return $defaults; -} + foreach ($form->_priceSet['fields'] as $key => $val) { + foreach ($val['options'] as $keys => $values) { + if ($values['is_default']) { + if ($val['html_type'] == 'CheckBox') { + $defaults["price_{$key}"][$keys] = 1; + } + else { + $defaults["price_{$key}"] = $keys; + } + } + } + } + return $defaults; + } -/** - * Get field ids of a price set - * - * @param int id Price Set id - * - * @return array of the field ids - * - * @static - */ -public static function getFieldIds($id) { -$priceField = new CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field(); -$priceField->price_set_id = $id; -$priceField->find(); -while ($priceField->fetch()) { -$var[] = $priceField->id; -} -return $var; -} + /** + * Get field ids of a price set + * + * @param int id Price Set id + * + * @return array of the field ids + * + * @static + */ + public static function getFieldIds($id) { + $priceField = new CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field(); + $priceField->price_set_id = $id; + $priceField->find(); + while ($priceField->fetch()) { + $var[] = $priceField->id; + } + return $var; + } -/** - * This function is to make a copy of a price set, including - * all the fields - * - * @param int $id - * The price set id to copy. - * - * @return the copy object - * @static - */ -static function copy($id) { -$maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set"); - -$title = ts('[Copy id %1]', array(1 => $maxId + 1)); -$fieldsFix = array( - 'suffix' => array('title' => ' ' . $title, -'name' => '__Copy_id_' . ($maxId + 1) . '_', -), -); - -$copy = &CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', -array('id' => $id), -NULL, -$fieldsFix -); - -//copying all the blocks pertaining to the price set -$copyPriceField = &CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field', -array('price_set_id' => $id), -array('price_set_id' => $copy->id) -); -if (!empty($copyPriceField)) { -$price = array_combine(self::getFieldIds($id), self::getFieldIds($copy->id)); - -//copy option group and values -foreach ($price as $originalId => $copyId) { -CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue', -array('price_field_id' => $originalId), -array('price_field_id' => $copyId) -); -} -} -$copy->save(); + /** + * This function is to make a copy of a price set, including + * all the fields + * + * @param int $id + * The price set id to copy. + * + * @return the copy object + * @static + */ + static function copy($id) { + $maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set"); + + $title = ts('[Copy id %1]', array(1 => $maxId + 1)); + $fieldsFix = array( + 'suffix' => array( + 'title' => ' ' . $title, + 'name' => '__Copy_id_' . ($maxId + 1) . '_', + ), + ); -CRM_Utils_Hook::copy('Set', $copy); -return $copy; -} + $copy = &CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', + array('id' => $id), + NULL, + $fieldsFix + ); + + //copying all the blocks pertaining to the price set + $copyPriceField = &CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field', + array('price_set_id' => $id), + array('price_set_id' => $copy->id) + ); + if (!empty($copyPriceField)) { + $price = array_combine(self::getFieldIds($id), self::getFieldIds($copy->id)); + + //copy option group and values + foreach ($price as $originalId => $copyId) { + CRM_Core_DAO::copyGeneric('CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue', + array('price_field_id' => $originalId), + array('price_field_id' => $copyId) + ); + } + } + $copy->save(); + + CRM_Utils_Hook::copy('Set', $copy); + return $copy; + } /** * This function is to check price set permission @@ -971,17 +973,17 @@ return $copy; * * @return bool */ -function checkPermission($sid) { -if ($sid && + function checkPermission($sid) { + if ($sid && self::eventPriceSetDomainID() ) { -$domain_id = CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $sid, 'domain_id', 'id'); -if (CRM_Core_Config::domainID() != $domain_id) { -CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); -} -} -return TRUE; -} + $domain_id = CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', $sid, 'domain_id', 'id'); + if (CRM_Core_Config::domainID() != $domain_id) { + CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); + } + } + return TRUE; + } /** * Get the sum of participant count @@ -995,20 +997,20 @@ return TRUE; * @return int|null|string * @static */ -public static function getPricesetCount($sid, $onlyActive = TRUE) { -$count = 0; -if (!$sid) { - return $count; -} + public static function getPricesetCount($sid, $onlyActive = TRUE) { + $count = 0; + if (!$sid) { + return $count; + } -$where = NULL; -if ($onlyActive) { - $where = 'AND value.is_active = 1 AND field.is_active = 1'; -} + $where = NULL; + if ($onlyActive) { + $where = 'AND value.is_active = 1 AND field.is_active = 1'; + } -static $pricesetFieldCount; -if (!isset($pricesetFieldCount[$sid])) { -$sql = " + static $pricesetFieldCount; + if (!isset($pricesetFieldCount[$sid])) { + $sql = " SELECT sum(value.count) as totalCount FROM civicrm_price_field_value value INNER JOIN civicrm_price_field field ON ( field.id = value.price_field_id ) @@ -1016,12 +1018,12 @@ INNER JOIN civicrm_price_set pset ON ( pset.id = field.price_set_id ) WHERE pset.id = %1 $where"; -$count = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($sid, 'Positive'))); -$pricesetFieldCount[$sid] = ($count) ? $count : 0; -} + $count = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($sid, 'Positive'))); + $pricesetFieldCount[$sid] = ($count) ? $count : 0; + } -return $pricesetFieldCount[$sid]; -} + return $pricesetFieldCount[$sid]; + } /** * @param $ids @@ -1029,38 +1031,38 @@ return $pricesetFieldCount[$sid]; * @return array */ public static function getMembershipCount($ids) { -$queryString = " + $queryString = " SELECT count( pfv.id ) AS count, pfv.id AS id FROM civicrm_price_field_value pfv INNER JOIN civicrm_membership_type mt ON mt.id = pfv.membership_type_id WHERE pfv.id IN ( $ids ) GROUP BY mt.member_of_contact_id"; -$crmDAO = CRM_Core_DAO::executeQuery($queryString); -$count = array(); + $crmDAO = CRM_Core_DAO::executeQuery($queryString); + $count = array(); -while ($crmDAO->fetch()) { -$count[$crmDAO->id] = $crmDAO->count; -} + while ($crmDAO->fetch()) { + $count[$crmDAO->id] = $crmDAO->count; + } -return $count; -} + return $count; + } -/** - * Function to check if auto renew option should be shown - * - * @param int $priceSetId - * Price set id. - * - * @return int $autoRenewOption ( 0:hide, 1:optional 2:required ) - */ -public static function checkAutoRenewForPriceSet($priceSetId) { -// auto-renew option should be visible if membership types associated with all the fields has -// been set for auto-renew option -// Auto renew checkbox should be frozen if for all the membership type auto renew is required + /** + * Function to check if auto renew option should be shown + * + * @param int $priceSetId + * Price set id. + * + * @return int $autoRenewOption ( 0:hide, 1:optional 2:required ) + */ + public static function checkAutoRenewForPriceSet($priceSetId) { + // auto-renew option should be visible if membership types associated with all the fields has + // been set for auto-renew option + // Auto renew checkbox should be frozen if for all the membership type auto renew is required -// get the membership type auto renew option and check if required or optional -$query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit + // get the membership type auto renew option and check if required or optional + $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit FROM civicrm_price_field_value pfv INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id @@ -1068,31 +1070,31 @@ $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit AND pf.is_active = 1 AND pfv.is_active = 1'; -$params = array(1 => array($priceSetId, 'Integer')); + $params = array(1 => array($priceSetId, 'Integer')); -$dao = CRM_Core_DAO::executeQuery($query, $params); -$autoRenewOption = 2; -$interval = $unit = array(); -while ($dao->fetch()) { -if (!$dao->auto_renew) { -$autoRenewOption = 0; -break; -} -if ($dao->auto_renew == 1) { -$autoRenewOption = 1; -} + $dao = CRM_Core_DAO::executeQuery($query, $params); + $autoRenewOption = 2; + $interval = $unit = array(); + while ($dao->fetch()) { + if (!$dao->auto_renew) { + $autoRenewOption = 0; + break; + } + if ($dao->auto_renew == 1) { + $autoRenewOption = 1; + } -$interval[$dao->duration_interval] = $dao->duration_interval; -$unit[$dao->duration_unit] = $dao->duration_unit; -} + $interval[$dao->duration_interval] = $dao->duration_interval; + $unit[$dao->duration_unit] = $dao->duration_unit; + } -if (count($interval) == 1 && count($unit) == 1 && $autoRenewOption > 0) { -return $autoRenewOption; -} -else { -return 0; -} -} + if (count($interval) == 1 && count($unit) == 1 && $autoRenewOption > 0) { + return $autoRenewOption; + } + else { + return 0; + } + } /** * Retrieve auto renew frequency and interval @@ -1103,18 +1105,18 @@ return 0; * @return array associate array of frequency interval and unit * @static */ - public static function getRecurDetails($priceSetId) { - $query = 'SELECT mt.duration_interval, mt.duration_unit + public static function getRecurDetails($priceSetId) { + $query = 'SELECT mt.duration_interval, mt.duration_unit FROM civicrm_price_field_value pfv INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id WHERE pf.price_set_id = %1 LIMIT 1'; - $params = array(1 => array($priceSetId, 'Integer')); - $dao = CRM_Core_DAO::executeQuery($query, $params); - $dao->fetch(); - return array($dao->duration_interval, $dao->duration_unit); - } + $params = array(1 => array($priceSetId, 'Integer')); + $dao = CRM_Core_DAO::executeQuery($query, $params); + $dao->fetch(); + return array($dao->duration_interval, $dao->duration_unit); + } /** * @return object @@ -1131,7 +1133,7 @@ return 0; * * @param int $id * Id of the database record. - * @param boolean $isQuickConfig + * @param bool $isQuickConfigValue we want to set the is_quick_config field. * Value we want to set the is_quick_config field. * * @return Object DAO object on sucess, null otherwise -- 2.25.1