Neos\Flow\Persistence\Doctrine\Service::markAsMigrated PHP Метод

markAsMigrated() публичный Метод

This does not execute any migration code but simply records a version as migrated or not.
public markAsMigrated ( string $version, boolean $markAsMigrated ) : void
$version string The version to add or remove
$markAsMigrated boolean
Результат void
    public function markAsMigrated($version, $markAsMigrated)
    {
        $configuration = $this->getMigrationConfiguration();
        if ($version === 'all') {
            foreach ($configuration->getMigrations() as $version) {
                if ($markAsMigrated === true && $configuration->hasVersionMigrated($version) === false) {
                    $version->markMigrated();
                } elseif ($markAsMigrated === false && $configuration->hasVersionMigrated($version) === true) {
                    $version->markNotMigrated();
                }
            }
        } else {
            if ($configuration->hasVersion($version) === false) {
                throw MigrationException::unknownMigrationVersion($version);
            }
            $version = $configuration->getVersion($version);
            if ($markAsMigrated === true) {
                if ($configuration->hasVersionMigrated($version) === true) {
                    throw new MigrationException(sprintf('The version "%s" is already marked as executed.', $version));
                }
                $version->markMigrated();
            } else {
                if ($configuration->hasVersionMigrated($version) === false) {
                    throw new MigrationException(sprintf('The version "%s" is already marked as not executed.', $version));
                }
                $version->markNotMigrated();
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * Mark/unmark migrations as migrated
  *
  * If <u>all</u> is given as version, all available migrations are marked
  * as requested.
  *
  * @param string $version The migration to execute
  * @param boolean $add The migration to mark as migrated
  * @param boolean $delete The migration to mark as not migrated
  * @return void
  * @throws \InvalidArgumentException
  * @see neos.flow:doctrine:migrate
  * @see neos.flow:doctrine:migrationstatus
  * @see neos.flow:doctrine:migrationexecute
  * @see neos.flow:doctrine:migrationgenerate
  */
 public function migrationVersionCommand($version, $add = false, $delete = false)
 {
     if (!$this->isDatabaseConfigured()) {
         $this->outputLine('Doctrine migration not possible, the driver and host backend options are not set in /Configuration/Settings.yaml.');
         $this->quit(1);
     }
     if ($add === false && $delete === false) {
         throw new \InvalidArgumentException('You must specify whether you want to --add or --delete the specified version.');
     }
     try {
         $this->doctrineService->markAsMigrated($version, $add ?: false);
     } catch (MigrationException $exception) {
         $this->outputLine($exception->getMessage());
         $this->quit(1);
     }
 }