protected function execute(InputInterface $input, OutputInterface $output) { /** * @var $schema Schema */ $schema = $this->application->getStorage()->getSchema(); $debug = $input->getArgument('debug') == true; $fs = new Filesystem(); $fs->dumpFile($this->application->getProject()->getPath('build php Storage Master.php'), $this->fenom->render("master", array('schema' => $schema))); if ($debug) { echo '- master' . PHP_EOL; } foreach ($schema->getModels() as $model) { $modelGenerator = $this->application->getManager()->create('Cti\\Storage\\Generator\\Model', array('model' => $model)); $modelSource = $modelGenerator->getCode(); $path = $this->application->getProject()->getPath('build php Storage Model ' . $model->getClassName() . 'Base.php'); $fs->dumpFile($path, $modelSource); $repositoryGenerator = $this->application->getManager()->create('Cti\\Storage\\Generator\\Repository', array('model' => $model)); $repositorySource = $repositoryGenerator->getCode(); $path = $this->application->getProject()->getPath('build php Storage Repository ' . $model->getClassName() . 'Repository.php'); $fs->dumpFile($path, $repositorySource); if ($debug) { echo '- generate ' . $model->getClassName() . PHP_EOL; } // if($model->hasOwnQuery()) { // $fs->dumpFile( // $this->application->getPath('build php Storage Query ' . $model->class_name . 'Select.php'), // $this->application->getManager()->create('Cti\Storage\Generator\Select', array( // 'model' => $model // )) // ); // } } }
protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $schema = $this->application->getStorage()->getSchema(); // create.sql $dbalToSchema = $this->dbalConverter->convert($schema); $dbalFromSchema = $schema = new \Doctrine\DBAL\Schema\Schema(); $this->generator->setToSchema($dbalToSchema); $this->generator->setFromSchema($dbalFromSchema); $queries = $this->generator->migrate(); $debug = $input->getArgument('debug') == true; $create = $this->application->getProject()->getPath('build sql create.sql'); if ($debug) { echo "- build create.sql" . PHP_EOL; } $output->writeln('Create ' . $create); $fs->dumpFile($create, implode(";\n", $queries) . ';'); // migrate.sql $dbalFromSchema = $this->dbal->getSchemaManager()->createSchema(); $this->generator->setFromSchema($dbalFromSchema); $queries = $this->generator->migrate(); $migrate = $this->application->getProject()->getPath('build sql migrate.sql'); if ($debug) { echo "- build migrate.sql" . PHP_EOL; } $output->writeln('Create ' . $migrate); $fs->dumpFile($migrate, implode(";\n", $queries) . (count($queries) ? ';' : '')); if (!$debug) { echo implode(";\n", $queries) . ';'; } if ($input->getOption('test') != true) { foreach ($queries as $query) { $this->dbal->executeQuery($query); } if ($input->getOption('commit') == true) { $this->dbal->commit(); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $schema = $this->application->getStorage()->getSchema(); echo json_encode($schema->asArray()); }