Ejemplo n.º 1
0
 protected function generateUpgradesFromOption(InputInterface $input)
 {
     if (null === $input->getOption('from') && null === $input->getOption('at-version')) {
         throw new \Exception('You MUST provide a `from` or `at-version` option');
     }
     if (null !== $input->getOption('from') && null !== $input->getOption('at-version')) {
         throw new \Exception('You CAN NOT provide a `from` AND `at-version` option at the same time');
     }
     $versions = ['Upgrade\\Step31' => '3.1', 'Upgrade\\Step35' => '3.5'];
     if (null !== $input->getOption('from')) {
         foreach ($versions as $classname => $version) {
             if (version::lt($version, $input->getOption('from'))) {
                 continue;
             }
             $classname = __NAMESPACE__ . '\\' . $classname;
             $this->upgrades[] = new $classname($this->container);
         }
     }
     if (null !== $input->getOption('at-version')) {
         if ('3.1' === $input->getOption('at-version')) {
             $this->upgrades[] = new Step31($this->container);
         }
         if ('3.5' === $input->getOption('at-version')) {
             $this->upgrades[] = new Step35($this->container);
         }
     }
 }
Ejemplo n.º 2
0
 public function validate($data)
 {
     if (!is_object($data)) {
         throw new InvalidArgumentException('Json Schema must be an object');
     }
     $this->validator->reset();
     $this->validator->check($data, $this->schemaData);
     if (!$this->validator->isValid()) {
         $errors = [];
         foreach ((array) $this->validator->getErrors() as $error) {
             $errors[] = ($error['property'] ? $error['property'] . ' : ' : '') . $error['message'];
         }
         throw new JsonValidationException('Manifest file does not match the expected JSON schema', $errors);
     }
     if (!preg_match('/^[a-z0-9-_]+$/', $data->name)) {
         throw new JsonValidationException('Does not match the expected JSON schema', ['"name" must not contains only alphanumeric caracters']);
     }
     if (isset($data->{'minimum-phraseanet-version'})) {
         if (version::lt($this->version->getNumber(), $data->{'minimum-phraseanet-version'})) {
             throw new JsonValidationException(sprintf('Version incompatibility : Minimum Phraseanet version required is %s, current version is %s', $data->{'minimum-phraseanet-version'}, $this->version->getNumber()));
         }
     }
     if (isset($data->{'maximum-phraseanet-version'})) {
         if (version::gte($this->version->getNumber(), $data->{'maximum-phraseanet-version'})) {
             throw new JsonValidationException(sprintf('Version incompatibility : Maximum Phraseanet version required is %s, current version is %s', $data->{'maximum-phraseanet-version'}, $this->version->getNumber()));
         }
     }
 }
Ejemplo n.º 3
0
 protected function doExecute(InputInterface $input, OutputInterface $output)
 {
     $grunt = $this->container['driver.grunt'];
     $grunt->getProcessBuilderFactory()->setTimeout(600);
     $bower = $this->container['driver.bower'];
     $output->writeln("Using <info>" . $grunt->getProcessBuilderFactory()->getBinary() . "</info> for driver");
     $output->writeln("Using <info>" . $bower->getProcessBuilderFactory()->getBinary() . "</info> for driver");
     $version = trim($bower->command('-v'));
     if (version::lt($version, '1.0.0-alpha.1')) {
         throw new RuntimeException(sprintf('Bower version 1.0.0-alpha.1 is required (version %s provided), please install bower-canary : `npm install -g bower-canary or run npm install from root directory`', $version));
     }
     $version = trim($grunt->command('--version'));
     if (!version_compare('0.4.0', substr($version, -5), '<=')) {
         throw new RuntimeException(sprintf('Grunt version >= 0.4.0 is required (version %s provided), please install grunt `http://gruntjs.com/getting-started`', $version));
     }
     if ($input->getOption('clear-cache')) {
         $output->write("Cleaning bower cache... ");
         $bower->command(['cache', 'clean']);
         $output->writeln("<comment>OK</comment>");
     }
     try {
         $output->write("Installing assets...");
         $grunt->command('install-assets');
         $output->write(" <comment>OK</comment>");
         $output->writeln("");
         $this->container['console']->get('assets:compile-less')->execute($input, $output);
     } catch (ExecutionFailureException $e) {
         throw new RuntimeException('Unable to install bower dependencies', $e->getCode(), $e);
     }
     return 0;
 }
Ejemplo n.º 4
0
 public function index()
 {
     $page_title = 'BFAdminCP Updater';
     $latest_release = Cache::remember('latest_release', 24 * 60, function () {
         $response = $this->guzzle->get('https://api.github.com/repos/Prophet731/BFAdminCP/releases/latest');
         $latest_release = $response->json();
         return $latest_release;
     });
     $releases = Cache::remember('releases', 24 * 60, function () {
         $response = $this->guzzle->get('https://api.github.com/repos/Prophet731/BFAdminCP/releases');
         $releases = $response->json();
         return $releases;
     });
     $outofdate = version::lt(BFACP_VERSION, $latest_release['tag_name']);
     return View::make('system.updater.index', compact('page_title', 'releases', 'outofdate', 'latest_release'));
 }
