after() 공개 메소드

After callback to be implemented in subclasses.
public after ( array $event = [] ) : void
$event array Schema object properties.
리턴 void
 /**
  * Runs sql from _create() or _update()
  *
  * @param array $contents
  * @param string $event
  * @param CakeSchema $Schema
  * @return void
  */
 protected function _run($contents, $event, &$Schema)
 {
     if (empty($contents)) {
         $this->err(__d('cake_console', 'Sql could not be run'));
         return;
     }
     Configure::write('debug', 2);
     $db = ConnectionManager::getDataSource($this->Schema->connection);
     foreach ($contents as $table => $sql) {
         if (empty($sql)) {
             $this->out(__d('cake_console', '%s is up to date.', $table));
         } else {
             if ($this->_dry === true) {
                 $this->out(__d('cake_console', 'Dry run for %s :', $table));
                 $this->out($sql);
             } else {
                 if (!$Schema->before(array($event => $table))) {
                     return false;
                 }
                 $error = null;
                 try {
                     $db->execute($sql);
                 } catch (PDOException $e) {
                     $error = $table . ': ' . $e->getMessage();
                 }
                 $Schema->after(array($event => $table, 'errors' => $error));
                 if (!empty($error)) {
                     $this->err($error);
                 } else {
                     $this->out(__d('cake_console', '%s updated.', $table));
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * Runs sql from _createSchema()
  *
  * NOTE: adapted from the schema shell lib/Cake/Console/Command/SchemaShell.php
  *
  * @param array $contents
  * @param string $event
  * @param CakeSchema $Schema
  * @return string
  */
 protected function _runSchema($db, $contents, $event, &$Schema)
 {
     $out = '';
     if (empty($contents)) {
         $this->error('Sql could not be run');
         return false;
     }
     foreach ($contents as $table => $sql) {
         if (empty($sql)) {
             $out .= sprintf("%s is up to date.\n", $table);
         } else {
             if (!$Schema->before(array($event => $table))) {
                 return false;
             }
             $error = null;
             try {
                 $db->execute($sql);
             } catch (PDOException $e) {
                 $error = $table . ': ' . $e->getMessage();
             }
             $Schema->after(array($event => $table, 'errors' => $error));
             if (!empty($error)) {
                 $this->error($error);
                 return false;
             } else {
                 $out .= sprintf("%s updated\n", $table);
             }
         }
     }
     return $out;
 }