Esempio n. 1
0
 /**
  * Run migration
  *
  * @param string $direction, up or down direction of migration process
  * @return boolean Status of the process
  */
 public function run($direction)
 {
     if (!in_array($direction, array('up', 'down'))) {
         throw new MigrationException($this, sprintf(__d('migrations', 'Migration direction (%s) is not one of valid directions.'), $direction), E_USER_NOTICE);
     }
     $this->direction = $direction;
     $null = null;
     $this->db = ConnectionManager::getDataSource($this->connection);
     $this->db->cacheSources = false;
     $this->db->begin($null);
     $this->Schema = new CakeSchema(array('connection' => $this->connection));
     try {
         $this->_invokeCallbacks('beforeMigration', $direction);
         $result = $this->_run();
         $this->_clearCache();
         $this->_invokeCallbacks('afterMigration', $direction);
         if (!$result) {
             return false;
         }
     } catch (Exception $e) {
         $this->db->rollback($null);
         throw $e;
     }
     return $this->db->commit($null);
 }
Esempio n. 2
0
 /**
  * Run
  *
  * @return void
  */
 public function run()
 {
     $null = null;
     $this->db = ConnectionManager::getDataSource($this->connection);
     $this->db->cacheSources = false;
     $this->db->begin($null);
     if (!isset($this->args[0]) || !in_array($this->args[0], array('insert', 'remove'))) {
         $this->out(__d('SoftDelete', 'Invalid option'));
         return $this->_displayHelp(null);
     }
     if (!isset($this->args[1])) {
         $this->out(__d('SoftDelete', 'You missed field name.'));
         return $this->_displayHelp(null);
     }
     try {
         $this->_run($this->args[0], $this->args[1]);
         $this->_clearCache();
     } catch (Exception $e) {
         $this->db->rollback($null);
         throw $e;
     }
     $this->out(__d('SoftDelete', 'All tables are updated.'));
     $this->out('');
     return $this->db->commit($null);
 }
Esempio n. 3
0
 /**
  * Rollback a transaction
  *
  * @param model $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  * @access public
  */
 function rollback(&$model)
 {
     if (parent::rollback($model) && $this->execute($this->_commands['rollback'])) {
         $this->_transactionStarted = false;
         return true;
     }
     return false;
 }