find() public méthode

public find ( )
 public function testMigrationByDiff()
 {
     $this->conn->query('DROP TABLE IF EXISTS users');
     $this->conn->query('DROP TABLE IF EXISTS test');
     $this->conn->query('CREATE TABLE users (account VARCHAR(128) UNIQUE)');
     if (!file_exists('tests/migrations_testing')) {
         mkdir('tests/migrations_testing');
     }
     $generator = new MigrationGenerator(Console::getInstance()->getLogger(), 'tests/migrations_testing');
     ok(class_exists('TestApp\\Model\\UserSchema', true));
     $finder = new SchemaFinder();
     $finder->find();
     list($class, $path) = $generator->generateWithDiff('DiffMigration', $this->getDriverType(), ["users" => new TestApp\Model\UserSchema()], '20120101');
     require_once $path;
     ok($class::getId());
     /*
     $userSchema = new TestApp\Model\UserSchema;
     $column = $userSchema->getColumn('account');
     */
     // run migration
     $runner = new MigrationRunner($this->logger, $this->getDriverType());
     $runner->resetMigrationId($this->conn, $this->queryDriver);
     $runner->load('tests/migrations_testing');
     // XXX: PHPUnit can't run this test in separated unit test since
     // there is a bug of serializing the global array, this assertion will get 5 instead of the expected 1.
     $scripts = $runner->loadMigrationScripts();
     $this->assertNotEmpty($scripts);
     // $this->assertCount(1, $scripts);
     // $this->expectOutputRegex('#DiffMigration_1325347200#');
     $runner->runUpgrade($this->conn, $this->queryDriver, [$class]);
     # echo file_get_contents($path);
     unlink($path);
     $this->conn->query('DROP TABLE IF EXISTS users');
 }
 public function execute($taskName)
 {
     $dsId = $this->getCurrentDataSourceId();
     $config = $this->getConfigLoader(true);
     $this->logger->info('Loading schema objects...');
     $finder = new SchemaFinder();
     $finder->setPaths($config->getSchemaPaths() ?: array());
     $finder->find();
     $generator = new MigrationGenerator($this->logger, 'db/migrations');
     $this->logger->info('Creating migration script from diff');
     $schemaMap = SchemaLoader::loadSchemaTableMap();
     list($class, $path) = $generator->generateWithDiff($taskName, $dsId, $schemaMap);
     $this->logger->info("Migration script is generated: {$path}");
 }
 public function execute($taskName)
 {
     $dsId = $this->getCurrentDataSourceId();
     $this->logger->info("Loading schema objects...");
     $finder = new SchemaFinder();
     $finder->paths = $this->config->getSchemaPaths() ?: array();
     $finder->find();
     $schemas = $finder->getSchemas();
     $this->logger->info('Found ' . count($schemas) == 0 . ' schemas');
     $generator = new MigrationGenerator(Console::getInstance()->getLogger(), 'db/migrations');
     $this->logger->info("Creating migration script from diff");
     list($class, $path) = $generator->generateWithDiff($taskName, $dsId, $schemas);
     $this->logger->info("Migration script is generated: {$path}");
 }
