Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2015-03-31 01:00:25 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-03-31 05:27:07 +0300
commitbe9dc8ecb9c74d515a1d510fddf09bbbb455fe5a (patch)
tree3ad34c68b4a7d37c1a40cfdd334df9e799c040ca /core/DataAccess
parent12d9b392a9f2a8a867d04b7c3889cfc261b783b1 (diff)
extracted code into a function
Diffstat (limited to 'core/DataAccess')
-rw-r--r--core/DataAccess/ArchiveSelector.php65
1 files changed, 31 insertions, 34 deletions
diff --git a/core/DataAccess/ArchiveSelector.php b/core/DataAccess/ArchiveSelector.php
index 2d38ab9146..faeef35b88 100644
--- a/core/DataAccess/ArchiveSelector.php
+++ b/core/DataAccess/ArchiveSelector.php
@@ -10,6 +10,7 @@ namespace Piwik\DataAccess;
use Exception;
use Piwik\Archive;
+use Piwik\Archive\Chunk;
use Piwik\ArchiveProcessor;
use Piwik\ArchiveProcessor\Rules;
use Piwik\Common;
@@ -221,13 +222,14 @@ class ArchiveSelector
* @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.
* @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
* @return array
*/
public static function getArchiveData($archiveIds, $recordNames, $archiveDataType, $idSubtable)
{
- $chunk = new Archive\Chunk();
+ $chunk = new Chunk();
// create the SQL to select archive data
$loadAllSubtables = $idSubtable == Archive::ID_SUBTABLE_LOAD_ALL_SUBTABLES;
@@ -301,37 +303,7 @@ class ArchiveSelector
$row['value'] = self::uncompress($row['value']);
if ($chunk->isRecordNameAChunk($row['name'])) {
- $blobs = unserialize($row['value']);
-
- 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'],
- );
- }
-
+ self::moveChunkRowToRows($rows, $row, $chunk, $loadAllSubtables, $idSubtable);
} else {
$rows[] = $row;
}
@@ -342,7 +314,32 @@ class ArchiveSelector
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;
}