Skip to content
Extraits de code Groupes Projets
Valider be9dc8ec rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

extracted code into a function

parent 12d9b392
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -514,11 +514,6 @@ class Archive ...@@ -514,11 +514,6 @@ class Archive
return $dataTable; return $dataTable;
} }
private function appendIdSubtable($recordName, $id)
{
return $recordName . "_" . $id;
}
private function getSiteIdsThatAreRequestedInThisArchiveButWereNotInvalidatedYet() private function getSiteIdsThatAreRequestedInThisArchiveButWereNotInvalidatedYet()
{ {
if (is_null(self::$cache)) { if (is_null(self::$cache)) {
...@@ -604,7 +599,7 @@ class Archive ...@@ -604,7 +599,7 @@ class Archive
// place. // place.
$dataNames = array(); $dataNames = array();
foreach ($archiveNames as $name) { foreach ($archiveNames as $name) {
$dataNames[] = $this->appendIdsubtable($name, $idSubtable); $dataNames[] = ArchiveSelector::appendIdsubtable($name, $idSubtable);
} }
} else { } else {
$dataNames = $archiveNames; $dataNames = $archiveNames;
......
...@@ -10,6 +10,7 @@ namespace Piwik\DataAccess; ...@@ -10,6 +10,7 @@ namespace Piwik\DataAccess;
use Exception; use Exception;
use Piwik\Archive; use Piwik\Archive;
use Piwik\Archive\Chunk;
use Piwik\ArchiveProcessor; use Piwik\ArchiveProcessor;
use Piwik\ArchiveProcessor\Rules; use Piwik\ArchiveProcessor\Rules;
use Piwik\Common; use Piwik\Common;
...@@ -221,13 +222,14 @@ class ArchiveSelector ...@@ -221,13 +222,14 @@ class ArchiveSelector
* @param array $recordNames The names of the data to retrieve (ie, nb_visits, nb_actions, etc.). * @param array $recordNames The names of the data to retrieve (ie, nb_visits, nb_actions, etc.).
* Note: You CANNOT pass multiple recordnames if $loadAllSubtables=true. * Note: You CANNOT pass multiple recordnames if $loadAllSubtables=true.
* @param string $archiveDataType The archive data type (either, 'blob' or 'numeric'). * @param string $archiveDataType The archive data type (either, 'blob' or 'numeric').
* @param int $idSubtable * @param int|null|string $idSubtable null if the root blob should be loaded, an integer if a subtable should be
* loaded and 'all' if all subtables should be loaded.
* @throws Exception * @throws Exception
* @return array * @return array
*/ */
public static function getArchiveData($archiveIds, $recordNames, $archiveDataType, $idSubtable) public static function getArchiveData($archiveIds, $recordNames, $archiveDataType, $idSubtable)
{ {
$chunk = new Archive\Chunk(); $chunk = new Chunk();
// create the SQL to select archive data // create the SQL to select archive data
$loadAllSubtables = $idSubtable == Archive::ID_SUBTABLE_LOAD_ALL_SUBTABLES; $loadAllSubtables = $idSubtable == Archive::ID_SUBTABLE_LOAD_ALL_SUBTABLES;
...@@ -301,37 +303,7 @@ class ArchiveSelector ...@@ -301,37 +303,7 @@ class ArchiveSelector
$row['value'] = self::uncompress($row['value']); $row['value'] = self::uncompress($row['value']);
if ($chunk->isRecordNameAChunk($row['name'])) { if ($chunk->isRecordNameAChunk($row['name'])) {
$blobs = unserialize($row['value']); self::moveChunkRowToRows($rows, $row, $chunk, $loadAllSubtables, $idSubtable);
if (!is_array($blobs)) {
continue;
}
// $rawName = eg 'PluginName_ArchiveName'
$rawName = $chunk->getRecordNameWithoutChunkAppendix($row['name']);
if ($loadAllSubtables) {
foreach ($blobs as $subtableId => $blob) {
$rows[] = array(
'name' => self::appendIdSubtable($rawName, $subtableId),
'value' => $blob,
'idsite' => $row['idsite'],
'date1' => $row['date1'],
'date2' => $row['date2'],
'ts_archived' => $row['ts_archived'],
);
}
} elseif (array_key_exists($idSubtable, $blobs)) {
$rows[] = array(
'name' => self::appendIdSubtable($rawName, $idSubtable),
'value' => $blobs[$idSubtable],
'idsite' => $row['idsite'],
'date1' => $row['date1'],
'date2' => $row['date2'],
'ts_archived' => $row['ts_archived'],
);
}
} else { } else {
$rows[] = $row; $rows[] = $row;
} }
...@@ -342,7 +314,32 @@ class ArchiveSelector ...@@ -342,7 +314,32 @@ class ArchiveSelector
return $rows; return $rows;
} }
private static function appendIdSubtable($recordName, $id) private static function moveChunkRowToRows(&$rows, $row, Chunk $chunk, $loadAllSubtables, $idSubtable)
{
// $blobs = array([subtableID] = [blob of subtableId])
$blobs = unserialize($row['value']);
if (!is_array($blobs)) {
return;
}
// $rawName = eg 'PluginName_ArchiveName'
$rawName = $chunk->getRecordNameWithoutChunkAppendix($row['name']);
if ($loadAllSubtables) {
foreach ($blobs as $subtableId => $blob) {
$row['value'] = $blob;
$row['name'] = self::appendIdSubtable($rawName, $subtableId);
$rows[] = $row;
}
} elseif (array_key_exists($idSubtable, $blobs)) {
$row['value'] = $blobs[$idSubtable];
$row['name'] = self::appendIdSubtable($rawName, $idSubtable);
$rows[] = $row;
}
}
public static function appendIdSubtable($recordName, $id)
{ {
return $recordName . "_" . $id; return $recordName . "_" . $id;
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter