Exemplo n.º 1
0
 public function process()
 {
     $this->updatedVersions = array();
     $currentVersion = $this->getCurrentVersion();
     $this->log('debug', "start update process");
     if (true === $this->isLatestVersion($currentVersion)) {
         $this->log('debug', "You already have the latest version. No update available");
         throw new UpToDateException('You already have the latest version. No update available');
     }
     $index = array_search($currentVersion, self::$version);
     $this->connection->beginTransaction();
     $database = new Database($this->connection);
     $version = null;
     try {
         $size = count(self::$version);
         for ($i = ++$index; $i < $size; $i++) {
             $version = self::$version[$i];
             $this->updateToVersion($version, $database);
             $this->updatedVersions[] = $version;
         }
         $this->connection->commit();
         $this->log('debug', 'update successfully');
     } catch (\Exception $e) {
         $this->connection->rollBack();
         $this->log('error', sprintf('error during update process with message : %s', $e->getMessage()));
         $ex = new UpdateException($e->getMessage(), $e->getCode(), $e->getPrevious());
         $ex->setVersion($version);
         throw $ex;
     }
     $this->log('debug', 'end of update processing');
     return $this->updatedVersions;
 }
Exemplo n.º 2
0
 public function process()
 {
     $this->updatedVersions = array();
     $currentVersion = $this->getCurrentVersion();
     $this->log('debug', "start update process");
     if (true === $this->isLatestVersion($currentVersion)) {
         $this->log('debug', "You already have the latest version. No update available");
         throw new UpToDateException('You already have the latest version. No update available');
     }
     $index = array_search($currentVersion, $this->version);
     $this->connection->beginTransaction();
     $database = new Database($this->connection);
     $version = null;
     try {
         $size = count($this->version);
         for ($i = ++$index; $i < $size; $i++) {
             $version = $this->version[$i];
             $this->updateToVersion($version, $database);
             $this->updatedVersions[] = $version;
         }
         $currentVersion = Version::parse();
         $this->log('debug', sprintf('setting database configuration to %s', $currentVersion['version']));
         $updateConfigVersion = ['thelia_version' => $currentVersion['version'], 'thelia_major_version' => $currentVersion['major'], 'thelia_minus_version' => $currentVersion['minus'], 'thelia_release_version' => $currentVersion['release'], 'thelia_extra_version' => $currentVersion['extra']];
         foreach ($updateConfigVersion as $name => $value) {
             $stmt = $this->connection->prepare('SELECT * FROM `config` WHERE `name` = ?');
             $stmt->execute([$name]);
             if ($stmt->rowCount()) {
                 $stmt = $this->connection->prepare('UPDATE `config` SET `value` = ? WHERE `name` = ?');
                 $stmt->execute([$version, $value]);
             } else {
                 $stmt = $this->connection->prepare('INSERT INTO `config` (?) VALUES (?)');
                 $stmt->execute([$version, $value]);
             }
         }
         $this->connection->commit();
         $this->log('debug', 'update successfully');
     } catch (\Exception $e) {
         $this->connection->rollBack();
         $this->log('error', sprintf('error during update process with message : %s', $e->getMessage()));
         $ex = new UpdateException($e->getMessage(), $e->getCode(), $e->getPrevious());
         $ex->setVersion($version);
         throw $ex;
     }
     $this->log('debug', 'end of update processing');
     return $this->updatedVersions;
 }