Пример #1
0
 /**
  * Vytvoří DB a naplní testovacími daty.
  */
 public function runMigrations()
 {
     if (!$this->context->parameters['migrations']['enabled']) {
         return;
     }
     $connection = $this->context->getService('dibiConnection');
     $dbNamePrefix = $this->context->parameters['testDbPrefix'] . date('Ymd_His') . '_';
     $i = 1;
     do {
         $dbName = $dbNamePrefix . $i;
         $i++;
     } while ($connection->query('SHOW DATABASES WHERE %n', 'Database', ' = %s', $dbName)->count());
     $connection->query('CREATE DATABASE %n COLLATE=utf8_czech_ci', $dbName);
     $connection->query('USE %n', $dbName);
     $migrationsPath = $this->context->parameters['wwwDir'] . '/' . $this->context->parameters['migrations']['path'];
     $finder = new Migration\Finders\MultipleDirectories();
     $finder->addDirectory($migrationsPath . '/struct');
     $finder->addDirectory($migrationsPath . '/data');
     $migrations = $this->createRunner($connection);
     ob_start();
     $migrations->run($finder, FALSE, TRUE);
     $result = ob_get_clean();
     if (substr(strip_tags($result), -2) !== 'OK') {
         throw new \Exception('Migrace neproběhly v pořádku: ' . $result);
     }
     $this->context->parameters['testDbName'] = $dbName;
 }
Пример #2
0
 /**
  * @param array of extensionName
  * @return array path => Migration\File
  */
 public function find(array $extensions)
 {
     $files = array();
     foreach ($this->directories as $directory) {
         $files += $directory->find($extensions);
     }
     uasort($files, function ($a, $b) {
         if ($a->file === $b->file) {
             list($a, $b) = MultipleDirectories::pathDiff($a->path, $b->path);
             throw new Migration\Exception("Finders\\MultipleDirectories: migration file name is same in '{$b}' and '{$a}'.");
         }
         return strcmp($a->file, $b->file);
     });
     return $files;
 }