/** * @param string $method * @param string $path * @param array|null $body * @return mixed */ public function request($method, $path, $body = null, $verbose = false) { $header = ['User-Agent' => 'Fusio-System v' . Base::getVersion(), 'Authorization' => 'Bearer ' . $this->getAccessToken()]; $body = $body !== null ? Parser::encode($body) : null; $request = new Request(new Url('http://127.0.0.1/backend/' . $path), $method, $header, $body); $response = new Response(); $response->setBody(new TempStream(fopen('php://memory', 'r+'))); $this->logger->pushHandler($verbose ? new StreamHandler(STDOUT) : new NullHandler()); $this->dispatch->route($request, $response, null, false); $this->logger->popHandler(); $body = (string) $response->getBody(); $data = Parser::decode($body, false); return $data; }
/** * Run the installation script to check whether an installation works * without errors */ public function testInstall() { // create a copy of the current schema $sm = $this->connection->getSchemaManager(); $toSchema = $sm->createSchema(); $this->removeAllTables(); // execute install $installer = new Installer($this->connection); $installer->install(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); } }
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'); } }
/** * @return \Symfony\Component\Console\Application */ public function getConsole() { $application = new Application('fusio', Base::getVersion()); $this->appendConsoleCommands($application); return $application; }
protected function parserHeaders($headers) { $result = []; $yaml = new Parser(); $headers = $yaml->parse($headers); if (is_array($headers)) { foreach ($headers as $key => $value) { if (is_string($key) && is_string($value)) { $result[$key] = $value; } } } // set user agent $headers['User-Agent'] = 'Fusio v' . Base::getVersion(); return $result; }
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; } }
protected function submitData(InstructionAbstract $instruction, $endpoint) { $header = ['User-Agent' => 'Fusio-Installer v' . Base::getVersion(), 'Authorization' => 'Bearer ' . $this->getAccessToken()]; $body = Json::encode($this->substituteParameters($instruction->getPayload())); $request = new PostRequest(new Url('http://127.0.0.1/' . $endpoint), $header, $body); $response = new Response(); $response->setBody(new TempStream(fopen('php://memory', 'r+'))); $this->dispatch->route($request, $response); $body = (string) $response->getBody(); $data = Json::decode($body, false); if (isset($data->success) && $data->success === true) { // installation successful $message = isset($data->message) ? $data->message : 'Insert ' . $instruction->getName() . ' successful'; $this->logger->notice($message); } else { $message = isset($data->message) ? $data->message : 'Unknown error occured'; throw new RuntimeException($message); } }