Example #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');
     }
 }
Example #2
0
 /**
  * @return \Symfony\Component\Console\Application
  */
 public function getConsole()
 {
     $application = new Application('fusio', Base::getVersion());
     $this->appendConsoleCommands($application);
     return $application;
 }
Example #3
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);
     }
 }
Example #4
0
 protected function doInstall($schemaVersion)
 {
     $version = self::getVersion($schemaVersion);
     if ($version instanceof VersionInterface) {
         $fromSchema = $this->connection->getSchemaManager()->createSchema();
         $toSchema = $version->getSchema();
         $queries = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());
         $this->connection->beginTransaction();
         foreach ($queries as $query) {
             $this->connection->query($query);
         }
         // insert installation entry
         $now = new DateTime();
         $this->connection->insert('fusio_meta', ['version' => Base::getVersion(), 'installDate' => $now->format('Y-m-d H:i:s')]);
         $this->connection->commit();
         return $version;
     } else {
         return null;
     }
 }
Example #5
0
 /**
  * Checks whether this version is in the upgrade path
  */
 public function testUpgradePath()
 {
     $installer = new Installer($this->connection);
     $path = $installer->getUpgradePath();
     $this->assertEquals(Base::getVersion(), current($path), 'The current version must be in the upgrade path');
 }