예제 #1
0
 function testKeepSimpleversion()
 {
     $t = array('1', '2.0', '1.0.1-', '1.3.2-', '1.02.0' => '1.2.0', '0.2.5', '01.2.6' => '1.2.6', '2.0.03' => '2.0.3', '0.0.0');
     foreach ($t as $original => $result) {
         if (!is_string($original)) {
             $original = $result;
         }
         $v = new SemVer\version($original);
         $this->assertEqual($v->__toString(), $result, '[' . $original . '] %s');
     }
 }
예제 #2
0
 function testIncrementVersions()
 {
     $compare = array(array("1.2.3", "major", "2.0.0"), array("1.2.3", "minor", "1.3.0"), array("1.2.3", "patch", "1.2.4"), array("1.2.3", "build", "1.2.3-1"), array("1.2.3-4", "build", "1.2.3-5"), array("1.2.3tag", "major", "2.0.0"), array("1.2.3-tag", "major", "2.0.0"), array("1.2.3tag", "build", "1.2.3-1"), array("1.2.3-tag", "build", "1.2.3-1"), array("1.2.3-4-tag", "build", "1.2.3-5"), array("1.2.3-4tag", "build", "1.2.3-5"), array("1.2.3", "fake", null), array("fake", "major", null));
     foreach ($compare as $set) {
         $s = $set[0];
         if ($set[2] === null) {
             $this->expectException();
         }
         $v = new SemVer\version($s);
         $this->assertEqual($v->inc($set[1])->getVersion(), $set[2], "%s > inc({$set['0']}, {$set['1']}) === {$set['2']}");
     }
 }
예제 #3
0
 /**
  * Process the New Release command.
  *
  * {@inheritDoc}
  *
  * - Update the version.php file
  * - Commit the change and tag it
  *
  * This command assumes you are running it from the root of the repository.
  * Additionally, this command makes changes to the master branch.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Get the version information from the project config.
     $config_vars = $this->getConfigParameter('vars');
     if (array_key_exists('version_file', $config_vars)) {
         $version_file = $config_vars['version_file'];
     } else {
         throw new \Exception("You must have a vars:version_file set up in your project-config.yml. Ex. version_file: ./version.php");
     }
     if (array_key_exists('version_constant', $config_vars)) {
         $version_constant = $config_vars['version_constant'];
     } else {
         throw new \Exception("You must have a vars:version_constant set up in your project-config.yml. Ex. version_constant: MY_PROJECT_VERSION");
     }
     // Determine the new version number.
     $increment = $input->getArgument('increment');
     try {
         // This will succeed when a specific version number is provided (as
         // opposed to "major" or "minor" or "patch"), otherwise an exception will
         // be thrown and the "catch" is used.
         $version = new version($increment);
         $version_number = $version->getVersion();
     } catch (\Exception $e) {
         // Get the current version from the version file if it exists. Otherwise
         // we're starting from scratch.
         if (file_exists($version_file)) {
             include $version_file;
         }
         $current_version = defined($version_constant) ? new version(constant($version_constant)) : new version('0.0.0');
         $version_number = $current_version->inc($increment);
     }
     // Update version file.
     $fs = new Filesystem();
     $fs->dumpFile($version_file, "<?php define('{$version_constant}', '{$version_number}');\n");
     $output->writeln("<info>Successfully updated the {$version_file} file and set the {$version_constant} to {$version_number}</info>");
     // Commit the updated version file.
     $process = new Process('git add ' . $version_file . ' && git commit -m "Preparing for new tag: ' . $version_number . '"');
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     // Tag the commit.
     $process = new Process('git tag ' . $version_number);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
 }
예제 #4
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()));
         }
     }
 }
예제 #5
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);
         }
     }
 }
예제 #6
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;
 }
예제 #7
0
파일: Need.php 프로젝트: LobbyOS/server
 /**
  * Check requirements
  * @param array $requires The array containing the requirements
  * @param bool $boolean Whether the return value must be a boolean
  * @param bool $multi Whether return value contain both satisfy boolean and requirement version
  */
 public static function checkRequirements($requires, $boolean = false, $multi = false)
 {
     $result = $requires;
     /**
      * $requiredVersion will look like ">=5.0"
      */
     foreach ($requires as $dependency => $requiredVersion) {
         $currentVersion = self::getDependencyVersion($dependency);
         /**
          * Compare the current version and required version
          */
         $version = new version($currentVersion);
         if ($version->satisfies(new expression($requiredVersion))) {
             $result[$dependency] = true;
         } else {
             $result[$dependency] = false;
         }
         /**
          * If dependency is an app
          */
         if (strpos($dependency, "/") !== false) {
             list($mainDependency, $subDependency) = explode("/", $dependency);
             if ($mainDependency === "app") {
                 $App = new Apps($subDependency);
                 if ($multi) {
                     $result = $result + self::checkRequirements($App->info["require"], false, true);
                 } else {
                     if ($boolean) {
                         $result[$dependency] = self::checkRequirements($App->info["require"], true);
                     } else {
                         $result = $result + self::checkRequirements($App->info["require"]);
                     }
                 }
             }
         }
     }
     if ($multi) {
         foreach ($result as $dependency => $satisfy) {
             if (!is_array($satisfy)) {
                 $result[$dependency] = array("require" => $requires[$dependency], "satisfy" => $satisfy);
             }
         }
         return $result;
     }
     return $boolean ? !in_array(false, $result) : $result;
 }
