public function testGet_status() { $datas = $this->object->get_status(); $this->assertTrue(is_array($datas)); $this->assertArrayHasKey('active', $datas); $this->assertArrayHasKey('percentage', $datas); $this->assertArrayHasKey('total_steps', $datas); $this->assertArrayHasKey('completed_steps', $datas); $this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('last_update', $datas); $this->assertDateAtom($datas['last_update']); }
/** * Get Databases control panel * * @param $app Application $app * @param $request Request $request * @return Response */ public function getDatabases(Application $app, Request $request) { $sbasIds = array_merge(array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_sbas(['bas_manage'])), array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_sbas(['bas_modify_struct']))); $sbas = []; foreach ($sbasIds as $sbasId) { $sbas[$sbasId] = ['version' => 'unknown', 'image' => '/skins/icons/db-remove.png', 'server_info' => '', 'name' => $app->trans('Unreachable server')]; try { $databox = $app['phraseanet.appbox']->get_databox($sbasId); $sbas[$sbasId] = ['version' => $databox->get_version(), 'image' => '/skins/icons/foldph20close_0.gif', 'server_info' => $databox->get_connection()->getWrappedConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION), 'name' => \phrasea::sbas_labels($sbasId, $app)]; } catch (\Exception $e) { } } switch ($errorMsg = $request->query->get('error')) { case 'scheduler-started': $errorMsg = $app->trans('Veuillez arreter le planificateur avant la mise a jour'); break; case 'already-started': $errorMsg = $app->trans('The upgrade is already started'); break; case 'unknow': $errorMsg = $app->trans('An error occured'); break; case 'bad-email': $errorMsg = $app->trans('Please fix the database before starting'); break; case 'special-chars': $errorMsg = $app->trans('Database name can not contains special characters'); break; case 'base-failed': $errorMsg = $app->trans('Base could not be created'); break; case 'database-failed': $errorMsg = $app->trans('Database does not exists or can not be accessed'); break; case 'no-empty': $errorMsg = $app->trans('Database can not be empty'); break; case 'mount-failed': $errorMsg = $app->trans('Database could not be mounted'); break; } $upgrader = new \Setup_Upgrade($app); return $app['twig']->render('admin/databases.html.twig', ['files' => new \DirectoryIterator($app['root.path'] . '/lib/conf.d/data_templates'), 'sbas' => $sbas, 'error_msg' => $errorMsg, 'recommendations' => $upgrader->getRecommendations(), 'advices' => $request->query->get('advices', []), 'reloadTree' => (bool) $request->query->get('reload-tree')]); }
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; }
protected function post_upgrade(Setup_Upgrade $upgrader, Application $app) { $upgrader->add_steps(1 + count($this->get_databoxes())); $this->apply_patches($this->get_version(), $app['phraseanet.version']->getNumber(), true, $upgrader, $app); $this->setVersion($app['phraseanet.version']); $upgrader->add_steps_complete(1); foreach ($this->get_databoxes() as $databox) { $databox->apply_patches($databox->get_version(), $app['phraseanet.version']->getNumber(), true, $upgrader, $app); $databox->setVersion($app['phraseanet.version']); $upgrader->add_steps_complete(1); } return $this; }
public function forceUpgrade(Setup_Upgrade $upgrader, Application $app) { $from_version = $this->get_version(); $app['phraseanet.cache-service']->flushAll(); // Executes stuff before applying patches $app['phraseanet.pre-schema-upgrader']->apply($app); $finder = new Finder(); $in = []; $path = $app['cache.path']; $in[] = $path . '/minify/'; $in[] = $path . '/twig/'; $in[] = $path . '/translations/'; $in[] = $path . '/profiler/'; $in[] = $path . '/doctrine/'; $in[] = $path . '/serializer/'; $finder->in(array_filter($in, function ($path) { return is_dir($path); }))->depth(0)->ignoreVCS(true)->ignoreDotFiles(true); $app['filesystem']->remove($finder); 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, null, array('override' => true)); } // do not apply patches // just update old database schema // it is need before applying patches $advices = $this->upgradeDB(false, $app); foreach ($this->get_databoxes() as $s) { $advices = array_merge($advices, $s->upgradeDB(false, $app)); } // then apply patches $advices = $this->upgradeDB(true, $app); foreach ($this->get_databoxes() as $s) { $advices = array_merge($advices, $s->upgradeDB(true, $app)); } $this->post_upgrade($app); $app['phraseanet.cache-service']->flushAll(); if ($app['orm.em']->getConnection()->getDatabasePlatform()->supportsAlterTable()) { $tool = new SchemaTool($app['orm.em']); $metas = $app['orm.em']->getMetadataFactory()->getAllMetadata(); $tool->updateSchema($metas, true); } 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; }