Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     if (!is_file($file)) {
         throw new RuntimeException('File does not exists');
     }
     $verbose = $output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL;
     if (!$verbose) {
         $this->logger->pushHandler(new NullHandler());
     }
     try {
         $this->connection->beginTransaction();
         $result = $this->importService->import(file_get_contents($file));
         $this->connection->commit();
         $output->writeln('Import successful!');
         $output->writeln('The following actions were done:');
         $output->writeln('');
         foreach ($result as $message) {
             $output->writeln('- ' . $message);
         }
     } catch (\Exception $e) {
         $this->connection->rollback();
         $output->writeln('An exception occured during import. No changes are applied to the database.');
         $output->writeln('');
         $output->writeln('Message: ' . $e->getMessage());
         $output->writeln('Trace: ' . $e->getTraceAsString());
     }
     if (!$verbose) {
         $this->logger->popHandler();
     }
 }
Example #2
0
 /**
  * Set different debug file location.
  *
  * @access  public
  * @param   string          $path  File path
  * @return  \carteiro\Mail
  */
 public function debugFilePath($path)
 {
     $this->debug(true);
     $this->logger->popHandler();
     $this->logger->pushHandler(new StreamHandler($path, Logger::DEBUG));
     return $this;
 }
Example #3
0
 /**
  * @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;
 }