예제 #8
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $version = $input->getArgument("version");
     try {
         $semver = new version($version);
     } catch (\Exception $e) {
         $output->writeln("<error>Given version is not valid. Please provide a semver version</error>");
         return;
     }
     $version = $semver->getVersion();
     $dir = $input->getOption("dir");
     $dir = realpath(getcwd() . "/" . ($dir ?: ""));
     if (!is_dir($dir) || is_writeable($dir)) {
         $output->writeln("Given directory does not exists or is not writeable");
         return;
     }
     $fs = new Filesystem(new Adapter($dir));
     $files = $fs->listContents("", true);
     $updates = [];
     foreach ($files as $file) {
         if ($file['type'] === 'dir') {
             continue;
         }
         $content = $fs->read($file['path']);
         $content = preg_replace_callback(static::SEMVER_REGEX, function ($matches) use($version, &$updates) {
             list($prefix, $ver) = array_slice($matches, 1);
             if (!isset($updates[$ver])) {
                 $updates[$ver] = 0;
             }
             $updates[$ver]++;
             return $prefix . $version;
         }, $content);
         $fs->update($file['path'], $content);
     }
     foreach ($updates as $update => $count) {
         $output->writeln("<info>{$count} files have been updated from {$update} to {$version}</info>");
     }
 }
예제 #9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $type = $input->getArgument('type');
     //Check the type is valid
     if (!in_array($type, array('major', 'minor', 'patch', 'build'))) {
         $output->writeln('<error>You must specify the release type (major, minor, patch or build)</error>');
     }
     //Fetch the current version from git
     $process = new Process('git describe --tags --abbrev=0');
     $process->run();
     if (!$process->isSuccessful()) {
         $output->writeln('<error>Git repository invalid or doesn\'t contain any tags');
         return;
     }
     $oldVersion = new version($process->getOutput());
     //Incriment the new version
     $newVersion = $oldVersion->inc($type);
     //Incriment the version
     $output->writeln('<info>Tagging new version ' . $newVersion->getVersion() . ' from version ' . $oldVersion->getVersion() . '</info>');
     //Tag the version
     $process = new Process('git tag ' . $newVersion->getVersion());
     $process->run();
     if (!$process->isSuccessful()) {
         $output->writeln('<error>Failed to create new tag. Is your source up to date?</error>');
         return;
     }
     //Push the tags
     $output->writeln('<info>Pushing tags to Origin...</info>');
     $process = new Process('git push origin --tags');
     $process->run();
     if ($process->isSuccessful()) {
         $output->writeln('<info>Success!</info>');
     } else {
         $output->writeln('<error>Failed to push new tag to origin!</error>');
     }
 }
예제 #10
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'));
 }
예제 #11
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;
 }
