Exemplo n.º 1
0
 /**
  * @return bool
  *
  * @throws InstallFailedException
  * @throws ModuleValidationException
  */
 public function run()
 {
     $installator = $this->module->getInstallator();
     $result = $installator->uninstall();
     if ($result == false) {
         $messages = $installator->getErrorMessages();
         throw new InstallFailedException(join("\n", $messages));
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * @return ModuleModel
  */
 private function getModule()
 {
     /** @var ModuleModel $module */
     $module = ModuleModel::findOne(['name' => $this->module->id]);
     if (is_null($module)) {
         $module = new ModuleModel();
     }
     return $module;
 }
Exemplo n.º 3
0
 public function beforeAction($action)
 {
     $moduleName = $this->id;
     /** @var \app\module\module\models\Module $moduleInstalled */
     $moduleInstalled = \app\module\module\models\Module::findOne(['name' => $moduleName]);
     if (is_null($moduleInstalled) || $moduleInstalled->isEnabled() == false) {
         throw new NotFoundHttpException(sprintf('Module %s not installed or disabled', $moduleName));
     }
     return true;
 }
Exemplo n.º 4
0
 /**
  * @return array
  */
 public function getToInstall()
 {
     $modulesInstalled = \app\module\module\models\Module::find()->all();
     $modules = $this->modules;
     /** @var Module $installedMod */
     foreach ($modulesInstalled as $installedMod) {
         if (array_key_exists($installedMod->name, $modules)) {
             unset($modules[$installedMod->name]);
         }
     }
     unset($modules['debug']);
     unset($modules['gii']);
     return $modules;
 }
Exemplo n.º 5
0
 public function init()
 {
     $moduleName = $this->module->id;
     /** @var Module $module */
     $this->currentModule = Module::findOne(['name' => $moduleName]);
     if ($this->needAuthentication() == false) {
         return true;
     }
     if (\Yii::$app->user->isGuest) {
         \Yii::$app->user->setReturnUrl(\Yii::$app->request->url);
         $this->addMessage('user', 'restricted_area', Message::ALERT);
         $this->redirect('/admin/user/auth/login');
         return false;
     }
     $this->checkModuleAccess();
     //		$this->checkAdminAccess();
     /** @var Module $menuItem */
     foreach (ModuleQuery::findAllOrdered() as $menuItem) {
         $this->menuItems[$menuItem->category_name][] = $menuItem;
     }
     \Yii::$app->layout = 'admin.tpl';
 }
Exemplo n.º 6
0
 public static function findAllOrdered()
 {
     $sql = "SELECT cm.*, cc.name__pl as category_name FROM core_module cm\n\t\t\tJOIN core_category cc ON cc.id = cm.category_id\n\t\t\tORDER BY cc.`ordering`,  cm.ordering";
     return Module::findBySql($sql)->all();
 }
Exemplo n.º 7
0
 public function beforeValidate()
 {
     $sql = "SELECT * FROM core_module WHERE category_id = :categoryId ORDER BY ordering DESC";
     /** @var Module $module */
     $module = Module::findBySql($sql, [':categoryId' => $this->category_id])->one();
     $maxOrdering = is_null($module) ? 1 : $module->ordering + 1;
     $this->ordering = $maxOrdering + 1;
     return parent::beforeValidate();
     // TODO: Change the autogenerated stub
 }
Exemplo n.º 8
0
 public function actionUpdate($id)
 {
     /** @var Module $module */
     $module = Module::findOne(['id' => $id]);
     if (is_null($module)) {
         $this->addMessage('module', 'module_not_found', Message::ALERT);
         return $this->redirect('/admin/module');
     }
     $transaction = \Yii::$app->getDb()->beginTransaction();
     try {
         $installator = new BaseInstallator(\Yii::$app->getModule($module->name));
         $installator->runWithData();
         $transaction->commit();
         $this->addMessage('module', sprintf('Module %s was succesfull updated', $module->name), Message::INFO);
     } catch (ModuleInstallatorNotFound $e) {
         $transaction->rollBack();
         $this->addMessage('module', 'instalator_not_found', Message::ALERT);
     } catch (InstallFailedException $e) {
         $transaction->rollBack();
         $message = sprintf("<pre>%s</pre>", $e->getMessage());
         $message = sprintf("`module.uninstall_error_with_message` \n %s", $message);
         $this->addMessage(null, $message, Message::ALERT);
     }
     return $this->redirect('/admin/module');
 }