class CRM_Upgrade_Incremental_php_FourThree {
const BATCH_SIZE = 5000;
+ /**
+ * @param $errors
+ *
+ * @return bool
+ */
function verifyPreDBstate(&$errors) {
return TRUE;
}
* Note: This function is called iteratively for each upcoming
* revision to the database.
*
- * @param $postUpgradeMessage string, alterable
+ * @param $preUpgradeMessage
* @param $rev string, a version number, e.g. '4.3.alpha1', '4.3.beta3', '4.3.0'
+ * @param null $currentVer
+ *
* @return void|bool
*/
function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
}
}
}
-
+
if ($rev == '4.3.6') {
$constraintArray = array(
'civicrm_contact' => 'contact_id',
- 'civicrm_payment_processor' => 'payment_processor_id',
+ 'civicrm_payment_processor' => 'payment_processor_id',
);
-
- if (version_compare('4.1alpha1', $currentVer) <= 0) {
+
+ if (version_compare('4.1alpha1', $currentVer) <= 0) {
$constraintArray['civicrm_campaign'] = 'campaign_id';
}
-
- if (version_compare('4.3alpha1', $currentVer) <= 0) {
+
+ if (version_compare('4.3alpha1', $currentVer) <= 0) {
$constraintArray['civicrm_financial_type'] = 'financial_type_id';
}
-
+
foreach ($constraintArray as $key => $value) {
$query = "SELECT contri_recur.id FROM civicrm_contribution_recur contri_recur LEFT JOIN {$key} ON contri_recur.{$value} = {$key}.id
WHERE {$key}.id IS NULL";
}
}
+ /**
+ * @param $rev
+ *
+ * @return bool
+ */
function upgrade_4_3_alpha1($rev) {
self::task_4_3_alpha1_checkDBConstraints();
return TRUE;
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_alpha2($rev) {
//CRM-11847
$isColumnPresent = CRM_Core_DAO::checkFieldExists('civicrm_dedupe_rule_group', 'is_default');
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha2')), 'task_4_3_x_runSql', $rev);
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_alpha3($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha3')), 'task_4_3_x_runSql', $rev);
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_beta2($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta2')), 'task_4_3_x_runSql', $rev);
}
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_beta3($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta3')), 'task_4_3_x_runSql', $rev);
// CRM-12065
$this->addTask('Replace contribution_type to financial_type in table civicrm_saved_search', 'replaceContributionTypeId', $query, 'savedSearch');
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_beta4($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta4')), 'task_4_3_x_runSql', $rev);
// add indexes for civicrm_entity_financial_trxn
$this->addTask('Check/Add indexes for civicrm_entity_financial_trxn', 'task_4_3_x_checkIndexes', $rev);
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_beta5($rev) {
// CRM-12205
if (
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta5')), 'task_4_3_x_runSql', $rev);
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_4($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.4')), 'task_4_3_x_runSql', $rev);
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_5($rev) {
// CRM-12156
$config = CRM_Core_Config::singleton();
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.5')), 'task_4_3_x_runSql', $rev);
}
+ /**
+ * @param $rev
+ */
function upgrade_4_3_6($rev) {
//CRM-13094
- $this->addTask(ts('Add missing contraints'), 'addMissingConstraints', $rev);
+ $this->addTask(ts('Add missing constraints'), 'addMissingConstraints', $rev);
//CRM-13088
$this->addTask('Add ON DELETE Options for constraints', 'task_4_3_x_checkConstraints', $rev);
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.6')), 'task_4_3_x_runSql', $rev);
$this->addTask('Update financial_account_id in financial_trxn table', 'updateFinancialTrxnData', $rev);
$this->addTask('Update Line Item Data', 'updateLineItemData', $rev);
}
-
+
//CRM-11636
+ /**
+ * @return bool
+ */
function assignFinancialTypeToPriceRecords() {
$upgrade = new CRM_Upgrade_Form();
//here we update price set entries
return TRUE;
}
+ /**
+ * @return bool
+ */
static function _checkAndMigrateDefaultFinancialTypes() {
$modifiedDefaults = FALSE;
//insert types if not exists
return $modifiedDefaults;
}
+ /**
+ * @return bool
+ */
function createFinancialRecords() {
$upgrade = new CRM_Upgrade_Form();
return TRUE;
}
+ /**
+ * @return array
+ */
function createDomainContacts() {
$domainParams = $context = array();
$query = "
return TRUE;
}
-
+
/**
- * change index and add missing constraints for civicrm_contribution_recur
+ * Change index and add missing constraints for civicrm_contribution_recur
*/
function addMissingConstraints(CRM_Queue_TaskContext $ctx) {
$query = "SHOW KEYS FROM `civicrm_contribution_recur` WHERE key_name = 'UI_contrib_payment_instrument_id'";
CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_contribution_recur ADD INDEX UI_contribution_recur_payment_instrument_id (payment_instrument_id)');
}
$constraintArray = array(
- 'contact_id' => " ADD CONSTRAINT `FK_civicrm_contribution_recur_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE ",
- 'payment_processor_id' => " ADD CONSTRAINT `FK_civicrm_contribution_recur_payment_processor_id` FOREIGN KEY (`payment_processor_id`) REFERENCES `civicrm_payment_processor` (`id`) ON DELETE SET NULL ",
- 'financial_type_id' => " ADD CONSTRAINT `FK_civicrm_contribution_recur_financial_type_id` FOREIGN KEY (`financial_type_id`) REFERENCES `civicrm_financial_type` (`id`) ON DELETE SET NULL ",
+ 'contact_id' => " ADD CONSTRAINT `FK_civicrm_contribution_recur_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE ",
+ 'payment_processor_id' => " ADD CONSTRAINT `FK_civicrm_contribution_recur_payment_processor_id` FOREIGN KEY (`payment_processor_id`) REFERENCES `civicrm_payment_processor` (`id`) ON DELETE SET NULL ",
+ 'financial_type_id' => " ADD CONSTRAINT `FK_civicrm_contribution_recur_financial_type_id` FOREIGN KEY (`financial_type_id`) REFERENCES `civicrm_financial_type` (`id`) ON DELETE SET NULL ",
'campaign_id' => " ADD CONSTRAINT `FK_civicrm_contribution_recur_campaign_id` FOREIGN KEY (`campaign_id`) REFERENCES `civicrm_campaign` (`id`) ON DELETE SET NULL ",
);
$constraint = array();
$query = "ALTER TABLE civicrm_contribution_recur " . implode(' , ', $constraint);
CRM_Core_DAO::executeQuery($query);
}
- return TRUE;
+ return TRUE;
}
/**
* Update financial_account_id for bad data in financial_trxn table
* CRM-12844
- *
+ *
*/
function updateFinancialTrxnData(CRM_Queue_TaskContext $ctx) {
$upgrade = new CRM_Upgrade_Form();
- $sql = "SELECT cc.id contribution_id, cc.contribution_recur_id, cft.payment_processor_id,
+ $sql = "SELECT cc.id contribution_id, cc.contribution_recur_id, cft.payment_processor_id,
cft.id financial_trxn_id, cfi.entity_table, cft.from_financial_account_id, cft.to_financial_account_id
FROM `civicrm_contribution` cc
LEFT JOIN civicrm_entity_financial_trxn ceft ON ceft.entity_id = cc.id
LEFT JOIN civicrm_financial_trxn cft ON cft.id = ceft.financial_trxn_id
-LEFT JOIN civicrm_entity_financial_trxn ceft1 ON ceft1.financial_trxn_id = ceft.financial_trxn_id
+LEFT JOIN civicrm_entity_financial_trxn ceft1 ON ceft1.financial_trxn_id = ceft.financial_trxn_id
LEFT JOIN civicrm_financial_item cfi ON cfi.id = ceft1.entity_id
WHERE ceft.entity_table = 'civicrm_contribution' AND cc.contribution_recur_id IS NOT NULL
AND ceft1.entity_table = 'civicrm_financial_item' AND cft.id IS NOT NULL AND cft.payment_instrument_id = %1
}
}
elseif (!array_key_exists($dao->contribution_id, $financialTrxn[$dao->contribution_recur_id])) {
- if (($dao->entity_table == 'civicrm_line_item' && $dao->to_financial_account_id == $financialTrxn[$dao->contribution_recur_id]['from_financial_account_id'])
+ if (($dao->entity_table == 'civicrm_line_item' && $dao->to_financial_account_id == $financialTrxn[$dao->contribution_recur_id]['from_financial_account_id'])
|| ($dao->entity_table == 'civicrm_financial_trxn' && $dao->from_financial_account_id == $financialTrxn[$dao->contribution_recur_id]['from_financial_account_id'])) {
continue;
}
else {
$field = 'to_financial_account_id';
}
- $sql = "UPDATE civicrm_financial_trxn SET $field = " . $financialTrxn[$dao->contribution_recur_id]['from_financial_account_id'] . ',
-payment_processor_id = ' . $financialTrxn[$dao->contribution_recur_id]['payment_processor_id'] . ' WHERE
+ $sql = "UPDATE civicrm_financial_trxn SET $field = " . $financialTrxn[$dao->contribution_recur_id]['from_financial_account_id'] . ',
+payment_processor_id = ' . $financialTrxn[$dao->contribution_recur_id]['payment_processor_id'] . ' WHERE
id IN (' . implode(',', $val) . ')';
CRM_Core_DAO::executeQuery($sql);
}
/**
* Update financial_account_id for bad data in financial_trxn table
* CRM-12844
- *
+ *
*/
function updateLineItemData(CRM_Queue_TaskContext $ctx) {
$sql = "SELECT cc.id contribution_id, cc.contribution_recur_id,
-cc.financial_type_id contribution_financial_type,
+cc.financial_type_id contribution_financial_type,
cli.financial_type_id line_financial_type_id,
cli.price_field_id, cli.price_field_value_id, cli.label, cli.id line_item_id,
cfi.financial_account_id
LEFT JOIN civicrm_price_field cpf ON cpf.id = cli.price_field_id
LEFT JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id
LEFT JOIN civicrm_price_field_value cpfv ON cpfv.id = cli.price_field_value_id
-WHERE cfi.entity_table = 'civicrm_line_item'
+WHERE cfi.entity_table = 'civicrm_line_item'
AND cli.entity_table = 'civicrm_contribution'
-AND cps.is_quick_config = 1 AND cc.contribution_recur_id IS NOT NULL
+AND cps.is_quick_config = 1 AND cc.contribution_recur_id IS NOT NULL
ORDER BY cli.id";
$dao = CRM_Core_DAO::executeQuery($sql);
$financialTrxn = $subsequentPayments = array();
foreach ($subsequentPayments as $key => $value) {
$sql = "UPDATE civicrm_line_item cli
LEFT JOIN civicrm_financial_item cfi ON cli.id = cfi.entity_id
-SET
+SET
cli.label = %1,
cli.price_field_id = %2,
cli.price_field_value_id = %3,
cfi.financial_account_id = %4,
cfi.description = %5,
cli.financial_type_id = %6
-WHERE cfi.entity_table = 'civicrm_line_item'
+WHERE cfi.entity_table = 'civicrm_line_item'
AND cli.entity_table = 'civicrm_contribution' AND cli.id IN (" . implode(',', $value). ');';
$params = array(
1 => array($financialTrxn[$key]['label'], 'String'),
}
/**
- * replace contribution_type to financial_type in table
+ * Replace contribution_type to financial_type in table
* civicrm_saved_search and Structure civicrm_report_instance
*/
function replaceContributionTypeId(CRM_Queue_TaskContext $ctx, $query, $table) {
* Add ON DELETE options for constraint if not present
* CRM-13088 && CRM-12156
*
+ * @param CRM_Queue_TaskContext $ctx
+ *
* @return bool TRUE for success
*/
function task_4_3_x_checkConstraints(CRM_Queue_TaskContext $ctx) {
"'FK_civicrm_grant_financial_type_id'",
);
- $sql = "SELECT DELETE_RULE, TABLE_NAME, CONSTRAINT_NAME
+ $sql = "SELECT DELETE_RULE, TABLE_NAME, CONSTRAINT_NAME
FROM information_schema.REFERENTIAL_CONSTRAINTS
WHERE CONSTRAINT_NAME IN (" . implode(',', $constraintArray) . ")
AND CONSTRAINT_SCHEMA = %1";
$params = array(1 => array($dbname['database'], 'String'));
$onDelete = CRM_Core_DAO::executeQuery($sql, $params, TRUE, FALSE);
while ($onDelete->fetch()) {
- if (($onDelete->TABLE_NAME != 'civicrm_financial_item' && $onDelete->DELETE_RULE != 'SET NULL') ||
+ if (($onDelete->TABLE_NAME != 'civicrm_financial_item' && $onDelete->DELETE_RULE != 'SET NULL') ||
($onDelete->TABLE_NAME == 'civicrm_financial_item' && $onDelete->DELETE_RULE != 'CASCADE')) {
$tableName = 'civicrm_financial_type';
$onDeleteOption = ' SET NULL ';
/**
* Check/Add INDEX CRM-12141
*
+ * @param CRM_Queue_TaskContext $ctx
+ *
* @return bool TRUE for success
*/
function task_4_3_x_checkIndexes(CRM_Queue_TaskContext $ctx) {
/**
* Update phones CRM-11292
*
+ * @param CRM_Queue_TaskContext $ctx
+ *
* @return bool TRUE for success
*/
static function phoneNumeric(CRM_Queue_TaskContext $ctx) {