예제 #12
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $dir = $input->getOption("dir");
     $dir = realpath(getcwd() . "/" . ($dir ?: ""));
     if (!is_dir($dir) || !is_writeable($dir)) {
         $output->writeln("<error>Given directory does not exists or is not writeable</error>");
         return;
     }
     $fs = new Filesystem(new Adapter($dir));
     $files = $fs->listContents("", true);
     $updates = [];
     $errors = 0;
     foreach ($files as $file) {
         if ($file['type'] === 'dir') {
             continue;
         }
         $content = $fs->read($file['path']);
         $content = preg_replace_callback(static::SEMVER_REGEX, function ($matches) use(&$updates, &$errors, $input) {
             list($prefix, $ver) = array_slice($matches, 1);
             try {
                 $semver = new version($ver);
             } catch (\Exception $e) {
                 $errors++;
                 return $prefix . $ver;
             }
             if ($input->getOption("major")) {
                 $semver->inc("major");
             } elseif ($input->getOption("minor")) {
                 $semver->inc("minor");
             } elseif ($input->getOption("patch")) {
                 $semver->inc("patch");
             } else {
                 $semver->inc("patch");
             }
             if (!isset($updates[$ver])) {
                 $updates[$ver] = ["count" => 0, "ver" => $semver->getVersion()];
             }
             $updates[$ver]['count']++;
             return $prefix . $semver->getVersion();
         }, $content);
         $fs->update($file['path'], $content);
     }
     foreach ($updates as $update => $count) {
         $output->writeln("<info>{$count['count']} files have been updated from {$update} to {$count['ver']}</info>");
     }
 }
예제 #13
0
파일: Base.php 프로젝트: chinazan/zzcrm
 public function checkVersions($versionList, $currentVersion, $errorMessage = '')
 {
     if (empty($versionList)) {
         return true;
     }
     if (is_string($versionList)) {
         $versionList = (array) $versionList;
     }
     try {
         $semver = new SemVer\version($currentVersion);
     } catch (\Exception $e) {
         $GLOBALS['log']->error('Cannot recognize currentVersion [' . $currentVersion . '], error: ' . $e->getMessage() . '.');
         return false;
     }
     foreach ($versionList as $version) {
         $isInRange = false;
         try {
             $isInRange = $semver->satisfies(new SemVer\expression($version));
         } catch (\Exception $e) {
             $GLOBALS['log']->error('Version identification error: ' . $e->getMessage() . '.');
         }
         if ($isInRange) {
             return true;
         }
     }
     $this->throwErrorAndRemovePackage($errorMessage);
 }
 /**
  * Checks if a plugin version is matches.
  *
  * @param  array $config
  * @return bool
  */
 public function pluginMatches($config)
 {
     $constraint = array_get($config, 'constraint', self::VERSION);
     return $this->version->satisfies(new SemVersionExpression($constraint));
 }
예제 #15
0
 /**
  * Check if a new version is available.
  *
  * @return bool
  */
 public function newVersionAvailable()
 {
     return version::gt($this->_latestVersion, $this->_currentVersion);
 }
