Ejemplo n.º 1
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.º 2
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;
 }
 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;
 }