Esempio n. 1
0
 public function execute()
 {
     $args = func_get_args();
     $logger = $this->getLogger();
     $config = $this->getConfigLoader(true);
     $this->logger->debug('Finding schemas...');
     $schemas = SchemaUtils::findSchemasByArguments($config, $args, $logger);
     $generator = new SchemaGenerator($config);
     if ($this->options->force) {
         $generator->setForceUpdate(true);
     }
     $classMap = array();
     foreach ($schemas as $schema) {
         if ($this->logger->isDebug()) {
             $this->logger->debug('Checking ' . get_class($schema));
         }
         $generated = $generator->generateSchemaFiles($schema);
         if (!empty($generated)) {
             if ($this->logger->isDebug()) {
                 // $filepath = str_replace(getcwd().'/', '', $schema->getClassFileName());
                 $this->logger->debug('Updated ' . get_class($schema));
                 foreach ($generated as $class => $file) {
                     $this->logger->debug(' - Updated ' . $file);
                 }
             } else {
                 $this->logger->info('Updated ' . get_class($schema));
             }
             $classMap += $generated;
         }
     }
 }
Esempio n. 2
0
 public function execute()
 {
     $logger = $this->getLogger();
     $config = $this->getConfigLoader();
     $this->logger->debug('Finding schemas...');
     $actionLogger = new ActionLogger(STDERR);
     $schemas = SchemaUtils::findSchemasByArguments($this->getConfigLoader(), func_get_args(), $this->logger);
     foreach ($schemas as $schema) {
         if ($this->logger->isVerbose()) {
             $actionLog = $actionLogger->newAction(get_class($schema), get_class($schema));
             $actionLog->setActionColumnWidth(50);
         } elseif ($this->logger->isDebug()) {
             $filepath = str_replace(getcwd() . '/', '', $schema->getClassFileName());
             $actionLog = $actionLogger->newAction($filepath, get_class($schema));
             $actionLog->setActionColumnWidth(50);
         } else {
             $actionLog = $actionLogger->newAction($schema->getShortClassName(), get_class($schema));
         }
         $actionLog->setStatus('checking');
         if ($schema->requireProxyFileUpdate()) {
             $actionLog->setStatus('modified', 'yellow');
         } else {
             $actionLog->setStatus('up-to-date');
         }
         $actionLog->finalize();
     }
 }
Esempio n. 3
0
 public function execute()
 {
     $logger = $this->getLogger();
     $config = $this->getConfigLoader();
     $this->logger->debug('Finding schemas...');
     $classes = $this->findSchemasByArguments(func_get_args());
     SchemaUtils::printSchemaClasses($classes, $this->logger);
     $this->logger->debug("Initializing schema generator...");
     $generator = new SchemaGenerator($config, $this->logger);
     if ($this->options->force) {
         $generator->setForceUpdate(true);
     }
     $classMap = $generator->generate($classes, $this->options->force);
     /*
     foreach( $classMap as $class => $file ) {
         $path = $file;
         if ( strpos( $path , getcwd() ) === 0 ) {
             $path = substr( $path , strlen(getcwd()) + 1 );
         }
         $logger->info($path);
         // $logger->info(sprintf("%-32s",ltrim($class,'\\')) . " => $path",1);
     }
     */
     $logger->info('Done');
 }
