/** * 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; }
/** * Get bundle version informations * * @param string $bundle * @return BundleVersionEntity */ public function getVersion($bundle) { $doctrine = $this->container->get('doctrine'); $return = $doctrine->getRepository('VersionsBundle:BundleVersion')->findOneByName($bundle); if ($return === null) { $return = new BundleVersionEntity($bundle); } $bundle = $this->container->get('kernel')->getBundle($bundle); if ($bundle instanceof VersionnedBundle) { $return->setVersion($bundle->getVersion()); } 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; }
/** * Install all bundle in required order * * @param OutputInterface $output */ public function installAll($output = null) { foreach ($this->container->getParameter('versions.installOrder') as $bundle => $options) { try { $bundleVersion = $this->getBundleVersion($bundle); } catch (\Exception $e) { if ($bundle != 'VersionsBundle') { throw $e; } $bundleVersion = new BundleVersion('VersionsBundle'); } if ($bundleVersion->isInstalled() === false) { $this->install($bundle, $options['force'], $output); } } foreach ($this->container->get('versions.bundle')->getBundles() as $bundle) { $bundleVersion = $this->getBundleVersion($bundle->getName()); if ($bundleVersion->isInstalled() === false) { $this->install($bundle->getName(), false, $output); } } }