protected function execute(InputInterface $input, OutputInterface $output) { try { $filename = $input->getArgument('filename'); $service = new ModuloService($this->em); if (is_dir($filename)) { $key = $input->getArgument('key'); if (empty($key)) { throw new Exception('Ao instalar a partir de um diretório, deve especificar a chave do módulo'); } $service->install($filename, $key); } else { $service->extractAndInstall($filename); } $output->writeln('<info>Módulo instalado com sucesso</info>'); } catch (Exception $e) { $output->writeln("<error>{$e->getMessage()}</error>"); } }
public function install(Context $context) { $response = new JsonResponse(); try { // file upload handling $ext = 'zip'; $fu = new FileUpload('uploadfile'); $result = $fu->handleUpload(NOVOSGA_CACHE, [$ext]); if (!$result) { throw new Exception($fu->getErrorMsg()); } // install module $service = new ModuloService($this->em()); $service->extractAndInstall($fu->getSavedFile(), $fu->getExtension()); FileUtils::rm($fu->getSavedFile()); // response $response->success = true; $response->message = _('Módulo instalado com sucesso'); } catch (Exception $e) { $response->message = $e->getMessage(); } return $response; }