Esempio n. 1
0
 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);
 }
Esempio 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;
 }
Esempio n. 3
0
 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;
 }