Пример #1
0
 public function testSet_current_message()
 {
     $message = 'ZOubid  èèè\\';
     $this->object->set_current_message($message);
     $datas = $this->object->get_status();
     $this->assertArrayHasKey('message', $datas);
     $this->assertEquals($message, $datas['message']);
 }
Пример #2
0
 protected function upgradeDb($apply_patches, Setup_Upgrade $upgrader, Application $app)
 {
     $recommends = [];
     $allTables = [];
     $schema = $this->get_schema();
     foreach ($schema->tables->table as $table) {
         $allTables[(string) $table['name']] = $table;
     }
     $upgrader->add_steps(count($allTables) + 1);
     $sql = "SHOW TABLE STATUS";
     $stmt = $this->get_connection()->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $ORMTables = ['AuthFailures', 'AggregateTokens', 'BasketElements', 'Baskets', 'FeedEntries', 'FeedItems', 'FeedPublishers', 'FeedTokens', 'Feeds', 'FtpCredential', 'FtpExportElements', 'FtpExports', 'OrderElements', 'Orders', 'Registrations', 'StoryWZ', 'UsrListOwners', 'UsrLists', 'UsrListsContent', 'ValidationDatas', 'ValidationParticipants', 'ValidationSessions', 'LazaretAttributes', 'LazaretChecks', 'LazaretFiles', 'LazaretSessions', 'SessionModules', 'Sessions', 'Tasks', 'UsrAuthProviders', 'UserQueries', 'UserSettings', 'Users', 'UserNotificationSettings'];
     foreach ($rs as $row) {
         $tname = $row["Name"];
         if (isset($allTables[$tname])) {
             $upgrader->set_current_message($app->trans('Updating table %table_name%', ['%table_name%' => $tname]));
             $engine = strtolower(trim($allTables[$tname]->engine));
             $ref_engine = strtolower($row['Engine']);
             if ($engine != $ref_engine && in_array($engine, ['innodb', 'myisam'])) {
                 $sql = 'ALTER TABLE `' . $tname . '` ENGINE = ' . $engine;
                 try {
                     $stmt = $this->get_connection()->prepare($sql);
                     $stmt->execute();
                     $stmt->closeCursor();
                 } catch (\Exception $e) {
                     $recommends[] = ['message' => $app->trans('Erreur lors de la tentative ; errreur : %message%', ['%message%' => $e->getMessage()]), 'sql' => $sql];
                 }
             }
             $ret = self::upgradeTable($allTables[$tname]);
             $recommends = array_merge($recommends, $ret);
             unset($allTables[$tname]);
             $upgrader->add_steps_complete(1);
         } elseif (!in_array($tname, $ORMTables)) {
             $recommends[] = ['message' => 'Une table pourrait etre supprime', 'sql' => 'DROP TABLE ' . $this->dbname . '.`' . $tname . '`;'];
         }
     }
     foreach ($allTables as $tname => $table) {
         $upgrader->set_current_message($app->trans('Creating table %table_name%', ['%table_name%' => $table]));
         $this->createTable($table);
         $upgrader->add_steps_complete(1);
     }
     $current_version = $this->get_version();
     $upgrader->set_current_message($app->trans('Applying patches on %databox_name%', ['%databox_name%' => $this->get_dbname()]));
     if ($apply_patches) {
         $this->apply_patches($current_version, $app['phraseanet.version']->getNumber(), false, $upgrader, $app);
     }
     $upgrader->add_steps_complete(1);
     return $recommends;
 }
Пример #3
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;
 }