예제 #16
0
 protected function doExecute(InputInterface $input, OutputInterface $output)
 {
     $interactive = !$input->getOption('yes');
     $dialog = $this->getHelperSet()->get('dialog');
     if (!$this->container['phraseanet.configuration']->isSetup()) {
         throw new RuntimeException(sprintf('Phraseanet is not setup. You can run <info>bin/setup system::install</info> command to install Phraseanet.'));
     }
     // get dbs
     $conf = $this->container['phraseanet.configuration']->getConfig();
     $dbs = array('ab' => $conf['main']['database']['dbname'], 'dbs' => array(), 'setup_dbs' => array());
     foreach ($this->container->getDataboxes() as $databox) {
         $dbs['dbs'][] = $databox;
     }
     if (count($dbs['dbs']) > 1) {
         if ($input->getOption('db-name')) {
             $dbName = $input->getOption('db-name');
         } else {
             $dialog = $this->getHelperSet()->get('dialog');
             $dbName = $dialog->ask($output, _('Please enter the databox name to reset or create'));
         }
     } else {
         if ($input->getOption('db-name')) {
             $dbName = $input->getOption('db-name');
         } else {
             $dbName = current($dbs['dbs'])->get_dbname();
         }
     }
     $continue = 'y';
     if (count($dbs['dbs']) > 1 && in_array($dbName, array_map(function ($db) {
         return $db->get_dbname();
     }, $dbs['dbs']))) {
         if ($interactive) {
             do {
                 $continue = mb_strtolower($dialog->ask($output, '<question>' . $dbName . ' database is going to be truncated, do you want to continue ? (Y/n)</question>', 'Y'));
             } while (!in_array($continue, array('y', 'n')));
         }
     }
     if ('y' !== $continue) {
         return;
     }
     $unmountedDbs = $dbToMount = array_diff(array_map(function ($db) {
         return $db->get_dbname();
     }, $dbs['dbs']), array($dbName));
     if (count($unmountedDbs) > 1 && $interactive) {
         array_unshift($unmountedDbs, 'all');
         $selected = $dialog->select($output, 'Choose Dbs to mount', $unmountedDbs, 0, false, 'Invalid choice', true);
         $dbToMount = array_map(function ($c) use($unmountedDbs) {
             return $unmountedDbs[$c];
         }, $selected);
     }
     if ($input->getOption('dependencies') || !SemVer::eq($this->container->getApplicationBox()->get_version(), $this->container['phraseanet.version']->getNumber())) {
         $this->getApplication()->find('dependencies:all')->run(new ArrayInput(array('command' => 'dependencies:all')), $output);
     }
     // get data paths
     $dataPath = $this->container['conf']->get(['main', 'storage', 'subdefs'], $this->container['root.path'] . '/datas');
     $schema = $this->container['orm.em']->getConnection()->getSchemaManager();
     $output->writeln('Creating database "' . $dbs['ab'] . '"...<info>OK</info>');
     $schema->dropAndCreateDatabase($dbs['ab']);
     $output->writeln('Creating database "' . $dbName . '"...<info>OK</info>');
     $schema->dropAndCreateDatabase($dbName);
     // inject v3.1 fixtures
     if ($input->getOption('run-patches')) {
         $content = file_get_contents($this->container['root.path'] . '/resources/hudson/connexion.inc');
         $content = str_replace('{{dbname}}', $conf['main']['database']['dbname'], $content);
         $content = str_replace('{{hostname}}', $conf['main']['database']['host'], $content);
         $content = str_replace('{{port}}', $conf['main']['database']['port'], $content);
         $content = str_replace('{{user}}', $conf['main']['database']['user'], $content);
         $content = str_replace('{{password}}', $conf['main']['database']['password'], $content);
         $tmpFile = tempnam(sys_get_temp_dir(), 'connexion.inc-v3.1-');
         $this->container['filesystem']->dumpFile($tmpFile, $content);
         $this->container['filesystem']->copy($tmpFile, $this->container['root.path'] . '/config/connexion.inc');
         $this->container['filesystem']->copy($this->container['root.path'] . '/resources/hudson/_GV.php', $this->container['root.path'] . '/config/_GV.php');
         $content = file_get_contents($this->container['root.path'] . '/resources/hudson/fixtures.sql');
         $content = str_replace('{{APPLICATION_BOX}}', $dbs['ab'], $content);
         $content = str_replace('{{DATA_BOX}}', $dbName, $content);
         $content = str_replace('{{DB_HOST}}', $conf['main']['database']['host'], $content);
         $content = str_replace('{{DB_PORT}}', $conf['main']['database']['port'], $content);
         $content = str_replace('{{DB_USER}}', $conf['main']['database']['user'], $content);
         $content = str_replace('{{DB_PASSWORD}}', $conf['main']['database']['password'], $content);
         $content = str_replace('{{DATA_BOX}}', $dbName, $content);
         $content = str_replace('{{USER_EMAIL}}', $input->getOption('email'), $content);
         $content = str_replace('{{USER_PASSWORD}}', hash('sha256', $input->getOption('password')), $content);
         $tmpFile = tempnam(sys_get_temp_dir(), 'fixtures-v3.1-');
         $this->container['filesystem']->dumpFile($tmpFile, $content);
         $verbosity = $output->getVerbosity();
         $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
         $this->getApplication()->find('dbal:import')->run(new ArrayInput(array('command' => 'dbal:import', 'file' => $tmpFile)), $output);
         $output->setVerbosity($verbosity);
         $output->writeln('Importing Phraseanet v3.1 fixtures...<info>OK</info>');
     } else {
         $this->getApplication()->find('system:uninstall')->run(new ArrayInput(array('command' => 'system:uninstall')), $output);
         $cmd = sprintf('php ' . __DIR__ . '/../../../../../bin/setup system:install --email=%s --password=%s --db-user=%s --db-template=%s --db-password=%s --databox=%s --appbox=%s --server-name=%s --db-host=%s --db-port=%s -y', $input->getOption('email'), $input->getOption('password'), $conf['main']['database']['user'], 'en', $conf['main']['database']['password'], $dbName, $dbs['ab'], $conf['servername'], $conf['main']['database']['host'], $conf['main']['database']['port']);
         $process = new Process($cmd);
         $process->setTimeout(300);
         $process->run(function ($type, $buffer) {
             if ('err' === $type) {
                 echo 'ERR > ' . $buffer;
             }
         });
         if (false === $process->isSuccessful()) {
             $output->writeln('<error>Failed to execute the following command "' . $cmd . '"</error>');
             return 1;
         }
         $output->writeln("<info>Install successful !</info>");
     }
     foreach ($dbs['dbs'] as $databox) {
         if (!in_array($databox->get_dbname(), $dbToMount) && !in_array('all', $dbToMount)) {
             continue;
         }
         $credentials = $databox->get_connection()->get_credentials();
         \databox::mount($this->container, $credentials['hostname'], $credentials['port'], $credentials['user'], $credentials['password'], $databox->get_dbname());
         $output->writeln('Mounting database "' . $databox->get_dbname() . '"...<info>OK</info>');
     }
     if ($input->getOption('run-patches') || false === $this->container['phraseanet.configuration']->isUpToDate()) {
         $version = new Version();
         if ($input->getOption('run-patches')) {
             $output->write(sprintf('Upgrading... from version <info>3.1.21</info> to <info>%s</info>', $version->getNumber()), true);
         } else {
             $output->write(sprintf('Upgrading... from version <info>%s</info> to <info>%s</info>', $this->app->getApplicationBox()->get_version(), $version->getNumber()), true);
         }
         $cmd = 'php ' . __DIR__ . '/../../../../../bin/setup system:upgrade -y -f -v';
         $process = new Process($cmd);
         $process->setTimeout(600);
         $process->run(function ($type, $buffer) {
             if ('err' === $type) {
                 echo 'ERR > ' . $buffer;
             }
         });
         if (false === $process->isSuccessful()) {
             $output->writeln('<error>Failed to execute the following command "' . $cmd . '"</error>');
             return 1;
         }
     }
     if (!$input->getOption('no-setup-dbs')) {
         // create setup dbs
         $command = $this->getApplication()->find('ini:setup-tests-dbs');
         $input = new ArrayInput(array('command' => 'ini:setup-tests-dbs'));
         $command->run($input, $output);
     }
     $this->container['conf']->set(['main', 'storage', 'subdefs'], $dataPath);
     return 0;
 }
 private function getMappedVersionTag(array $tags, $versionTag)
 {
     foreach ($tags as $tag) {
         try {
             if (SemanticVersion::eq($versionTag, $tag)) {
                 return $tag;
             }
         } catch (RuntimeException $e) {
             // Do nothing
         }
     }
     return null;
 }
