Skip to content

Commit

Permalink
Merge branch 'hotfix' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jimyhuang committed Jul 2, 2024
2 parents b25cf5c + 1bc28e6 commit 9e0191b
Show file tree
Hide file tree
Showing 41 changed files with 154 additions and 180 deletions.
7 changes: 6 additions & 1 deletion CRM/Contact/BAO/GroupContactCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ static function load(&$group, $fresh = FALSE) {
$idName = 'contact_id';
}
else {
$additionalWhereClause = " contact_a.id NOT IN ( SELECT contact_id FROM civicrm_group_contact WHERE civicrm_group_contact.status = 'Removed' AND civicrm_group_contact.group_id = $groupID )";
$additionalWhereClause = <<<EOT
NOT EXISTS (
SELECT 1 FROM civicrm_group_contact cgc_removed
WHERE cgc_removed.contact_id = contact_a.id AND cgc_removed.group_id = {$groupID} AND cgc_removed.status = 'Removed'
)
EOT;
$formValues = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);

$query = new CRM_Contact_BAO_Query(
Expand Down
27 changes: 16 additions & 11 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2691,13 +2691,6 @@ function addGroupContactCache($groups, $tableAlias = NULL, $joinTable = "contact
$group = CRM_Core_DAO::executeQuery($sql);
$ssWhere = array();
while ($group->fetch()) {
if ($tableAlias == NULL) {
$alias = "`civicrm_group_contact_cache_{$group->id}`";
}
else {
$alias = $tableAlias;
}

$this->_useDistinct = TRUE;

if (!$this->_smartGroupCache || $group->cache_date == NULL) {
Expand All @@ -2714,12 +2707,24 @@ function addGroupContactCache($groups, $tableAlias = NULL, $joinTable = "contact
}
}

$this->_tables[$alias] = $this->_whereTables[$alias] = " LEFT JOIN civicrm_group_contact_cache {$alias} ON {$joinTable}.id = {$alias}.contact_id ";
$ssWhere[] = "{$alias}.group_id = {$group->id}";
$groupIds[] = $group->id;
}

if (!empty($ssWhere)) {
return CRM_Utils_Array::implode(' OR ', $ssWhere);
if (!empty($groupIds)) {
if ($tableAlias == NULL) {
$alias = '`cgcc`';
}
else {
$alias = $tableAlias;
}
$groupIds = implode(',', $groupIds);
$whereSql = <<<EOT
EXISTS (
SELECT 1 FROM civicrm_group_contact_cache {$alias}
WHERE {$alias}.contact_id = {$joinTable}.id AND {$alias}.group_id IN ({$groupIds})
)
EOT;
return $whereSql;
}
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Import/Form/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function preProcess() {
$this->assign('dataValues', $this->_dataValues);

$tableName = $this->get('importTableName');
$prefix = str_replace('civicrm_import_job', CRM_Contribute_Import_Parser::ERROR_FILE_PREFIX, $tableName);
$prefix = str_replace(CRM_Import_ImportJob::TABLE_PREFIX, CRM_Contribute_Import_Parser::ERROR_FILE_PREFIX, $tableName);
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);

CRM_Import_Parser::setImportErrorFilenames($qfKey, array('error', 'conflict','no_match'), 'CRM_Contribute_Import_Parser', $prefix, $this);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Import/Form/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function preProcess() {
$this->set('totalRowCount', $totalRowCount);

$tableName = $this->get('importTableName');
$prefix = str_replace('civicrm_import_job', CRM_Contribute_Import_Parser::ERROR_FILE_PREFIX, $tableName);
$prefix = str_replace(CRM_Import_ImportJob::TABLE_PREFIX, CRM_Contribute_Import_Parser::ERROR_FILE_PREFIX, $tableName);
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);

CRM_Import_Parser::setImportErrorFilenames($qfKey, array('error', 'conflict','soft_credit_error', 'pcp_error', 'pledge_payment_error', 'duplicate', 'no_match'), 'CRM_Contribute_Import_Parser', $prefix, $this);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Import/Form/UploadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function postProcess() {
$this->_params['import_table_name'] = $this->get('importTableName');
if (!$this->_params['import_table_name']) {
$tableName = str_replace('.', '_', microtime(TRUE));
$this->_params['import_table_name'] = 'civicrm_import_job_' . $tableName;
$this->_params['import_table_name'] = CRM_Import_ImportJob::TABLE_PREFIX.'_' . $tableName;
}
CRM_Import_DataSource_CSV::postProcess($this, $this->_params, $db);
$importTableName = $this->get('importTableName');
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Import/ImportJob/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function runImport(&$form) {
$lock = NULL;
if (empty($civicrm_batch)) {
if ($this->_totalRowCount > CRM_Import_ImportJob::BATCH_THRESHOLD) {
$fileName = str_replace('civicrm_import_job_', '', $this->_tableName);
$fileName = str_replace(CRM_Import_ImportJob::TABLE_PREFIX.'_', '', $this->_tableName);
$fileName = 'import_contribution_'.$fileName.'.zip';
$config = CRM_Core_Config::singleton();
$file = $config->uploadDir.$fileName;
Expand Down Expand Up @@ -176,7 +176,7 @@ public function batchFinishCallback() {

if ($zip->open($zipFile, ZipArchive::CREATE) == TRUE) {
$config = CRM_Core_Config::singleton();
$fileName = str_replace('civicrm_import_job', CRM_Contribute_Import_Parser::ERROR_FILE_PREFIX, $this->_tableName);
$fileName = str_replace(CRM_Import_ImportJob::TABLE_PREFIX, CRM_Contribute_Import_Parser::ERROR_FILE_PREFIX, $this->_tableName);
$errorFiles = array();
$errorFiles[] = CRM_Contribute_Import_Parser::errorFileName(CRM_Contribute_Import_Parser::ERROR, $fileName);
$errorFiles[] = CRM_Contribute_Import_Parser::errorFileName(CRM_Contribute_Import_Parser::CONFLICT, $fileName);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ function run($tableName,
}
}
$headers = array_merge(array(ts('Line Number'), ts('Reason')), $customHeaders);
$filenamePrefix = str_replace('civicrm_import_job', self::ERROR_FILE_PREFIX, $tableName);
$filenamePrefix = str_replace(CRM_Import_ImportJob::TABLE_PREFIX, self::ERROR_FILE_PREFIX, $tableName);

if ($this->_invalidRowCount) {
$this->_errorFileName = self::errorFileName(self::ERROR, $filenamePrefix);
Expand Down
12 changes: 6 additions & 6 deletions CRM/Contribute/Page/DashBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ function processDashBoard(){
}

$contrib_this_year = $summary_contrib['ContribThisYear'];
$this->assign('this_year_sum_non_recur', $contrib_this_year['not_recur']['sum'] ? array_sum($contrib_this_year['not_recur']['sum']) : NULL);
$this->assign('this_year_sum_recur', $contrib_this_year['recur']['sum'] ? array_sum($contrib_this_year['recur']['sum']) : NULL);
$this->assign('this_year_count_non_recur', $contrib_this_year['not_recur']['count'] ? array_sum($contrib_this_year['not_recur']['count']) : NULL);
$this->assign('this_year_count_recur', $contrib_this_year['recur']['count'] ? array_sum($contrib_this_year['recur']['count']) : NULL);
$this->assign('this_year_people_non_recur', $contrib_this_year['not_recur']['people'] ? array_sum($contrib_this_year['not_recur']['people']) : NULL);
$this->assign('this_year_people_recur', $contrib_this_year['recur']['people'] ? array_sum($contrib_this_year['recur']['people']) : NULL);
$this->assign('this_year_sum_non_recur', $contrib_this_year['not_recur']['sum'] ? array_sum($contrib_this_year['not_recur']['sum']) : 0);
$this->assign('this_year_sum_recur', $contrib_this_year['recur']['sum'] ? array_sum($contrib_this_year['recur']['sum']) : 0);
$this->assign('this_year_count_non_recur', $contrib_this_year['not_recur']['count'] ? array_sum($contrib_this_year['not_recur']['count']) : 0);
$this->assign('this_year_count_recur', $contrib_this_year['recur']['count'] ? array_sum($contrib_this_year['recur']['count']) : 0);
$this->assign('this_year_people_non_recur', $contrib_this_year['not_recur']['people'] ? array_sum($contrib_this_year['not_recur']['people']) : 0);
$this->assign('this_year_people_recur', $contrib_this_year['recur']['people'] ? array_sum($contrib_this_year['recur']['people']) : 0);
$recur_year_sum = self::getDataForChart($year_month_label, $contrib_this_year['recur']);
$not_recur_year_sum = self::getDataForChart($year_month_label, $contrib_this_year['not_recur']);
for ($i=1; $i < 12; $i++) {
Expand Down
5 changes: 3 additions & 2 deletions CRM/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,15 +747,16 @@ function clearTempTables() {
// CRM-5645
require_once 'CRM/Contact/DAO/Contact.php';
$dao = new CRM_Contact_DAO_Contact();
$importTablePrefix = CRM_Import_ImportJob::TABLE_PREFIX;
$query = "
SELECT TABLE_NAME as import_table
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = %1 AND TABLE_NAME LIKE 'civicrm_import_job_%'";
WHERE TABLE_SCHEMA = %1 AND TABLE_NAME LIKE '{$importTablePrefix}_%'";
$params = array(1 => array($dao->database(), 'String'));
$tableDAO = CRM_Core_DAO::executeQuery($query, $params);
$importTables = array();
while ($tableDAO->fetch()) {
$microtime = str_replace('civicrm_import_job_', '', $tableDAO->import_table);
$microtime = str_replace($importTablePrefix.'_', '', $tableDAO->import_table);
list($microtime) = explode('_', $microtime);
// check if over 30 days
if (is_numeric($microtime)) {
Expand Down
5 changes: 5 additions & 0 deletions CRM/Core/DAO/AllCoreTables.data.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,11 @@
'class' => 'CRM_Contribute_DAO_AllPay',
'table' => 'civicrm_contribution_allpay',
) ,
'CRM_Contribute_DAO_SPGATEWAY' => array(
'name' => 'SPGATEWAY',
'class' => 'CRM_Contribute_DAO_SPGATEWAY',
'table' => 'civicrm_contribution_spgateway',
) ,
'CRM_Coupon_DAO_CouponTrack' => array(
'name' => 'CouponTrack',
'class' => 'CRM_Coupon_DAO_CouponTrack',
Expand Down
10 changes: 5 additions & 5 deletions CRM/Core/Payment/Backer.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ function processContribution($jsonString, &$contributionResult) {
$backerRelationTypeId = $config->backerFounderRelationship;
if (!empty($params['additional']['first_name']) && !empty($params['additional']['address']) && !empty($backerRelationTypeId)) {
$dedupeParams = array(
'email' => $params['additional']['email'][0]['email'],
'last_name' => $params['additional']['last_name'],
'first_name' => $params['additional']['first_name'],
'phone' => $params['additional']['phone'][0]['phone']
'email' => $params['additional']['email'][0]['email'],
'phone' => $params['additional']['phone'][0]['phone'],
);
$dedupeParams = CRM_Dedupe_Finder::formatParams($dedupeParams, 'Individual');
$foundDupes = CRM_Dedupe_Finder::dupesByRules(
Expand All @@ -330,9 +330,9 @@ function processContribution($jsonString, &$contributionResult) {
array(),
array(
array('table' => 'civicrm_contact', 'field' => 'last_name', 'weight' => 2),
array('table' => 'civicrm_contact', 'field' => 'first_name', 'weight' => 8),
array('table' => 'civicrm_email', 'field' => 'email', 'weight' => 10),
array('table' => 'civicrm_phone', 'field' => 'phone', 'weight' => 7),
array('table' => 'civicrm_contact', 'field' => 'first_name', 'weight' => 9),
array('table' => 'civicrm_email', 'field' => 'email', 'weight' => 9),
array('table' => 'civicrm_phone', 'field' => 'phone', 'weight' => 9),
),
20
);
Expand Down
12 changes: 9 additions & 3 deletions CRM/Core/Payment/SPGATEWAY.php
Original file line number Diff line number Diff line change
Expand Up @@ -1163,10 +1163,11 @@ public static function syncTransaction($inputTrxnId, $order = NULL) {
else {
$trxnId = $inputTrxnId;
}
$queryTrxnId = preg_replace('/^r_/', '', $trxnId);
$data = array(
'Amt' => floor($amount),
'MerchantID' => $paymentProcessor['user_name'],
'MerchantOrderNo' => $trxnId,
'MerchantOrderNo' => $queryTrxnId,
'RespondType' => self::RESPONSE_TYPE,
'TimeStamp' => CRM_REQUEST_TIME,
'Version' => self::QUERY_VERSION,
Expand Down Expand Up @@ -1345,10 +1346,12 @@ public static function recurSyncTransaction($trxnId, $createContribution = FALSE
}
else {
$amount = CRM_Core_DAO::singleValueQuery('SELECT amount FROM civicrm_contribution_recur WHERE id = %1', array(1 => array($contribution->contribution_recur_id, 'Positive')));

$queryTrxnId = preg_replace('/^r_/', '', $trxnId);
$data = array(
'Amt' => floor($amount),
'MerchantID' => $paymentProcessor['user_name'],
'MerchantOrderNo' => $trxnId,
'MerchantOrderNo' => $queryTrxnId,
'RespondType' => self::RESPONSE_TYPE,
'TimeStamp' => CRM_REQUEST_TIME,
'Version' => self::QUERY_VERSION,
Expand Down Expand Up @@ -1381,6 +1384,9 @@ public static function recurSyncTransaction($trxnId, $createContribution = FALSE
$ipnResult->Result->AlreadyTimes = $period_times;
}
$ipnResult->Result->MerchantOrderNo = $first_id;
if (preg_match('/^r_/', $trxnId)) {
$ipnResult->Result->OrderNo = $trxnId;
}
$ipnResult = json_encode($ipnResult);
$ipnPost = array('Period' => CRM_Core_Payment_SPGATEWAYAPI::recurEncrypt($ipnResult, $paymentProcessor));

Expand All @@ -1395,7 +1401,7 @@ public static function recurSyncTransaction($trxnId, $createContribution = FALSE
$result->_response = self::doIPN(array('spgateway', 'ipn', 'Credit'), $ipnPost, $ipnGet, FALSE);
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->trxn_id = $parentTrxnId;
if ($contribution->find(TRUE) && strstr($trxnId, '_1')) {
if ($contribution->find(TRUE) && preg_match('/_1$/', $trxnId)) {
// The case first contribution trxn_id not append '_1' in the end.
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'trxn_id', $trxnId);
}
Expand Down
Loading

0 comments on commit 9e0191b

Please sign in to comment.