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

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

If $outputPathAndFilename is given, the SQL statements will be written to the given file instead of executed.
public executeMigrations ( string $version = null, string $outputPathAndFilename = null, boolean $dryRun = false, boolean $quiet = false ) : string
$version string The version to migrate to
$outputPathAndFilename string A file to write SQL to, instead of executing it
$dryRun boolean Whether to do a dry run or not
$quiet boolean Whether to do a quiet run or not
Результат string
    public function executeMigrations($version = null, $outputPathAndFilename = null, $dryRun = false, $quiet = false)
    {
        $configuration = $this->getMigrationConfiguration();
        $migration = new Migration($configuration);
        if ($outputPathAndFilename !== null) {
            $migration->writeSqlFile($outputPathAndFilename, $version);
        } else {
            $migration->migrate($version, $dryRun);
        }
        if ($quiet === true) {
            $output = '';
            foreach ($this->output as $line) {
                $line = strip_tags($line);
                if (strpos($line, '  ++ migrating ') !== false || strpos($line, '  -- reverting ') !== false) {
                    $output .= substr($line, -15);
                }
            }
            return $output;
        } else {
            return implode(PHP_EOL, $this->output);
        }
    }

Usage Example

Пример #1
0
 /**
  * Migrate the database schema
  *
  * Adjusts the database structure by applying the pending
  * migrations provided by currently active packages.
  *
  * @param string $version The version to migrate to
  * @param string $output A file to write SQL to, instead of executing it
  * @param boolean $dryRun Whether to do a dry run or not
  * @param boolean $quiet If set, only the executed migration versions will be output, one per line
  * @return void
  * @see neos.flow:doctrine:migrationstatus
  * @see neos.flow:doctrine:migrationexecute
  * @see neos.flow:doctrine:migrationgenerate
  * @see neos.flow:doctrine:migrationversion
  */
 public function migrateCommand($version = null, $output = null, $dryRun = false, $quiet = 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);
     }
     try {
         $result = $this->doctrineService->executeMigrations($version, $output, $dryRun, $quiet);
         if ($result == '') {
             if (!$quiet) {
                 $this->outputLine('No migration was necessary.');
             }
         } elseif ($output === null) {
             $this->outputLine($result);
         } else {
             if (!$quiet) {
                 $this->outputLine('Wrote migration SQL to file "' . $output . '".');
             }
         }
         $this->emitAfterDatabaseMigration();
     } catch (\Exception $exception) {
         $this->handleException($exception);
     }
 }