Esempio n. 4
0
 public function execute()
 {
     $options = $this->options;
     $logger = $this->logger;
     $configLoader = $this->getConfigLoader(true);
     $id = $this->getCurrentDataSourceId();
     $logger->debug('Finding schema classes...');
     $schemas = SchemaUtils::findSchemasByArguments($configLoader, func_get_args(), $this->logger);
     $logger->debug('Initialize schema builder...');
     if ($output = $this->options->output) {
         $dataSourceConfig = $configLoader->getDataSource($id);
         $driverType = $dataSourceConfig['driver'];
         switch ($driverType) {
             case 'sqlite':
                 $driver = new SQLiteDriver();
                 break;
             case 'mysql':
                 $driver = new MySQLDriver();
                 break;
             case 'pgsql':
                 $driver = new PgSQLDriver();
                 break;
             default:
                 throw new Exception("Unsupported driver type: {$driverType}");
                 break;
         }
         $sqlBuilder = SqlBuilder::create($driver, ['rebuild' => $options->rebuild, 'clean' => $options->clean]);
         $fp = fopen($output, 'w');
         foreach ($schemas as $schema) {
             $sqls = $sqlBuilder->buildTable($schema);
             fwrite($fp, implode("\n", $sqls));
             $sqls = $sqlBuilder->buildIndex($schema);
             fwrite($fp, implode("\n", $sqls));
             $sqls = $sqlBuilder->buildForeignKeys($schema);
             fwrite($fp, implode("\n", $sqls));
         }
         fclose($fp);
         $this->logger->warn('Warning: seeding is not supported when using --output option.');
     } else {
         $connectionManager = ConnectionManager::getInstance();
         $conn = $connectionManager->getConnection($id);
         $driver = $connectionManager->getQueryDriver($id);
         $sqlBuilder = SqlBuilder::create($driver, ['rebuild' => $options->rebuild, 'clean' => $options->clean]);
         $bootstrap = new Bootstrap($conn, $sqlBuilder, $this->logger);
         $bootstrap->build($schemas);
         if ($this->options->basedata) {
             $bootstrap->seed($schemas, $configLoader);
         }
         $time = time();
         $logger->info("Setting migration timestamp to {$time}");
         $metadata = new Metadata($conn, $driver);
         // update migration timestamp
         $metadata['migration'] = $time;
         $logger->info($logger->formatter->format('Done. ' . count($schemas) . " schema tables were generated into data source '{$id}'.", 'green'));
     }
 }
Esempio n. 5
0
 public function execute()
 {
     $options = $this->options;
     $logger = $this->logger;
     $classes = $this->findSchemasByArguments(func_get_args());
     SchemaUtils::printSchemaClasses($classes, $this->logger);
     $collection = new SchemaCollection($classes);
     $collection = $collection->evaluate();
     $seedBuilder = new SeedBuilder($this->getConfigLoader(), $this->logger);
     $seedBuilder->build($collection);
     $this->logger->info('Done');
 }
 public function __construct(BaseDriver $driver, PDO $connection)
 {
     $this->driver = $driver;
     $this->connection = $connection;
     $c = ServiceContainer::getInstance();
     $this->config = $c['config_loader'];
     // pre-initialize all schema objects and expand template schema
     $this->schemas = SchemaUtils::findSchemasByConfigLoader($this->config, $c['logger']);
     $this->schemas = SchemaUtils::filterBuildableSchemas($this->schemas);
     // map table names to declare schema objects
     foreach ($this->schemas as $schema) {
         $this->schemaMap[$schema->getTable()] = $schema;
     }
 }
Esempio n. 7
0
 public function execute()
 {
     $logger = $this->getLogger();
     $config = $this->getConfigLoader();
     $this->logger->debug('Finding schemas...');
     $schemas = SchemaUtils::findSchemasByArguments($this->getConfigLoader(), func_get_args(), $this->logger);
     foreach ($schemas as $schema) {
         $this->logger->info('Cleaning schema ' . get_class($schema));
         $paths = array();
         $paths[] = $schema->getRelatedClassPath($schema->getBaseModelClass());
         $paths[] = $schema->getRelatedClassPath($schema->getBaseCollectionClass());
         $paths[] = $schema->getRelatedClassPath($schema->getSchemaProxyClass());
         foreach ($paths as $path) {
             $this->logger->info(' - Deleting ' . $path);
             if (file_exists($path)) {
                 unlink($path);
             }
         }
     }
     /*
             $generator = new SchemaGenerator($config, $this->logger);
             if ( $this->options->force ) {
        $generator->setForceUpdate(true);
             }
             $classMap = $generator->generate($classes);
     */
     /*
     foreach( $classMap as $class => $file ) {
         $path = $file;
         if ( strpos( $path , getcwd() ) === 0 ) {
             $path = substr( $path , strlen(getcwd()) + 1 );
         }
         $logger->info($path);
         // $logger->info(sprintf("%-32s",ltrim($class,'\\')) . " => $path",1);
     }
     */
     $logger->info('Done');
 }
Esempio n. 8
0
 /**
  * Returns schema objects
  *
  * @return array Schema objects
  */
 public function getSchemas()
 {
     return SchemaUtils::expandSchemaClasses(ClassUtils::get_declared_schema_classes());
 }
Esempio n. 9
0
 public function findSchemasByArguments(array $arguments)
 {
     return SchemaUtils::findSchemasByArguments($this->getConfigLoader(), $arguments, $this->logger);
 }