Exemple #4
0
 /**
  * Returns schema objects.
  *
  * @return array schema objects
  */
 public static function findSchemasByArguments(ConfigLoader $loader, $args, $logger = null)
 {
     if (count($args) && !file_exists($args[0])) {
         $classes = array();
         // it's classnames
         foreach ($args as $class) {
             // call class loader to load
             if (class_exists($class, true)) {
                 $classes[] = $class;
             } else {
                 if ($logger) {
                     $logger->warn("{$class} not found.");
                 } else {
                     echo ">>> {$class} not found.\n";
                 }
             }
         }
         return ClassUtils::schema_classes_to_objects($classes);
     } else {
         $finder = new SchemaFinder();
         if (count($args) && file_exists($args[0])) {
             $finder->paths = $args;
             foreach ($args as $file) {
                 if (is_file($file)) {
                     require_once $file;
                 }
             }
         } elseif ($paths = $loader->getSchemaPaths()) {
             $finder->setPaths($paths);
         }
         $finder->find();
         // load class from class map
         if ($classMap = $loader->getClassMap()) {
             foreach ($classMap as $file => $class) {
                 if (!is_numeric($file) && is_string($file)) {
                     require $file;
                 }
             }
         }
         return SchemaLoader::loadDeclaredSchemas();
     }
 }
 public function testMigrationByDiff()
 {
     $connectionManager = ConnectionManager::getInstance();
     $connectionManager->addDataSource('default', array('driver' => 'mysql', 'dsn' => @$_ENV['DB_MYSQL_DSN'], 'user' => @$_ENV['DB_MYSQL_USER'], 'pass' => @$_ENV['DB_MYSQL_PASS']));
     $pdo = $connectionManager->getConnection('default');
     $pdo->query('DROP TABLE IF EXISTS users');
     $pdo->query('DROP TABLE IF EXISTS test');
     $pdo->query('CREATE TABLE users (account VARCHAR(128) UNIQUE)');
     if (!file_exists('tests/migrations_testing')) {
         mkdir('tests/migrations_testing');
     }
     $generator = new MigrationGenerator(Console::getInstance()->getLogger(), 'tests/migrations_testing');
     ok(class_exists('TestApp\\Model\\UserSchema', true));
     $finder = new SchemaFinder();
     $finder->find();
     list($class, $path) = $generator->generateWithDiff('DiffMigration', 'default', [new TestApp\Model\UserSchema()], '20120101');
     require_once $path;
     ok($class::getId());
     /*
     $userSchema = new TestApp\Model\UserSchema;
     $column = $userSchema->getColumn('account');
     */
     /*
      */
     // run migration
     $runner = new MigrationRunner('default');
     $runner->resetMigrationId('default');
     $runner->load('tests/migrations_testing');
     // XXX: PHPUnit can't run this test in separated unit test since
     // there is a bug of serializing the global array, this assertion will get 5 instead of the expected 1.
     $scripts = $runner->getMigrationScripts();
     $this->assertNotEmpty($scripts);
     // $this->assertCount(1, $scripts);
     // $this->expectOutputRegex('#DiffMigration_1325347200#');
     $runner->runUpgrade([$class]);
     # echo file_get_contents($path);
     unlink($path);
     $pdo->query('DROP TABLE IF EXISTS users');
     $connectionManager->removeDataSource('default');
     $connectionManager->close('default');
 }
 public function initForBuild()
 {
     if (!$this->loaded) {
         throw new Exception('Can not initialize config: Config is not loaded.');
     }
     $this->loadDataSources();
     $this->loadBootstrap();
     if (!$this->loadExternalSchemaLoader()) {
         // Load default schema loader
         $paths = $this->getSchemaPaths();
         if (!empty($paths)) {
             $finder = new SchemaFinder($paths);
             $finder->find();
         }
     }
 }
Exemple #7
0
 /**
  * Returns schema objects.
  *
  * @return array schema objects
  */
 public static function findSchemasByArguments(ConfigLoader $loader, array $args, Logger $logger = null)
 {
     $classes = array_filter($args, function ($class) {
         return class_exists($class, true);
     });
     if (!empty($classes)) {
         return ClassUtils::schema_classes_to_objects(array_unique($classes));
     }
     $paths = array_filter($args, 'file_exists');
     if (empty($paths)) {
         $paths = $loader->getSchemaPaths();
     }
     if (!empty($paths)) {
         $finder = new SchemaFinder($paths);
         $finder->find();
     }
     // load class from class map
     if ($classMap = $loader->getClassMap()) {
         foreach ($classMap as $file => $class) {
             if (is_numeric($file)) {
                 continue;
             }
             require_once $file;
         }
     }
     return SchemaLoader::loadDeclaredSchemas();
 }