示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fromSchema = $this->connection->getSchemaManager()->createSchema();
     $tableCount = count($fromSchema->getTableNames());
     if ($tableCount > 0) {
         $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion('The provided database "' . $fromSchema->getName() . '" contains already ' . $tableCount . ' tables.' . "\n" . 'The installation script will DELETE all tables on the database which does not belong to the fusio schema.' . "\n" . 'Do you want to continue with this action (y|n)?', false);
         if (!$helper->ask($input, $output, $question)) {
             return;
         }
     }
     // execute install or upgrade
     $currentVersion = $this->getInstalledVersion($fromSchema);
     $installer = new Installer($this->connection);
     if ($currentVersion !== null) {
         $output->writeln('Upgrade from version ' . $currentVersion . ' to ' . Base::getVersion());
         $installer->upgrade($currentVersion, Base::getVersion());
         $output->writeln('Upgrade successful');
     } else {
         $output->writeln('Install version ' . Base::getVersion());
         $installer->install(Base::getVersion());
         $output->writeln('Installation successful');
     }
 }
示例#2
0
 /**
  * Executes all executeUpgrade methods of each version
  */
 public function testUpgrade()
 {
     // create a copy of the current schema
     $sm = $this->connection->getSchemaManager();
     $toSchema = $sm->createSchema();
     $this->removeAllTables();
     // execute upgrade
     $installer = new Installer($this->connection);
     $installer->upgrade('0.1', Base::getVersion());
     // @TODO make checks to verify that the installation works
     $this->removeAllTables();
     // restore the schema
     $fromSchema = $sm->createSchema();
     $queries = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());
     foreach ($queries as $sql) {
         $this->connection->executeUpdate($sql);
     }
 }