예제 #18
0
 /**
  * @param  array $tags
  * @return array
  */
 private function sortTags($tags)
 {
     $return = array();
     // Don't include invalid tags
     foreach ($tags as $tag) {
         try {
             $fixedName = $this->fixupRawTag($tag['name']);
             $v = new version($fixedName, true);
             if ($v->valid()) {
                 $tag['parsed_version'] = $v;
                 $return[$v->getVersion()] = $tag;
             }
         } catch (\Exception $ex) {
             // Skip
         }
     }
     uasort($return, function ($a, $b) {
         return version::compare($a['parsed_version'], $b['parsed_version']);
     });
     return $return;
 }
예제 #19
0
 function testBug24()
 {
     $this->assertFalse(SemVer\version::gt('4.0.0-beta.9', '4.0.0-beta.10'), '4.0.0-beta.9 < 4.0.0-beta.10 (Bug #24)');
 }
예제 #20
0
 /**
  * @param version $currentVersion
  * @param $releases
  *
  * @return bool|array
  */
 private function getHighestPatchReleaseOfNextMinorVersion(version $currentVersion, $releases)
 {
     $nextMinorStep = new expression($currentVersion->getMajor() . "." . ($currentVersion->getMinor() + 1) . ".*");
     foreach ($releases as $release) {
         if ($nextMinorStep->satisfiedBy($this->getVersionFromRelease($release))) {
             return $release;
         }
     }
     return false;
 }
