/**
  * Run migration
  *
  * @param string|null    $sTimestamp The time at which the migrations aims. Only migrations up to this point are being executed
  * @param oxIOutput|null $oOutput    Out handler for console output
  */
 public function run($sTimestamp = null, oxIOutput $oOutput = null)
 {
     if (null === $sTimestamp) {
         $sTimestamp = oxMigrationQuery::getCurrentTimestamp();
     }
     foreach ($this->getQueries() as $oQuery) {
         $oQuery->getTimestamp() < $sTimestamp ? $this->_goUp($oQuery, $oOutput) : $this->_goDown($oQuery, $oOutput);
     }
 }
 /**
  * Execute current command
  *
  * @param oxIOutput $oOutput
  */
 public function execute(oxIOutput $oOutput)
 {
     $sMigrationsDir = OX_BASE_PATH . 'migration' . DIRECTORY_SEPARATOR;
     $sTemplatePath = $this->_getTemplatePath();
     $sMigrationName = $this->_parseMigrationNameFromInput();
     if (!$sMigrationName) {
         do {
             $sMigrationName = $this->_askForMigrationNameInput();
         } while (!$sMigrationName);
     }
     $sMigrationFilePath = $sMigrationsDir . oxMigrationQuery::getCurrentTimestamp() . '_' . strtolower($sMigrationName) . '.php';
     /** @var Smarty $oSmarty */
     $oSmarty = oxRegistry::get('oxUtilsView')->getSmarty();
     $oSmarty->assign('sMigrationName', $sMigrationName);
     $sContent = $oSmarty->fetch($sTemplatePath);
     file_put_contents($sMigrationFilePath, $sContent);
 }
示例#3
0
 /**
  * Parse timestamp from user input
  *
  * @return string
  *
  * @throws oxConsoleException
  */
 protected function _parseTimestamp()
 {
     $oInput = $this->getInput();
     if ($sTimestamp = $oInput->getArgument(1)) {
         if (!oxMigrationQuery::isValidTimestamp($sTimestamp)) {
             if ($sTime = strtotime($sTimestamp)) {
                 $sTimestamp = date('YmdHis', $sTime);
             } else {
                 /** @var oxConsoleException $oEx */
                 $oEx = oxNew('oxConsoleException');
                 $oEx->setMessage('Invalid timestamp format, use YYYYMMDDhhmmss format');
                 throw $oEx;
             }
         }
         return $sTimestamp;
     }
     return oxMigrationQuery::getCurrentTimestamp();
 }