From: Jamie McClelland Date: Mon, 5 May 2014 15:43:12 +0000 (-0400) Subject: CRM-14646 - optimze image display upgrade code X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e71693e1d083a8c58a5acfa170af33138b0caa3d;p=civicrm-core.git CRM-14646 - optimze image display upgrade code ---------------------------------------- * CRM-14646: new image display upgrade code not optimized, can result in error https://issues.civicrm.org/jira/browse/CRM-14646 --- diff --git a/CRM/Upgrade/Incremental/php/FourFour.php b/CRM/Upgrade/Incremental/php/FourFour.php index d909df79c9..58d055ae46 100644 --- a/CRM/Upgrade/Incremental/php/FourFour.php +++ b/CRM/Upgrade/Incremental/php/FourFour.php @@ -308,8 +308,16 @@ ALTER TABLE civicrm_dashboard } function upgrade_4_4_6($rev){ - $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contact'); - $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contact'); + $sql = "SELECT count(*) AS count FROM INFORMATION_SCHEMA.STATISTICS where ". + "INDEX_NAME = 'index_image_url' AND TABLE_NAME = 'civicrm_contact';"; + $dao = CRM_Core_DAO::executeQuery($sql); + $dao->fetch(); + if($dao->count < 1) { + $sql = "CREATE INDEX index_image_url ON civicrm_contact (image_url);"; + $dao = CRM_Core_DAO::executeQuery($sql); + } + $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contact WHERE image_URL IS NOT NULL'); + $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contact WHERE image_URL IS NOT NULL'); for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) { $endId = $startId + self::BATCH_SIZE - 1; $title = ts('Upgrade image_urls (%1 => %2)', array(1 => $startId, 2 => $endId)); @@ -318,13 +326,12 @@ ALTER TABLE civicrm_dashboard } static function upgradeImageUrls(CRM_Queue_TaskContext $ctx, $startId, $endId){ - $sql = "CREATE INDEX index_image_url ON civicrm_contact (image_url);"; - $dao = CRM_Core_DAO::executeQuery($sql); $sql = " SELECT id, image_url FROM civicrm_contact WHERE 1 AND id BETWEEN %1 AND %2 +AND image_URL IS NOT NULL "; $params = array( 1 => array($startId, 'Integer'),