예제 #21
0
 function testVersionFunctions()
 {
     $t = array('1.0.0-alpha' => array('M' => 1, 'm' => 0, 'p' => 0, 'pr' => array('alpha'), 'b' => array()), '1.0.0-alpha.1' => array('M' => 1, 'm' => 0, 'p' => 0, 'pr' => array('alpha', 1), 'b' => array()), '1.0.0-0.3.7' => array('M' => 1, 'm' => 0, 'p' => 0, 'pr' => array(0, 3, 7), 'b' => array()), '1.0.0-x.7.z.92' => array('M' => 1, 'm' => 0, 'p' => 0, 'pr' => array('x', 7, 'z', 92), 'b' => array()), '1.0.0-alpha+001' => array('M' => 1, 'm' => 0, 'p' => 0, 'pr' => array('alpha'), 'b' => array('001')), '1.2.3-alpha.2+02' => array('M' => 1, 'm' => 2, 'p' => 3, 'pr' => array('alpha', 2), 'b' => array('02')), '1.2.3-a.3+02.5.a' => array('M' => 1, 'm' => 2, 'p' => 3, 'pr' => array('a', 3), 'b' => array('02', 5, 'a')));
     foreach ($t as $version => $parts) {
         $v = new SemVer\version($version);
         $this->assertEquals($v->getMajor(), $parts['M']);
         $this->assertEquals($v->getMinor(), $parts['m']);
         $this->assertEquals($v->getPatch(), $parts['p']);
         $this->assertEquals($v->getPrerelease(), $parts['pr']);
         $this->assertEquals($v->getBuild(), $parts['b']);
     }
 }
예제 #22
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;
 }
예제 #23
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;
 }
예제 #24
0
 public function getVersionsToSync()
 {
     $versionsToSync = [];
     $remote = $this->client($this->setting('remote'));
     $currentVersions = $this->project->getRefs();
     $allowedVersionRange = new expression($this->setting('sync.constraints.versions'));
     $tags = $remote->getTags($this->setting('repository'), $this->setting('owner'));
     #$this->remote->repositories()->tags();
     $this->fire('git.syncer.versions.start', [$tags]);
     foreach ($tags as $tag => $sha) {
         try {
             $version = new version($tag);
         } catch (SemVerException $e) {
             continue;
         }
         if ($version->satisfies($allowedVersionRange) === false or in_array($version->getVersion(), $currentVersions, true)) {
             continue;
         }
         $versionsToSync[] = $version;
     }
     $this->fire('git.syncer.versions.finish', [$versionsToSync]);
     return $versionsToSync;
 }
 /**
  * Sorts an array of packages by version.
  * Descending order based on Semantic Versioning.
  *
  * @param array $array Array of objects
  */
 protected function sortPackagesByVersion(array $array = array())
 {
     usort($array, function ($first, $second) {
         if ($first instanceof UpdatePackage && $second instanceof UpdatePackage) {
             return version::compare($first->getVersion(), $second->getVersion());
         }
     });
     return $array;
 }
예제 #26
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;
 }
예제 #27
0
 public function compareTwoVersions($a, $b)
 {
     return version::compare($a, $b);
 }
예제 #28
0
파일: Project.php 프로젝트: jpalala/codex
 /**
  * Get refs sorted by the configured order.
  *
  * @return array
  */
 public function getSortedRefs()
 {
     $versions = $this->versions;
     usort($versions, function (version $v1, version $v2) {
         return version::gt($v1, $v2) ? -1 : 1;
     });
     $versions = array_map(function (version $v) {
         return $v->getVersion();
     }, $versions);
     return array_merge($this->branches, $versions);
 }
예제 #29
0
 /**
  * @param version $version
  *
  * @return bool
  */
 private function isNotStable(version $version)
 {
     return count($version->getPrerelease()) > 0;
 }
예제 #30
0
 public function getVersionsToSync()
 {
     $versionsToSync = [];
     $currentVersions = $this->project->getRefs();
     $allowedVersionRange = new expression($this->setting('sync.sync.versions'));
     $tags = $this->github->repositories()->tags($this->setting('owner'), $this->setting('repository'));
     foreach ($tags as $tag) {
         try {
             $version = new version($tag['name']);
         } catch (SemVerException $e) {
             continue;
         }
         if ($version->satisfies($allowedVersionRange) === false or in_array($version->getVersion(), $currentVersions, true)) {
             continue;
         }
         $versionsToSync[] = $version;
     }
     return $versionsToSync;
 }