Beispiel #1
0
 /**
  * @param string $name
  * @param string|string[] $values  A blob string or an array of blob strings. If an array
  *                                 is used, the first element in the array will be inserted
  *                                 with the `$name` name. The others will be splitted into chunks. All subtables
  *                                 within one chunk will be serialized as an array where the index is the
  *                                 subtableId.
  */
 public function insertBlobRecord($name, $values)
 {
     if (is_array($values)) {
         $clean = array();
         if (isset($values[0])) {
             // we always store the root table in a single blob for fast access
             $clean[] = array($name, $this->compress($values[0]));
             unset($values[0]);
         }
         if (!empty($values)) {
             // we move all subtables into chunks
             $chunk = new Chunk();
             $chunks = $chunk->moveArchiveBlobsIntoChunks($name, $values);
             foreach ($chunks as $index => $subtables) {
                 $clean[] = array($index, $this->compress(serialize($subtables)));
             }
         }
         $this->insertBulkRecords($clean);
         return;
     }
     $values = $this->compress($values);
     $this->insertRecord($name, $values);
 }
 /**
  *  Check that it merges all subtables into one blob entry
  *
  * @depends      testApi
  */
 public function test_checkArchiveRecords_shouldMergeSubtablesIntoOneRow()
 {
     $chunk = new Chunk();
     $tests = array('archive_blob_2010_01' => array($chunk->getRecordNameForTableId('CustomVariables_valueByName', 0) => 6, $chunk->getRecordNameForTableId('Referrers_keywordBySearchEngine', 0) => 1, $chunk->getRecordNameForTableId('Referrers_searchEngineByKeyword', 0) => 1), 'archive_blob_2009_12' => array($chunk->getRecordNameForTableId('CustomVariables_valueByName', 0) => 6, $chunk->getRecordNameForTableId('Referrers_keywordBySearchEngine', 0) => 1, $chunk->getRecordNameForTableId('Referrers_searchEngineByKeyword', 0) => 1));
     $numTests = 0;
     foreach ($tests as $table => $expectedSubtables) {
         foreach ($expectedSubtables as $name => $expectedNumSubtables) {
             $sql = "SELECT `value` FROM " . Common::prefixTable($table) . " WHERE `name` ='{$name}'";
             $blobs = Db::get()->fetchAll($sql);
             foreach ($blobs as $blob) {
                 $numTests++;
                 $blob = $blob['value'];
                 $blob = gzuncompress($blob);
                 $blob = unserialize($blob);
                 $countSubtables = count($blob);
                 $this->assertEquals($expectedNumSubtables, $countSubtables, "{$name} in {$table} expected to contain {$expectedNumSubtables} subtables, got {$countSubtables}");
             }
         }
     }
     // 6 _subtables entries + 6 _subtables entries for the segment
     $this->assertEquals(12, $numTests, "{$numTests} were executed but expected 12");
 }
 /**
  *  Check that requesting period "Range" means only processing
  *  the requested Plugin blob (Actions in this case), not all Plugins blobs
  *
  * @depends      testApi
  */
 public function test_checkArchiveRecords_shouldMergeSubtablesIntoOneRow()
 {
     $tests = array('archive_blob_2010_12' => 3, 'archive_blob_2011_01' => 3);
     $chunk = new Chunk();
     $chunkName = $chunk->getRecordNameForTableId('Actions_actions_url', 0);
     foreach ($tests as $table => $expectedNumSubtables) {
         $sql = "SELECT value FROM " . Common::prefixTable($table) . " WHERE period = " . Piwik::$idPeriods['range'] . " and `name` ='{$chunkName}'";
         $blob = Db::get()->fetchOne($sql);
         $blob = gzuncompress($blob);
         $blob = unserialize($blob);
         $countSubtables = count($blob);
         $this->assertEquals($expectedNumSubtables, $countSubtables, "Actions_actions_url_chunk_0_99 in {$table} expected to contain {$expectedNumSubtables} subtables, got {$countSubtables}");
     }
 }
Beispiel #4
0
 /**
  * @dataProvider getRecordNameWithoutChunkAppendixDataProvider
  */
 public function test_getRecordNameWithoutChunkAppendix_shouldSplitChunksIntoBitsOf100($realName, $recordName)
 {
     $this->assertSame($realName, $this->chunk->getRecordNameWithoutChunkAppendix($recordName));
 }
 private function createManyDifferentArchiveBlobs()
 {
     $recordName1 = 'Actions_Actions';
     $recordName2 = 'Actions_Actionsurl';
     $chunk = new Chunk();
     $chunk0_1 = $chunk->getRecordNameForTableId($recordName1, 0);
     $chunk0_2 = $chunk->getRecordNameForTableId($recordName2, 0);
     $this->createArchiveBlobEntry('2013-01-01', array($recordName2 => 'test01'));
     $this->createArchiveBlobEntry('2013-01-02', array($recordName2 => 'test02', $recordName2 . '_1' => 'test1', $recordName2 . '_2' => 'test2', $recordName1 => 'actions_02', $chunk0_1 => serialize(array(1 => 'actionsSubtable1', 2 => 'actionsSubtable2', 5 => 'actionsSubtable5'))));
     $this->createArchiveBlobEntry('2013-01-03', array($recordName2 => 'test03', $chunk0_2 => serialize(array(1 => 'subtable1', 2 => 'subtable2', 5 => 'subtable5')), $recordName1 => 'actions_03', $recordName1 . '_1' => 'actionsTest1', $recordName1 . '_2' => 'actionsTest2'));
     $this->createArchiveBlobEntry('2013-01-04', array($recordName2 => 'test04', $recordName2 . '_5' => 'subtable45', $recordName2 . '_6' => 'subtable6'));
     $this->createArchiveBlobEntry('2013-01-06', array($recordName2 => 'test06', $chunk0_2 => serialize(array())));
 }
Beispiel #6
0
 protected 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'] = ArchiveSelector::appendIdSubtable($rawName, $subtableId);
             $rows[] = $row;
         }
     } elseif (array_key_exists($idSubtable, $blobs)) {
         $row['value'] = $blobs[$idSubtable];
         $row['name'] = ArchiveSelector::appendIdSubtable($rawName, $idSubtable);
         $rows[] = $row;
     }
 }