protected function initQuery()
 {
     if ($this->rows instanceof \PDOStatement) {
         $this->cleanupResults();
     }
     $this->rows = $this->fromDbHelper->getAdapter()->prepare($this->query . ' LIMIT ' . $this->start . ', ' . $this->loadAtOnce);
     $this->rows->execute();
     $this->currentPosition = 0;
 }
 protected function processRow(&$row)
 {
     $id = $this->getIdFromRow($row);
     $this->translateRow($row);
     $this->targetDb->executeInsert($this->getTableName(), $row);
     if ($id != null) {
         $this->addNewId($id, $this->targetDb->lastInsertId());
     }
 }
 /**
  * Returns the archive list as strings looking like this: '2014-01'
  *
  * @param \DateTime $from
  * @param \DateTime $to
  *
  * @return string[]
  */
 public function getArchiveList(\DateTime $from = null, \DateTime $to = null)
 {
     $tablePrefix = $this->database->prefixTable('archive_numeric_');
     // We can't use Piwik\DataAccess\ArchiveTableCreator::getTablesArchivesInstalled()
     // because of the global DB object: it will use the "sourceDb" instead of the "targetDb"...
     // TODO Fix later when we have dependency injection
     $archives = $this->database->getAdapter()->fetchCol("SHOW TABLES LIKE '" . $tablePrefix . "%'");
     $archives = array_map(function ($value) use($tablePrefix) {
         return str_replace($tablePrefix, '', $value);
     }, $archives);
     $archives = array_filter($archives, function ($archive) use($from, $to) {
         $date = new \DateTime(str_replace('_', '-', $archive) . '-01');
         $excluded = $from && $from > $date || $to && $to < $date;
         return !$excluded;
     });
     return array_values($archives);
 }
 /**
  * @test
  */
 public function test_it_flushes_correctly()
 {
     $this->dbHelper->insert('test1', array('k1' => 'v1', 'k2' => 2));
     $this->dbHelper->insert('test1', array('k1' => 'v3', 'k2' => 4));
     $this->dbHelper->insert('test2', array('k3' => 'v5', 'k4' => 6));
     $this->adapter->expects($this->exactly(6))->method('quote')->willReturnCallback(function ($arg) {
         return "'" . $arg . "'";
     });
     $this->adapter->expects($this->exactly(2))->method('query')->withConsecutive(array("INSERT INTO piwik_test1 (`k1`, `k2`) VALUES ('v1', '2'), ('v3', '4')"), array("INSERT INTO piwik_test2 (`k3`, `k4`) VALUES ('v5', '6')"));
     $this->dbHelper->flushInserts();
 }
 private function getArchiveId($archiveDate, $archiveId)
 {
     if (!isset($this->archiveIdMap[$archiveDate][$archiveId])) {
         $sequence = new Sequence($this->targetDb->prefixTable('archive_numeric_' . $archiveDate), $this->targetDb->getAdapter(), $this->targetDb->prefixTable(''));
         if (!$sequence->exists()) {
             $sequence->create();
         }
         $this->archiveIdMap[$archiveDate][$archiveId] = $sequence->getNextId();
     }
     return $this->archiveIdMap[$archiveDate][$archiveId];
 }
예제 #6
0
 private function getLogVisitQueriesFor($table)
 {
     $visitIdRanges = $this->visitMigrator->getIdRanges();
     if (count($visitIdRanges) > 0) {
         $baseQuery = "SELECT * FROM " . $this->sourceDbHelper->prefixTable($table) . ' WHERE idvisit IN ';
         $queries = array();
         foreach ($visitIdRanges as $range) {
             $queries[] = $baseQuery . ' (' . implode(', ', $range) . ')';
         }
         return $queries;
     } else {
         return array();
     }
 }