Neos\Flow\Persistence\Doctrine\Service::updateSchema PHP 메소드

updateSchema() 공개 메소드

Updates the DB schema using Doctrine's SchemaTool. The $safeMode flag is passed to SchemaTool unchanged.
public updateSchema ( boolean $safeMode = true, string $outputPathAndFilename = null ) : string
$safeMode boolean
$outputPathAndFilename string A file to write SQL to, instead of executing it
리턴 string
    public function updateSchema($safeMode = true, $outputPathAndFilename = null)
    {
        $schemaTool = new SchemaTool($this->entityManager);
        $allMetaData = $this->entityManager->getMetadataFactory()->getAllMetadata();
        if ($outputPathAndFilename === null) {
            $schemaTool->updateSchema($allMetaData, $safeMode);
        } else {
            $updateSchemaSqlStatements = $schemaTool->getUpdateSchemaSql($allMetaData, $safeMode);
            file_put_contents($outputPathAndFilename, implode(PHP_EOL, $updateSchemaSqlStatements));
        }
    }

Usage Example

예제 #1
0
 /**
  * Update the database schema
  *
  * Updates the database schema without using existing migrations.
  *
  * It will not drop foreign keys, sequences and tables, unless <u>--unsafe-mode</u> is set.
  *
  * @param boolean $unsafeMode If set, foreign keys, sequences and tables can potentially be dropped.
  * @param string $output A file to write SQL to, instead of executing the update directly
  * @return void
  * @see neos.flow:doctrine:create
  * @see neos.flow:doctrine:migrate
  */
 public function updateCommand($unsafeMode = false, $output = null)
 {
     if (!$this->isDatabaseConfigured()) {
         $this->outputLine('Database schema update has been SKIPPED, the driver and host backend options are not set in /Configuration/Settings.yaml.');
         $this->quit(1);
     }
     $this->doctrineService->updateSchema(!$unsafeMode, $output);
     if ($output === null) {
         $this->outputLine('Executed a database schema update.');
     } else {
         $this->outputLine('Wrote schema update SQL to file "' . $output . '".');
     }
 }