Exemplo n.º 1
0
 /**
  * Try to patch all older versions, in Patch\Version_X_Y_Z dirs
  *
  * @param BundleVersion $bundleVersion
  * @return Version
  */
 protected function patchOldVersions(BundleVersion $bundleVersion)
 {
     $reflection = new \ReflectionClass(get_called_class());
     $fileInfos = new \SplFileInfo($reflection->getFileName());
     $patchPath = $fileInfos->getPath() . DIRECTORY_SEPARATOR . 'Patch';
     // directory doesn't exists, no patch to call
     if (is_dir($patchPath) === false) {
         return $bundleVersion->getInstalledVersion();
     }
     // dirs like Update\Version_X_Y_Z
     $finderVersions = new Finder();
     $finderVersions->directories()->in($patchPath)->name('Version_*')->sortByName();
     $dirsVersions = array();
     foreach ($finderVersions as $dir) {
         $dirsVersions[] = str_replace('_', '.', substr($dir->getFilename(), 8));
     }
     usort($dirsVersions, array($this, 'compareDirVersion'));
     // now that we have dirs in right order, let's find patch files
     $return = $bundleVersion->getInstalledVersion();
     foreach ($dirsVersions as $dir) {
         $files = $this->findPatchsFiles($patchPath . DIRECTORY_SEPARATOR . 'Version_' . str_replace('.', '_', $dir));
         foreach ($files as $file) {
             $className = $reflection->getNamespaceName() . '\\Patch\\Version_' . str_replace('.', '_', $dir) . '\\' . $file->getBasename('.' . $file->getExtension());
             $this->callUpdate($className, $bundleVersion);
         }
         $return = new Version($dir);
     }
     return $return;
 }
 /**
  * Update bundle
  *
  * @param UpdateInterface $updater Use $this in your class
  * @param BundleVersion $bundleVersion
  * @param Version $version Update to this version
  * @return Version
  */
 protected function updateOneVersionOneMethod(UpdateInterface $updater, BundleVersion $bundleVersion, Version $version)
 {
     $methods = $this->findUpdateMethods($updater);
     $service = $this->container->get('versions.version');
     foreach ($methods as $method) {
         if ($service->compare($method, $version) == 1) {
             break;
         }
         if ($service->compare($method, $bundleVersion->getInstalledVersion()) == 1 && $service->compare($method, $bundleVersion->getVersion()) <= 0) {
             $this->{'update_' . str_replace('.', '_', $method)}();
         }
     }
     return $version;
 }