public function testAdd_steps_complete() { $this->check_percentage(1, 0, 0); $this->object->add_steps(1)->add_steps_complete(1); $this->check_percentage(1, 1, 1); $this->object->add_steps(20)->add_steps_complete(20); $this->check_percentage(1, 21, 21); $this->object->add_steps(20); $this->check_percentage(round(21 / 41, 2), 41, 21); $this->object->add_steps_complete(40); $this->check_percentage(1, 41, 61); }
protected function apply_patches($from, $to, $post_process, Setup_Upgrade $upgrader, Application $app) { if (version::eq($from, $to)) { return true; } $list_patches = []; $upgrader->add_steps(1)->set_current_message($app->trans('Looking for patches')); $iterator = new DirectoryIterator($this->app['root.path'] . '/lib/classes/patch/'); foreach ($iterator as $fileinfo) { if (!$fileinfo->isDot()) { if (substr($fileinfo->getFilename(), 0, 1) == '.') { continue; } $versions = array_reverse(explode('.', $fileinfo->getFilename())); $classname = 'patch_' . array_pop($versions); $patch = new $classname(); if (!in_array($this->get_base_type(), $patch->concern())) { continue; } if (!!$post_process !== !!$patch->require_all_upgrades()) { continue; } // if patch is older than current install if (version::lte($patch->get_release(), $from)) { continue; } // if patch is new than current target if (version::gt($patch->get_release(), $to)) { continue; } $n = 0; do { $key = $patch->get_release() . '.' . $n; $n++; } while (isset($list_patches[$key])); $list_patches[$key] = $patch; } } $upgrader->add_steps_complete(1)->add_steps(count($list_patches))->set_current_message($app->trans('Applying patches on %databox_name%', ['%databox_name%' => $this->get_dbname()])); uasort($list_patches, function (\patchInterface $patch1, \patchInterface $patch2) { return version::lt($patch1->get_release(), $patch2->get_release()) ? -1 : 1; }); $success = true; foreach ($list_patches as $patch) { // Gets doctrine migrations required for current patch foreach ($patch->getDoctrineMigrations() as $doctrineVersion) { $version = $app['doctrine-migration.configuration']->getVersion($doctrineVersion); // Skip if already migrated if ($version->isMigrated()) { continue; } $migration = $version->getMigration(); // Inject entity manager $migration->setEntityManager($app['EM']); // Execute migration if not marked as migrated and not already applied by an older patch if (!$migration->isAlreadyApplied()) { $version->execute('up'); continue; } // Or mark it as migrated $version->markMigrated(); } if (false === $patch->apply($this, $app)) { $success = false; } $upgrader->add_steps_complete(1); } return $success; }
public function forceUpgrade(Setup_Upgrade $upgrader, Application $app) { $from_version = $this->get_version(); $upgrader->add_steps(7 + count($this->get_databoxes())); /** * Step 1 */ $upgrader->set_current_message($this->app->trans('Flushing cache')); $app['phraseanet.cache-service']->flushAll(); $upgrader->add_steps_complete(1); $upgrader->set_current_message($this->app->trans('Creating new tables')); // Executes stuff before applying patches $app['phraseanet.pre-schema-upgrader']->apply($app); $upgrader->add_steps_complete(1); /** * Step 2 */ $upgrader->set_current_message($this->app->trans('Purging directories')); $finder = new Finder(); $finder->in([$this->app['root.path'] . '/tmp/cache_minify/', $this->app['root.path'] . '/tmp/cache_twig/', $this->app['root.path'] . '/tmp/translations/', $this->app['root.path'] . '/tmp/cache/profiler/', $this->app['root.path'] . '/tmp/doctrine/', $this->app['root.path'] . '/tmp/serializer/'])->depth(0)->ignoreVCS(true)->ignoreDotFiles(true); foreach ($finder as $file) { $app['filesystem']->remove($file); } $upgrader->add_steps_complete(1); /** * Step 5 */ $upgrader->set_current_message($this->app->trans('Copying files')); foreach (['config/custom_files/' => 'www/custom/', 'config/minilogos/' => 'www/custom/minilogos/', 'config/stamp/' => 'www/custom/stamp/', 'config/status/' => 'www/custom/status/', 'config/wm/' => 'www/custom/wm/'] as $source => $target) { $app['filesystem']->mirror($this->app['root.path'] . '/' . $source, $this->app['root.path'] . '/' . $target); } $upgrader->add_steps_complete(1); $advices = []; /** * Step 6 */ $upgrader->set_current_message($this->app->trans('Upgrading appbox')); $advices = $this->upgradeDB(true, $upgrader, $app); $upgrader->add_steps_complete(1); /** * Step 7 */ foreach ($this->get_databoxes() as $s) { $upgrader->set_current_message($this->app->trans('Upgrading %databox_name%', ['%databox_name%' => $s->get_label($this->app['locale'])])); $advices = array_merge($advices, $s->upgradeDB(true, $upgrader, $app)); $upgrader->add_steps_complete(1); } /** * Step 8 */ $upgrader->set_current_message($this->app->trans('Post upgrade')); $this->post_upgrade($upgrader, $app); $upgrader->add_steps_complete(1); /** * Step 9 */ $upgrader->set_current_message($this->app->trans('Flushing cache')); $app['phraseanet.cache-service']->flushAll(); if ($app['EM']->getConnection()->getDatabasePlatform()->supportsAlterTable()) { $tool = new SchemaTool($app['EM']); $metas = $app['EM']->getMetadataFactory()->getAllMetadata(); $tool->updateSchema($metas, true); } $upgrader->add_steps_complete(1); if (version::lt($from_version, '3.1')) { $upgrader->addRecommendation($app->trans('Your install requires data migration, please execute the following command'), 'bin/setup system:upgrade-datas --from=3.1'); } elseif (version::lt($from_version, '3.5')) { $upgrader->addRecommendation($app->trans('Your install requires data migration, please execute the following command'), 'bin/setup system:upgrade-datas --from=3.5'); } if (version::lt($from_version, '3.7')) { $upgrader->addRecommendation($app->trans('Your install might need to re-read technical datas'), 'bin/console records:rescan-technical-datas'); $upgrader->addRecommendation($app->trans('Your install might need to build some sub-definitions'), 'bin/console records:build-missing-subdefs'); } return $advices; }