Exemple #1
0
 /**
  * Entityを生成します。
  * 
  */
 public function execute()
 {
     // --force フラグのチェック
     if (isset($this->_argv) && in_array('--force', $this->_argv)) {
         $this->forceUpdate = TRUE;
     }
     $config = $this->dataSource->getDataSourceConfig();
     foreach ($config as $name => $dsn) {
         $this->generate($name, $this->convertDSN($dsn));
     }
 }
Exemple #2
0
 /**
  * Migrationを実行します。
  * 
  */
 public function execute()
 {
     $config = $this->dataSource->getDataSourceConfig();
     foreach ($config as $name => $dsn) {
         print "** start migration for {$name}. \n";
         $conn = $this->dataSource->getConnection($name);
         $this->pdo = $conn->getDB();
         // DBのmigratoin番号を取得
         $remote_num = $this->getRemoteNum();
         print "remote: {$remote_num}\n";
         // ローカルのmigration番号を取得
         $local = new Teeple_Migration_Local(dirname(BASE_DIR) . "/migration/" . $name);
         $local_num = $local->getMaxNum();
         print "local: {$local_num}\n";
         while ($remote_num < $local_num) {
             $remote_num++;
             print "apply {$remote_num}..";
             $ddl = $local->getContent($remote_num);
             $ddllist = explode(';', $ddl);
             try {
                 foreach ($ddllist as $q) {
                     $q = trim($q);
                     if (strlen($q)) {
                         $stmt = $this->pdo->prepare($q);
                         $stmt->execute();
                     }
                 }
             } catch (Exception $e) {
                 print "fail.\n";
                 print $e->getMessage();
                 return;
             }
             $this->pdo->beginTransaction();
             $stmt = $this->pdo->prepare("UPDATE " . self::TABLE_NAME . " SET version = {$remote_num}");
             $stmt->execute();
             $this->pdo->commit();
             print "success.\n";
         }
         print "** finish migration for {$name}. \n";
     }
     // --entityがセットされていたらEntityも更新する
     if (isset($this->_argv) && in_array('--entity', $this->_argv)) {
         print "\n*** update entity class.\n";
         $entityGenerator = Teeple_Container::getInstance()->getComponent('Teeple_EntityGenerator');
         $entityGenerator->_argv = array('--force');
         $entityGenerator->execute();
     }
 }