From f931b74cf85c797e77962eb01aee0c5a5755f806 Mon Sep 17 00:00:00 2001 From: deepak-srivastava Date: Mon, 27 Jul 2015 17:24:54 +0100 Subject: [PATCH] Code styling fixes --- CRM/Contact/Page/AJAX.php | 106 ++++++++++++++++-------------- CRM/Contact/Page/DedupeMerge.php | 34 +++++----- CRM/Core/BAO/CustomValueTable.php | 3 +- CRM/Core/BAO/PrevNextCache.php | 22 +++---- CRM/Dedupe/Merger.php | 14 ++-- CRM/Utils/JSON.php | 3 +- 6 files changed, 98 insertions(+), 84 deletions(-) diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index fea8d422ee..f03bc0d640 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -668,7 +668,7 @@ LIMIT {$offset}, {$rowCount} CRM_Utils_JSON::output(array('status' => ($status) ? $oper : $status)); } - static function getDedupes() { + public static function getDedupes() { $offset = isset($_REQUEST['start']) ? CRM_Utils_Type::escape($_REQUEST['start'], 'Integer') : 0; $rowCount = isset($_REQUEST['length']) ? CRM_Utils_Type::escape($_REQUEST['length'], 'Integer') : 25; @@ -697,7 +697,7 @@ LIMIT {$offset}, {$rowCount} $searchData = CRM_Utils_Array::value('search', $_REQUEST); $searchData['value'] = CRM_Utils_Type::escape($searchData['value'], 'String'); - if ($src || !empty($searchData['value']) ) { + if ($src || !empty($searchData['value'])) { $src = $src ? $src : $searchData['value']; $where[] = " cc1.display_name LIKE '%{$src}%'"; } @@ -730,13 +730,13 @@ LIMIT {$offset}, {$rowCount} $where[] = " (ca2.is_primary = 1 AND ca2.street_address LIKE '%{$dst_street}%')"; } if (!empty($searchData['value'])) { - $whereClause = ' ( '.implode(' OR ', $where).' ) '; + $whereClause = ' ( ' . implode(' OR ', $where) . ' ) '; } else { if (!empty($where)) { $whereClause = implode(' AND ', $where); } - } + } $whereClause .= $whereClause ? ' AND de.id IS NULL' : ' de.id IS NULL'; if ($selected) { @@ -744,23 +744,22 @@ LIMIT {$offset}, {$rowCount} } $join .= " LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND pn.entity_id2 = de.contact_id2 )"; - $select = array( - 'cc1.contact_type' => 'src_contact_type', - 'cc1.display_name' => 'src_display_name', - 'cc1.contact_sub_type'=> 'src_contact_sub_type', - 'cc2.contact_type' => 'dst_contact_type', - 'cc2.display_name' => 'dst_display_name', - 'cc2.contact_sub_type'=> 'dst_contact_sub_type', - 'ce1.email' => 'src_email', - 'ce2.email' => 'dst_email', - 'ca1.postal_code' => 'src_postcode', - 'ca2.postal_code' => 'dst_postcode', - 'ca1.street_address' => 'src_street', - 'ca2.street_address' => 'dst_street' + 'cc1.contact_type' => 'src_contact_type', + 'cc1.display_name' => 'src_display_name', + 'cc1.contact_sub_type' => 'src_contact_sub_type', + 'cc2.contact_type' => 'dst_contact_type', + 'cc2.display_name' => 'dst_display_name', + 'cc2.contact_sub_type' => 'dst_contact_sub_type', + 'ce1.email' => 'src_email', + 'ce2.email' => 'dst_email', + 'ca1.postal_code' => 'src_postcode', + 'ca2.postal_code' => 'dst_postcode', + 'ca1.street_address' => 'src_street', + 'ca2.street_address' => 'dst_street', ); - if($select) { + if ($select) { $join .= " INNER JOIN civicrm_contact cc1 ON cc1.id = pn.entity_id1"; $join .= " INNER JOIN civicrm_contact cc2 ON cc2.id = pn.entity_id2"; $join .= " LEFT JOIN civicrm_email ce1 ON (ce1.contact_id = pn.entity_id1 AND ce1.is_primary = 1 )"; @@ -776,34 +775,42 @@ LIMIT {$offset}, {$rowCount} } } $columnDetails = CRM_Utils_Array::value($orderColumnNumber, $_REQUEST['columns']); - if(!empty($columnDetails)) { + if (!empty($columnDetails)) { switch ($columnDetails['data']) { - case 'src': - $whereClause .= " ORDER BY cc1.display_name {$dir}"; - break; - case 'src_email': - $whereClause .= " ORDER BY ce1.email {$dir}"; - break; - case 'src_street': - $whereClause .= " ORDER BY ca1.street_address {$dir}"; - break; - case 'src_postcode': - $whereClause .= " ORDER BY ca1.postal_code {$dir}"; - break; - case 'dst': - $whereClause .= " ORDER BY cc2.display_name {$dir}"; - break; - case 'dst_email': - $whereClause .= " ORDER BY ce2.email {$dir}"; - break; - case 'dst_street': - $whereClause .= " ORDER BY ca2.street_address {$dir}"; - break; - case 'dst_postcode': - $whereClause .= " ORDER BY ca2.postal_code {$dir}"; - break; - default: - break; + case 'src': + $whereClause .= " ORDER BY cc1.display_name {$dir}"; + break; + + case 'src_email': + $whereClause .= " ORDER BY ce1.email {$dir}"; + break; + + case 'src_street': + $whereClause .= " ORDER BY ca1.street_address {$dir}"; + break; + + case 'src_postcode': + $whereClause .= " ORDER BY ca1.postal_code {$dir}"; + break; + + case 'dst': + $whereClause .= " ORDER BY cc2.display_name {$dir}"; + break; + + case 'dst_email': + $whereClause .= " ORDER BY ce2.email {$dir}"; + break; + + case 'dst_street': + $whereClause .= " ORDER BY ca2.street_address {$dir}"; + break; + + case 'dst_postcode': + $whereClause .= " ORDER BY ca2.postal_code {$dir}"; + break; + + default: + break; } } @@ -885,7 +892,7 @@ LIMIT {$offset}, {$rowCount} CRM_Utils_JSON::output($paperSize); } - static function flipDupePairs($prevNextId = NULL) { + public static function flipDupePairs($prevNextId = NULL) { if (!$prevNextId) { $prevNextId = $_REQUEST['pnid']; } @@ -897,7 +904,8 @@ LIMIT {$offset}, {$rowCount} $prevNextId = implode(', ', $prevNextId); $prevNextId = CRM_Utils_Type::escape($prevNextId, 'String'); $query .= "WHERE cpc.id IN ({$prevNextId}) AND cpc.is_selected = 1"; - } else { + } + else { $prevNextId = CRM_Utils_Type::escape($prevNextId, 'Positive'); $query .= "WHERE cpc.id = $prevNextId"; } @@ -970,7 +978,7 @@ LIMIT {$offset}, {$rowCount} CRM_Utils_JSON::output($addressVal); } - static function toggleDedupeSelect() { + public static function toggleDedupeSelect() { $rgid = CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer'); $gid = CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer'); $pnid = $_REQUEST['pnid']; @@ -983,7 +991,7 @@ LIMIT {$offset}, {$rowCount} $params = array( 1 => array($isSelected, 'Boolean'), - 3 => array("$cacheKeyString%", 'String') // using % to address rows with conflicts as well + 3 => array("$cacheKeyString%", 'String'), // using % to address rows with conflicts as well ); //check pnid is_array or integer diff --git a/CRM/Contact/Page/DedupeMerge.php b/CRM/Contact/Page/DedupeMerge.php index 97970ea44a..da762dda6b 100644 --- a/CRM/Contact/Page/DedupeMerge.php +++ b/CRM/Contact/Page/DedupeMerge.php @@ -23,7 +23,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ /** * @@ -32,7 +32,7 @@ * $Id$ * */ -class CRM_Contact_Page_DedupeMerge extends CRM_Core_Page{ +class CRM_Contact_Page_DedupeMerge extends CRM_Core_Page { const BATCHLIMIT = 2; @@ -42,12 +42,13 @@ class CRM_Contact_Page_DedupeMerge extends CRM_Core_Page{ * @return void * @access public */ - function run() { + public function run() { $runner = self::getRunner(); if ($runner) { // Run Everything in the Queue via the Web. $runner->runAllViaWeb(); - } else { + } + else { CRM_Core_Session::setStatus(ts('Nothing to merge.')); } @@ -55,7 +56,7 @@ class CRM_Contact_Page_DedupeMerge extends CRM_Core_Page{ return parent::run(); } - static function getRunner() { + public static function getRunner() { $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0); $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0); $action = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject); @@ -84,9 +85,10 @@ class CRM_Contact_Page_DedupeMerge extends CRM_Core_Page{ if ($action == CRM_Core_Action::MAP) { $where = "pn.is_selected = 1"; $isSelected = 1; - } else { + } + else { // else merge all (2) - $isSelected = 2; + $isSelected = 2; } $total = CRM_Core_BAO_PrevNextCache::getCount($cacheKeyString, NULL, $where); @@ -98,11 +100,11 @@ class CRM_Contact_Page_DedupeMerge extends CRM_Core_Page{ // reset merge stats, so we compute new stats CRM_Dedupe_Merger::resetMergeStats($cacheKeyString); - for ($i = 1; $i <= ceil($total/self::BATCHLIMIT); $i++) { + for ($i = 1; $i <= ceil($total / self::BATCHLIMIT); $i++) { $task = new CRM_Queue_Task( - array ('CRM_Contact_Page_DedupeMerge', 'callBatchMerge'), + array('CRM_Contact_Page_DedupeMerge', 'callBatchMerge'), array($rgid, $gid, $mode, TRUE, self::BATCHLIMIT, $isSelected), - "Processed " . $i*self::BATCHLIMIT . " pair of duplicates out of " . $total + "Processed " . $i * self::BATCHLIMIT . " pair of duplicates out of " . $total ); // Add the Task to the Queue @@ -112,10 +114,10 @@ class CRM_Contact_Page_DedupeMerge extends CRM_Core_Page{ // Setup the Runner $urlQry .= "&context=conflicts"; $runner = new CRM_Queue_Runner(array( - 'title' => ts('Merging Duplicates..'), - 'queue' => $queue, - 'errorMode'=> CRM_Queue_Runner::ERROR_ABORT, - 'onEndUrl' => CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry, TRUE, NULL, FALSE), + 'title' => ts('Merging Duplicates..'), + 'queue' => $queue, + 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, + 'onEndUrl' => CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry, TRUE, NULL, FALSE), )); return $runner; @@ -124,10 +126,10 @@ class CRM_Contact_Page_DedupeMerge extends CRM_Core_Page{ /** * Collect Mailchimp data into temporary working table. */ - static function callBatchMerge(CRM_Queue_TaskContext $ctx, $rgid, $gid = NULL, $mode = 'safe', $autoFlip = TRUE, $batchLimit = 1, $isSelected = 2) { + public static function callBatchMerge(CRM_Queue_TaskContext $ctx, $rgid, $gid = NULL, $mode = 'safe', $autoFlip = TRUE, $batchLimit = 1, $isSelected = 2) { $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, $mode, $autoFlip, $batchLimit, $isSelected); return CRM_Queue_Task::TASK_SUCCESS; } -} +} diff --git a/CRM/Core/BAO/CustomValueTable.php b/CRM/Core/BAO/CustomValueTable.php index d2da71444e..a86ffe6655 100644 --- a/CRM/Core/BAO/CustomValueTable.php +++ b/CRM/Core/BAO/CustomValueTable.php @@ -214,7 +214,8 @@ class CRM_Core_BAO_CustomValueTable { // when unsetting a value to null, we don't need to validate the type // https://projectllr.atlassian.net/browse/VGQBMP-20 $set[$field['column_name']] = $value; - } else { + } + else { $set[$field['column_name']] = "%{$count}"; $params[$count] = array($value, $type); $count++; diff --git a/CRM/Core/BAO/PrevNextCache.php b/CRM/Core/BAO/PrevNextCache.php index 74d9995a33..3550edb7b1 100644 --- a/CRM/Core/BAO/PrevNextCache.php +++ b/CRM/Core/BAO/PrevNextCache.php @@ -159,7 +159,7 @@ WHERE cacheKey = %3 AND CRM_Core_DAO::executeQuery($sql, $params); } - static function markConflict($id1, $id2, $cacheKey, $conflicts) { + public static function markConflict($id1, $id2, $cacheKey, $conflicts) { if (empty($cacheKey) || empty($conflicts)) { return FALSE; } @@ -206,12 +206,12 @@ WHERE cacheKey = %3 AND */ public static function retrieve($cacheKey, $join = NULL, $where = NULL, $offset = 0, $rowCount = 0, $select = array()) { $selectString = 'pn.*'; - if(!empty($select)) { + if (!empty($select)) { $aliasArray = array(); foreach ($select as $column => $alias) { - $aliasArray[] = $column.' as '.$alias; + $aliasArray[] = $column . ' as ' . $alias; } - $selectString .= " , ".implode(' , ', $aliasArray); + $selectString .= " , " . implode(' , ', $aliasArray); } $query = " SELECT SQL_CALC_FOUND_ROWS {$selectString} @@ -221,7 +221,7 @@ WHERE (pn.cacheKey = %1 OR pn.cacheKey = %2) "; $params = array( 1 => array($cacheKey, 'String'), - 2 => array("{$cacheKey}_conflicts", 'String') + 2 => array("{$cacheKey}_conflicts", 'String'), ); if ($where) { @@ -253,10 +253,10 @@ WHERE (pn.cacheKey = %1 OR pn.cacheKey = %2) $extraData[$sfield] = $dao->$sfield; } $main[$count] = array( - 'prevnext_id' => $dao->id, - 'is_selected' => $dao->is_selected, - 'entity_id1' => $dao->entity_id1, - 'entity_id2' => $dao->entity_id2, + 'prevnext_id' => $dao->id, + 'is_selected' => $dao->is_selected, + 'entity_id1' => $dao->entity_id1, + 'entity_id2' => $dao->entity_id2, 'data' => $main[$count], ); $main[$count] = array_merge($main[$count], $extraData); @@ -266,7 +266,7 @@ WHERE (pn.cacheKey = %1 OR pn.cacheKey = %2) return $main; } - + /** * @param $string * @@ -307,7 +307,7 @@ WHERE (pn.cacheKey $op %1 OR pn.cacheKey $op %2) $params = array( 1 => array($cacheKey, 'String'), - 2 => array("{$cacheKey}_conflicts", 'String') + 2 => array("{$cacheKey}_conflicts", 'String'), ); return (int) CRM_Core_DAO::singleValueQuery($query, $params, TRUE, FALSE); } diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 2f5e5d7de7..e1e9ea9287 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -565,7 +565,8 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m * Does a force merge otherwise. * @param bool $autoFlip to let api decide which contact to retain and which to delete. * Wether to let api decide which contact to retain and which to delete. - * @param bool $redirectForPerformance + * @param int $batchLimit number of merges to carry out in one batch. + * @param int $isSelected if records with is_selected column needs to be processed. * * @return array|bool */ @@ -601,7 +602,7 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m return CRM_Dedupe_Merger::merge($dupePairs, $cacheParams, $mode, $autoFlip, $redirectForPerformance); } - static function updateMergeStats($cacheKeyString, $result = array()) { + public static function updateMergeStats($cacheKeyString, $result = array()) { // gather latest stats $merged = count($result['merged']); $skipped = count($result['skipped']); @@ -636,11 +637,11 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m CRM_Core_BAO_PrevNextCache::setItem($values); } - static function resetMergeStats($cacheKeyString) { + public static function resetMergeStats($cacheKeyString) { return CRM_Core_BAO_PrevNextCache::deleteItem(NULL, "{$cacheKeyString}_stats"); } - static function getMergeStats($cacheKeyString) { + public static function getMergeStats($cacheKeyString) { $stats = CRM_Core_BAO_PrevNextCache::retrieve("{$cacheKeyString}_stats"); if (!empty($stats)) { $stats = $stats[0]; @@ -648,7 +649,7 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m return $stats; } - static function getMergeStatsMsg($cacheKeyString) { + public static function getMergeStatsMsg($cacheKeyString) { $msg = ''; $stats = CRM_Dedupe_Merger::getMergeStats($cacheKeyString); if (!empty($stats['merged'])) { @@ -735,7 +736,8 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m $conflicts[$key] = "{$migrationInfo['rows'][$key]['title']}: '{$migrationInfo['rows'][$key]['main']}' vs. '{$migrationInfo['rows'][$key]['other']}'"; } CRM_Core_BAO_PrevNextCache::markConflict($mainId, $otherId, $cacheKeyString, $conflicts); - } else { + } + else { // delete entry from PrevNextCache table so we don't consider the pair next time // pair may have been flipped, so make sure we delete using both orders CRM_Core_BAO_PrevNextCache::deletePair($mainId, $otherId, $cacheKeyString, TRUE); diff --git a/CRM/Utils/JSON.php b/CRM/Utils/JSON.php index 169ac62924..6df05ada6e 100644 --- a/CRM/Utils/JSON.php +++ b/CRM/Utils/JSON.php @@ -99,7 +99,7 @@ class CRM_Utils_JSON { * @return string * */ - static function encodeDataTable($params, $iTotal, $iFilteredTotal, $selectorElements) { + public static function encodeDataTable($params, $iTotal, $iFilteredTotal, $selectorElements) { $sOutput = '{'; $sOutput .= '"recordsTotal": ' . $iTotal . ', '; $sOutput .= '"recordsFiltered": ' . $iFilteredTotal . ', '; @@ -127,4 +127,5 @@ class CRM_Utils_JSON { return $sOutput; } + } -- 2.25.1