/**
  * 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);
 }
 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];
 }
 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();
     }
 }
 public function test_executeInsert()
 {
     $this->adapter->expects($this->once())->method('insert')->with($this->dbHelper->prefixTable('table'), $this->anything());
     $this->dbHelper->executeInsert('table', array());
 }