Ejemplo n.º 5
0
 /**
  *
  * @return boolean
  */
 public function isUpgradable()
 {
     if (!$this->isInstalled()) {
         return false;
     }
     $upgradable = version::lt($this->app->getApplicationBox()->get_version(), $this->app['phraseanet.version']->getNumber());
     if (!$upgradable) {
         foreach ($this->app->getDataboxes() as $databox) {
             if (version::lt($databox->get_version(), $this->app['phraseanet.version']->getNumber())) {
                 $upgradable = true;
                 break;
             }
         }
     }
     return $upgradable;
 }
Ejemplo n.º 6
0
 function testEquality()
 {
     $compare = array(array("1.2.3", "v1.2.3"), array("1.2.3", "=1.2.3"), array("1.2.3", "v 1.2.3"), array("1.2.3", "= 1.2.3"), array("1.2.3", " v1.2.3"), array("1.2.3", " =1.2.3"), array("1.2.3", " v 1.2.3"), array("1.2.3", " = 1.2.3"), array("1.2.3-0", "v1.2.3-0"), array("1.2.3-0", "=1.2.3-0"), array("1.2.3-0", "v 1.2.3-0"), array("1.2.3-0", "= 1.2.3-0"), array("1.2.3-0", " v1.2.3-0"), array("1.2.3-0", " =1.2.3-0"), array("1.2.3-0", " v 1.2.3-0"), array("1.2.3-0", " = 1.2.3-0"), array("1.2.3-01", "v1.2.3-1"), array("1.2.3-01", "=1.2.3-1"), array("1.2.3-01", "v 1.2.3-1"), array("1.2.3-01", "= 1.2.3-1"), array("1.2.3-01", " v1.2.3-1"), array("1.2.3-01", " =1.2.3-1"), array("1.2.3-01", " v 1.2.3-1"), array("1.2.3-01", " = 1.2.3-1"), array("1.2.3beta", "v1.2.3beta"), array("1.2.3beta", "=1.2.3beta"), array("1.2.3beta", "v 1.2.3beta"), array("1.2.3beta", "= 1.2.3beta"), array("1.2.3beta", " v1.2.3beta"), array("1.2.3beta", " =1.2.3beta"), array("1.2.3beta", " v 1.2.3beta"), array("1.2.3beta", " = 1.2.3beta"));
     foreach ($compare as $set) {
         $a = $set[0];
         $b = $set[1];
         $this->assertTrue(SemVer\version::eq($a, $b), "%s > eq('" . $a . "', '" . $b . "')");
         $this->assertFalse(SemVer\version::neq($a, $b), "%s > !neq('" . $a . "', '" . $b . "')");
         $this->assertTrue(SemVer\version::cmp($a, "==", $b), "%s > cmp(" . $a . "==" . $b . ")");
         $this->assertFalse(SemVer\version::cmp($a, "!=", $b), "%s > !cmp(" . $a . "!=" . $b . ")");
         $this->assertFalse(SemVer\version::cmp($a, "===", $b), "%s > !cmp(" . $a . "===" . $b . ")");
         $this->assertTrue(SemVer\version::cmp($a, "!==", $b), "%s > cmp(" . $a . "!==" . $b . ")");
         $this->assertFalse(SemVer\version::gt($a, $b), "%s > !gt('" . $a . "', '" . $b . "')");
         $this->assertTrue(SemVer\version::gte($a, $b), "%s > gte('" . $a . "', '" . $b . "')");
         $this->assertFalse(SemVer\version::lt($a, $b), "%s > !lt('" . $a . "', '" . $b . "')");
         $this->assertTrue(SemVer\version::lte($a, $b), "%s > lte('" . $a . "', '" . $b . "')");
     }
 }
Ejemplo n.º 7
0
 function testBug23()
 {
     $this->assertTrue(SemVer\version::lt('3.0.0', '4.0.0-beta.1'), '3.0.0 < 4.0.0-beta.1 (Bug #23)');
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 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;
 }
 public function applyPatches(\base $base, $from, $to, $post_process)
 {
     if (version::eq($from, $to)) {
         return true;
     }
     $list_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);
             /** @var \patchAbstract $patch */
             $patch = new $classname();
             if (!in_array($base->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;
         }
     }
     uasort($list_patches, function (\patchInterface $patch1, \patchInterface $patch2) {
         return version::lt($patch1->get_release(), $patch2->get_release()) ? -1 : 1;
     });
     $success = true;
     // disable mail
     $this->app['swiftmailer.transport'] = null;
     foreach ($list_patches as $patch) {
         // Gets doctrine migrations required for current patch
         foreach ($patch->getDoctrineMigrations() as $doctrineVersion) {
             /** @var \Doctrine\DBAL\Migrations\Version $version */
             $version = $this->app['doctrine-migration.configuration']->getVersion($doctrineVersion);
             // Skip if already migrated
             if ($version->isMigrated()) {
                 continue;
             }
             $migration = $version->getMigration();
             // Handle legacy migrations
             if ($migration instanceof AbstractMigration) {
                 // Inject entity manager
                 $migration->setEntityManager($this->app['orm.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();
             } else {
                 $version->execute('up');
             }
         }
         if (false === $patch->apply($base, $this->app)) {
             $success = false;
         }
     }
     return $success;
 }