示例#1
0
 /**
  * Executes all deltas not executed before
  *
  * @see \Mage\Task\AbstractTask::run()
  */
 public function run()
 {
     // Get full path of last executed delta or null if none
     $deployOriginRoot = getcwd() . DIRECTORY_SEPARATOR . $this->config->deployment("from");
     $lastDeltaFile = $deployOriginRoot . DIRECTORY_SEPARATOR . ".mage" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "environment" . DIRECTORY_SEPARATOR . "LastDelta" . DIRECTORY_SEPARATOR . $this->getConfig()->getEnvironment();
     if (!file_exists($lastDeltaFile)) {
         throw new SkipException('Error fetching path to last delta file. The file most exist. (at least empty). Path: ' . $lastDeltaFile);
     }
     // MySQL with PDO_MYSQL
     $parametersYMLFile = $deployOriginRoot . DIRECTORY_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "parameters.yml";
     $parametersYML = Yaml::parse($parametersYMLFile);
     $mysql_host = $parametersYML['parameters']["database_host"];
     $mysql_user = $parametersYML['parameters']["database_user"];
     $mysql_password = $parametersYML['parameters']["database_password"];
     $db = new \PDO("mysql:host={$mysql_host};", $mysql_user, $mysql_password);
     // Get path to root folder with delta's
     $deltaRootPath = $this->getParameter('delta-root');
     if (!$deltaRootPath || !is_dir($deltaRootPath)) {
         throw new SkipException('Param deltaRootPath is mandatory and most exist.');
     }
     $lastDelta = file_get_contents($lastDeltaFile);
     // Iterate recursively over all files on delta's folder
     $deltas = preg_grep('/^.*\\.sql/', $this->getDirContents($deltaRootPath));
     $exec = false;
     $noErrors = true;
     $stopOnError = $this->getParameter('stop-on-error', true);
     foreach ($deltas as $delta) {
         // Check for Errors
         if (!$noErrors && $stopOnError) {
             break;
         }
         $nameMatch = strcmp($delta, $lastDelta) == 0;
         $logDelta = 'Checking delta ' . $delta . ' against last delta (' . $lastDelta . '): ' . $nameMatch;
         Console::log($logDelta);
         // Execute or skip
         if ($exec) {
             if (!$this->executeSQL($delta, $db, $lastDeltaFile)) {
                 $noErrors = false;
             }
         } else {
             if (strcmp($delta, $lastDelta) == 0) {
                 $exec = true;
             }
         }
     }
     if (!$exec) {
         foreach ($deltas as $delta) {
             // Check for Errors
             if (!$noErrors && $stopOnError) {
                 break;
             }
             if (!$this->executeSQL($delta, $db, $lastDeltaFile)) {
                 $noErrors = false;
             }
         }
     }
     return $noErrors;
 }
示例#2
0
 public function parseConfigText($input)
 {
     return Yaml::parse($input);
 }