Skip to content

Commit

Permalink
Refs #7112, do not access database in DuplicateActionRemover construc…
Browse files Browse the repository at this point in the history
…tor.
  • Loading branch information
diosmosis committed Feb 9, 2015
1 parent a85b33a commit e084b06
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions plugins/CoreAdminHome/Model/DuplicateActionRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DuplicateActionRemover
*
* @var string[]
*/
private $idactionColumns;
private $idactionColumns = null;

/**
* Constructor.
Expand All @@ -67,8 +67,6 @@ public function __construct($tableMetadataAccess = null, $logger = null)
$logger = StaticContainer::get('Psr\Log\LoggerInterface');
}
$this->logger = $logger;

$this->idactionColumns = $this->getIdActionTableColumnsFromMetadata();
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 ";
Expand All @@ -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)
Expand Down

0 comments on commit e084b06

Please sign in to comment.