/**
  * Determines what action should be performed and takes that action.
  *
  * @uses MpmDownController::displayHelp()
  * @uses MpmCommandLineWriter::getInstance()
  * @uses MpmCommandLineWriter::writeHeader()
  * @uses MpmMigrationHelper::getListOfMigrations()
  * @uses MpmMigrationHelper::getCurrentMigrationNumber()
  * @uses MpmMigrationHelper::getTimestampFromId()
  * @uses MpmMigrationHelper::runMigration()
  * @uses MpmMigrationHelper::setCurrentMigration()
  * 
  * @return void
  */
 public function doAction($quiet = false)
 {
     // write the header
     $clw = MpmCommandLineWriter::getInstance();
     $skip_headers = false;
     if (!empty($this->arguments[2])) {
         $skip_headers = true;
     }
     if (!$quiet && !$skip_headers) {
         $clw->writeHeader();
     }
     // correct number of command line arguments?
     if (count($this->arguments) == 0) {
         return $this->displayHelp();
     }
     // ID of the migration we are going down to
     $down_to = $this->arguments[0];
     if (!is_numeric($down_to)) {
         return $this->displayHelp();
     }
     if ($down_to == 0) {
         $down_to = -1;
     }
     // are we forcing this?
     $forced = false;
     if (isset($this->arguments[1]) && strcasecmp($this->arguments[1], '--force') == 0) {
         $forced = true;
     }
     // get list of migrations and the current migration number
     $list = MpmMigrationHelper::getListOfMigrations($down_to, 'down');
     $total = count($list);
     $current = MpmMigrationHelper::getCurrentMigrationNumber();
     if ($down_to == '-1') {
         if (!$quiet) {
             echo "Removing all migrations... ";
         }
         $down_to = 0;
     } else {
         if (!$quiet) {
             echo "Migrating to " . MpmMigrationHelper::getTimestampFromId($down_to) . ' (ID ' . $down_to . ')... ';
         }
     }
     foreach ($list as $id => $obj) {
         MpmMigrationHelper::runMigration($obj, 'down', $forced);
     }
     MpmMigrationHelper::setCurrentMigration($down_to);
     if (!$skip_headers && !$quiet) {
         echo "\n";
         $clw->writeFooter();
     }
 }
 /**
  * Determines what action should be performed and takes that action.
  *
  * @uses MpmUpController::displayHelp()
  * @uses MpmCommandLineWriter::getInstance()
  * @uses MpmCommandLineWriter::writeHeader()
  * @uses MpmCommandLineWriter::writeFooter()
  * @uses MpmMigrationHelper::getListOfMigrations()
  * @uses MpmMigrationHelper::getTimestampFromId()
  * @uses MpmMigrationHelper::runMigration()
  * @uses MpmMigrationHelper::setCurrentMigration
  * 
  * @param bool $quiet suppresses certain text when true
  *
  * @return void
  */
 public function doAction($quiet = false)
 {
     $clw = MpmCommandLineWriter::getInstance();
     $skip_headers = false;
     if (!empty($this->arguments[2])) {
         $skip_headers = true;
     }
     if (!$quiet && !$skip_headers) {
         $clw->writeHeader();
     }
     if (count($this->arguments) == 0) {
         return $this->displayHelp();
     }
     $up_to = $this->arguments[0];
     if (!is_numeric($up_to)) {
         return $this->displayHelp();
     }
     // are we forcing this?
     $forced = false;
     if (isset($this->arguments[1]) && strcasecmp($this->arguments[1], '--force') == 0) {
         $forced = true;
     }
     // what migrations need to be done?
     $list = MpmMigrationHelper::getListOfMigrations($up_to);
     if (count($list) == 0) {
         if (!$quiet) {
             echo "\nAll needed migrations have already been run or no migrations exist.";
             if (!$skip_headers) {
                 $clw->writeFooter();
             }
             return;
         } else {
             return;
         }
     }
     $to = MpmMigrationHelper::getTimestampFromId($up_to);
     if (!$quiet) {
         echo "\nMigrating to " . $to . ' (ID ' . $up_to . ')... ';
     }
     foreach ($list as $id => $obj) {
         MpmMigrationHelper::runMigration($obj, 'up', $forced);
     }
     MpmMigrationHelper::setCurrentMigration($up_to);
     if (!$quiet && !$skip_headers) {
         $clw->writeFooter();
     }
 }
 /**
  * Determines what action should be performed and takes that action.
  *
  * @uses MpmRunController::displayHelp()
  * @uses MpmCommandLineWriter::getInstance()
  * @uses MpmCommandLineWriter::addText()
  * @uses MpmCommandLineWriter::write()
  * @uses MpmCommandLineWriter::writeHeader()
  * @uses MpmCommandLineWriter::writeFooter()
  * @uses MpmMigrationHelper::doesMigrationExist() 
  * @uses MpmMigrationHelper::getMigrationObject()
  * @uses MpmMigrationHelper::runMigration()
  *
  * @return void
  */
 public function doAction()
 {
     // make sure system is init'ed
     MpmDbHelper::test();
     if (count($this->arguments) != 2) {
         $obj = MpmCommandLineWriter::getInstance();
         $obj->addText('ERROR: You must provide two arguments with this command.');
         $obj->addText(' ');
         $this->displayHelp();
         return;
     }
     // are we running the up or the down?
     $type = strtolower($this->arguments[0]);
     // what number do we want to run?
     $num = $this->arguments[1];
     if (!is_numeric($num)) {
         $obj = MpmCommandLineWriter::getInstance();
         $obj->addText('ERROR: Migration number must be numeric.');
         $obj->addText(' ');
         $this->displayHelp();
         return;
     }
     if ($type != 'up' && $type != 'down') {
         $obj = MpmCommandLineWriter::getInstance();
         $obj->addText('ERROR: Method must be either up or down.');
         $obj->addText(' ');
         $this->displayHelp();
         return;
     }
     // does this migration number exist?
     if (!MpmMigrationHelper::doesMigrationExist($num)) {
         $obj = MpmCommandLineWriter::getInstance();
         $obj->addText('ERROR: Migration ' . $num . ' does not exist.');
         $obj->write();
         return;
     }
     $row = MpmMigrationHelper::getMigrationObject($num);
     $obj = MpmCommandLineWriter::getInstance();
     $obj->writeHeader();
     MpmMigrationHelper::runMigration($row, $type);
     echo "\n";
     $obj->writeFooter();
 }
