Esempio n. 1
0
 /**
  * Find the last morph function in the previous migration files
  *
  * @param ItemInterface $toVersion
  * @param string        $tableName
  *
  * @return null|Migration
  * @throws Exception
  * @internal param ItemInterface $version
  */
 private static function createPrevClassWithMorphMethod(ItemInterface $toVersion, $tableName)
 {
     $prevVersions = [];
     $versions = self::scanForVersions(self::$_migrationPath);
     foreach ($versions as $prevVersion) {
         if ($prevVersion->getStamp() <= $toVersion->getStamp()) {
             $prevVersions[] = $prevVersion;
         }
     }
     $prevVersions = VersionCollection::sortDesc($prevVersions);
     foreach ($prevVersions as $prevVersion) {
         $migration = self::createClass($prevVersion, $tableName);
         if (is_object($migration) && method_exists($migration, 'morph')) {
             return $migration;
         }
     }
     return null;
 }
Esempio n. 2
0
 /**
  * Get latest completed migration version
  *
  * @param array $options Applications options
  * @return ItemInterface
  */
 public static function getCurrentVersion($options)
 {
     self::connectionSetup($options);
     if (isset($options['migrationsInDb']) && (bool) $options['migrationsInDb']) {
         /** @var AdapterInterface $connection */
         $connection = self::$_storage;
         $lastGoodMigration = $connection->query('SELECT * FROM ' . self::MIGRATION_LOG_TABLE . ' ORDER BY version DESC LIMIT 1');
         if (0 == $lastGoodMigration->numRows()) {
             return VersionCollection::createItem(null);
         } else {
             $lastGoodMigration = $lastGoodMigration->fetchArray();
             return VersionCollection::createItem($lastGoodMigration['version']);
         }
     } else {
         // Get and clean migration
         $version = file_exists(self::$_storage) ? file_get_contents(self::$_storage) : null;
         $version = trim($version) ?: null;
         return VersionCollection::createItem($version);
     }
 }