From e084b065d0b8abd8684fb74be4d1e0e66db33f74 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Mon, 9 Feb 2015 10:48:05 -0800 Subject: [PATCH] Refs #7112, do not access database in DuplicateActionRemover constructor. --- .../Model/DuplicateActionRemover.php | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/plugins/CoreAdminHome/Model/DuplicateActionRemover.php b/plugins/CoreAdminHome/Model/DuplicateActionRemover.php index 51a93bab472..03cc5292842 100644 --- a/plugins/CoreAdminHome/Model/DuplicateActionRemover.php +++ b/plugins/CoreAdminHome/Model/DuplicateActionRemover.php @@ -48,7 +48,7 @@ class DuplicateActionRemover * * @var string[] */ - private $idactionColumns; + private $idactionColumns = null; /** * Constructor. @@ -67,8 +67,6 @@ public function __construct($tableMetadataAccess = null, $logger = null) $logger = StaticContainer::get('Psr\Log\LoggerInterface'); } $this->logger = $logger; - - $this->idactionColumns = $this->getIdActionTableColumnsFromMetadata(); } /** @@ -120,7 +118,8 @@ public function getDuplicateIdActions() */ public function fixDuplicateActionsInTable($table, $realIdAction, $duplicateIdActions) { - $idactionColumns = array_values($this->idactionColumns[$table]); + $idactionColumns = $this->getIdActionTableColumnsFromMetadata(); + $idactionColumns = array_values($idactionColumns[$table]); $table = Common::prefixTable($table); $inFromIdsExpression = $this->getInFromIdsExpression($duplicateIdActions); @@ -149,7 +148,8 @@ public function fixDuplicateActionsInTable($table, $realIdAction, $duplicateIdAc */ public function getSitesAndDatesOfRowsUsingDuplicates($table, $duplicateIdActions) { - $idactionColumns = array_values($this->idactionColumns[$table]); + $idactionColumns = $this->getIdActionTableColumnsFromMetadata(); + $idactionColumns = array_values($idactionColumns[$table]); $table = Common::prefixTable($table); $sql = "SELECT idsite, DATE(server_time) as server_time FROM $table "; @@ -159,18 +159,20 @@ public function getSitesAndDatesOfRowsUsingDuplicates($table, $duplicateIdAction private function getIdActionTableColumnsFromMetadata() { - $result = array(); - foreach (self::$tablesWithIdActionColumns as $table) { - $columns = $this->tableMetadataAccess->getIdActionColumnNames(Common::prefixTable($table)); + if ($this->idactionColumns === null) { + $this->idactionColumns = array(); + foreach (self::$tablesWithIdActionColumns as $table) { + $columns = $this->tableMetadataAccess->getIdActionColumnNames(Common::prefixTable($table)); - $this->logger->debug("Found following idactions in {table}: {columns}", array( - 'table' => $table, - 'columns' => implode(',', $columns) - )); + $this->logger->debug("Found following idactions in {table}: {columns}", array( + 'table' => $table, + 'columns' => implode(',', $columns) + )); - $result[$table] = $columns; + $this->idactionColumns[$table] = $columns; + } } - return $result; + return $this->idactionColumns; } private function getWhereToGetRowsUsingDuplicateActions($idactionColumns, $fromIdActions)