Exemplo n.º 4
0
 /**
  * Determines what action should be performed and takes that action.
  *
  * @uses MpmUpController::displayHelp()
  * @uses MpmCommandLineWriter::getInstance()
  * @uses MpmCommandLineWriter::writeHeader()
  * @uses MpmCommandLineWriter::writeFooter()
  * @uses MpmMigrationHelper::getListOfMigrations()
  * @uses MpmMigrationHelper::getTimestampFromId()
  * @uses MpmMigrationHelper::runMigration()
  * @uses MpmMigrationHelper::setCurrentMigration
  *
  * @param bool $quiet supresses certain text when true
  *
  * @return void
  */
 public function doAction($quiet = false)
 {
     $clw = MpmCommandLineWriter::getInstance();
     if (!$quiet) {
         $clw->writeHeader();
     }
     if (count($this->arguments) == 0) {
         return $this->displayHelp();
     }
     $up_to = $this->arguments[0];
     if (!is_numeric($up_to)) {
         return $this->displayHelp();
     }
     // parse other optional arguments
     list($forced, $dryrun) = $this->parse_options($this->arguments);
     // what migrations need to be done?
     $list = MpmMigrationHelper::getListOfMigrations($up_to);
     if (count($list) == 0) {
         if (!$quiet) {
             echo 'All needed migrations have already been run or no migrations exist.';
             $clw->writeFooter();
             exit;
         } else {
             return;
         }
     }
     $to = MpmMigrationHelper::getTimestampFromId($up_to);
     if (!$quiet) {
         echo "Migrating to " . $to . ' (ID ' . $up_to . ')... ';
     }
     foreach ($list as $id => $obj) {
         MpmMigrationHelper::runMigration($obj, 'up', array('forced' => $forced, 'dryrun' => $dryrun));
     }
     MpmMigrationHelper::setCurrentMigration($up_to, $dryrun);
     if (!$quiet) {
         echo "\n";
         $clw->writeFooter();
     }
 }
 /**
  * Determines what action should be performed and takes that action.
  *
  * @uses MpmDownController::displayHelp()
  * @uses MpmCommandLineWriter::getInstance()
  * @uses MpmCommandLineWriter::writeHeader()
  * @uses MpmMigrationHelper::getListOfMigrations()
  * @uses MpmMigrationHelper::getCurrentMigrationNumber()
  * @uses MpmMigrationHelper::getTimestampFromId()
  * @uses MpmMigrationHelper::runMigration()
  * @uses MpmMigrationHelper::setCurrentMigration()
  * 
  * @return void
  */
 public function doAction()
 {
     // write the header
     $clw = MpmCommandLineWriter::getInstance();
     $clw->writeHeader();
     // correct number of command line arguments?
     if (count($this->arguments) == 0) {
         return $this->displayHelp();
     }
     // ID of the migration we are going down to
     $down_to = $this->arguments[0];
     if (!is_numeric($down_to)) {
         return $this->displayHelp();
     }
     if ($down_to == 0) {
         $down_to = -1;
     }
     // parse other optional arguments
     list($forced, $dryrun) = $this->parse_options($this->arguments);
     // get list of migrations and the current migration number
     $list = MpmMigrationHelper::getListOfMigrations($down_to, 'down');
     $total = count($list);
     $current = MpmMigrationHelper::getCurrentMigrationNumber();
     if ($down_to == '-1') {
         echo "Removing all migrations... ";
         $down_to = 0;
     } else {
         echo "Migrating to " . MpmMigrationHelper::getTimestampFromId($down_to) . ' (ID ' . $down_to . ')... ';
     }
     foreach ($list as $id => $obj) {
         MpmMigrationHelper::runMigration($obj, 'down', array('forced' => $forced, 'dryrun' => $dryrun));
     }
     MpmMigrationHelper::setCurrentMigration($down_to, $dryrun);
     echo "\n";
     $clw->writeFooter();
 }