/** * Installs a module provided by a ModuleInstallForm * @return null */ public function installAction() { $form = new ModuleInstallForm($this->request->getBasePath() . '/install'); if (!$form->isSubmitted()) { $this->response->setRedirect($this->request->getBasePath()); return; } $exception = null; try { $form->validate(); $file = $form->getModuleFile(); $this->installer->installModule($file); } catch (ValidationException $validationException) { $this->setIndexView($form); return; } catch (Exception $installException) { $exception = $installException; } if ($file->exists()) { $file->delete(); } if ($exception != null) { $this->addError(self::TRANSLATION_ERROR_INSTALL_FILE, array('error' => $exception->getMessage(), 'file' => $file->getName())); Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString()); } else { $this->addInformation(self::TRANSLATION_FILE_INSTALLED, array('file' => $file->getName())); } $this->response->setRedirect($this->request->getBasePath()); }
/** * Installs the provided module on the filesystem * @param string $moduleFileContent Decoded Base64 of the contents of the module phar file * @param string $namespace The namespace of the module * @param string $name The name of the module * @return null * @throws Exception when an error occured */ private function installModuleLocally($moduleFileContent, $namespace, $name) { if ($moduleFileContent === '') { throw new ZiboException('No sources for the module ' . $namespace . '.' . $name . ' recieved from the repository'); } $downloadDirectory = new File('application/data'); $downloadDirectory->create(); $moduleFile = new File($downloadDirectory, $namespace . '.' . $name . '.phar'); $moduleFile->write($moduleFileContent); $exception = null; try { $this->installer->installModule($moduleFile); } catch (Exception $e) { $exception = $e; } if ($moduleFile->exists()) { $moduleFile->delete(); } if ($exception) { throw $exception; } }