/** * Search * * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = App::find(); // create data provider $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['version' => $this->version, 'install_date' => $this->install_date]); $query->andFilterWhere(['like', 'description', $this->description]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @inheritdoc */ function initialize($module, $type = 'install') { parent::initialize($module, $type); $this->installationObject = $this->module->getConfigLibrary(); if (is_null($this->installationObject)) { throw new yii\base\InvalidParamException('Config class for module ' . $this->module->id . ' is not defined.'); } // Each method from config class has it's special parameter that can only be used within it, // to prevent using this parameters in the rest of the methods we will add an exception to each one foreach ($this->methodTypes as $method => $object_launched) { if ($object_launched['param']) { $this->createInstallException($object_launched['param']); } } if (!is_null(Yii::$app->db->schema->getTableSchema(App::tableName(), TRUE))) { /** @var App $app */ $this->app = App::findOne(['name' => $this->module->id]); } }
<?php use cyneek\yii2\routes\components\Route; Route::pattern('id', '\\d+'); /** * Checks if Static Object Exists */ Route::filter('checkAppId', function () { /** @var \atuin\apps\models\App $app */ $app = \atuin\apps\models\App::findOne(Route::input('id')); if (is_null($app)) { throw new \yii\web\NotFoundHttpException(Yii::t('admin', "App doesn't exist.")); } return TRUE; }); /** * Checks if the App Market Id exists in the market */ Route::filter('checkAppMarketId', function () { /** @var array $app */ $app = \atuin\apps\models\ModelApp::getAppMarketData(Route::input('AppMarketId')); if (empty($app)) { throw new \yii\web\NotFoundHttpException(Yii::t('admin', "App is not located in the market.")); } return TRUE; }); /** * Apps */ Route::get('apps', 'apps/admin/apps'); Route::any('apps/market', 'apps/admin/apps/market');
public function deleteApp($id) { /** @var App $appData */ $appData = App::findOne($id); if ($appData->core_module == 1) { throw new ErrorException("It's not possible to delete a Core App."); } // Get the market data for the app because there is where it's stored the installation data $marketData = $this->getAppMarketData($appData->app_id); $appLoader = new AppLoader(); /** @var \atuin\skeleton\Module $module */ $module = $appLoader->getModule($appData->app_id, $appData->namespace, $appData->directory); // Define the actions that will be made to update the App, in this case, the App // database update and config update // This will have different order than the install and update because we want to first // delete the config and then the App data $installActions = [new AppConfigManagement(), new AppManagement()]; AppInstaller::execute($module, $installActions, 'uninstall'); // Gets the uninstallation handler, usually will be based in composer, to delete the module data $installationHandler = $this->getInstallationHandler(['id' => $appData->app_id, 'namespace' => $appData->namespace, 'composerPackage' => $marketData[$appData->app_id]['composerPackage']]); /* Delete the App physically, last step to uninstall the App Module */ /** @var \atuin\skeleton\Module $module */ $appLoader->deleteApp($installationHandler); }
/** * Checks the app installation, since it will be done one app each time * it will have to handle multiple tasks at once. * * -* Checks if every config and apps are installed * * Checks if the config is installed and installs it * * Checks if there is any app uninstalled and installs it * * Everything depends of the request type. * * @param bool $executeInstallation * @return AjaxResponse|bool */ public function checkAppInstallation($executeInstallation = FALSE) { // 1 - Checks the app installation states // Check if basic configs are installed $configInstalled = !is_null(Yii::$app->db->schema->getTableSchema(App::tableName(), TRUE)); // Check if the core apps are installed $coreAppsInstalled = TRUE; if ($configInstalled === TRUE) { foreach ($this->basicModules as $id => $data) { if (is_null(App::findOne(['name' => $id]))) { $coreApp = $id; $coreAppsInstalled = FALSE; break; } } } // If everything is installed, return TRUE and carry on. if ($configInstalled === TRUE and $coreAppsInstalled === TRUE) { if (Yii::$app->request->getIsAjax() === FALSE) { return TRUE; } else { Yii::$app->catchAll = ['installation/site/appbox']; Yii::$app->urlManager->enablePrettyUrl = TRUE; return FALSE; } } // If there is something without installation and the call is not // ajax then we will serve the main app installation page if (($configInstalled === FALSE or $coreAppsInstalled === FALSE) and Yii::$app->request->getIsAjax() === FALSE) { Yii::$app->catchAll = ['installation/site/appinstallation']; Yii::$app->urlManager->enablePrettyUrl = TRUE; return FALSE; } // $executeInstallation = (Yii::$app->request->post('type') === 'launch'); $response = new AjaxResponse(); // If the basic configs are not installed and an ajax call then: // - if is launch type -> install them // - if is not launch type -> return a box with the text if ($configInstalled === FALSE and Yii::$app->request->getIsAjax() === TRUE) { if ($executeInstallation === TRUE) { try { $appModel = new ModelApp(); // For the coreModules we will only apply the Configs // because they are already installed via Composer foreach ($this->coreModules as $appData) { // $app = $appLoader->loadApp($coreModule); // AppInstaller::execute($app, [new AppConfigManagement()]); // Installs the app using the ModelApp library. // instead of doing it manually $appModel->installAppFromData($appData, [new AppConfigManagement()]); } } catch (\Exception $e) { $response->setErrorMessage($e->getMessage() . $e->getTraceAsString()); } $response->setData(TRUE); } else { $response->setData('Installing basic configuration'); } } if ($coreAppsInstalled === FALSE and Yii::$app->request->getIsAjax() === TRUE) { if ($executeInstallation === TRUE) { try { // Now we will install the basic modules, like user, routes, etc... // Using right now Composer only, in the future we will be able to use another // forms of installing apps. $data = $this->basicModules[$coreApp]; // Installs the app using the ModelApp library. // instead of doing it manually $appModel = new ModelApp(); $appModel->installAppFromData($data); } catch (\Exception $e) { $response->setErrorMessage($e->getMessage()); } } else { $response->setData('Installing core app ' . $coreApp); } } Yii::$app->catchAll = ['installation/site/appbox']; Yii::$app->urlManager->enablePrettyUrl = TRUE; return $response; }
/** * Deleting the App data from databases * * @throws \Exception * @throws yii\base\Exception */ public function downModule() { /** @var App $app_record */ $app_record = App::findOne(['name' => $this->module->id, 'className' => $this->module->getModuleClassName()]); if (!is_null($app_record)) { if ($app_record->core_module == 1) { throw new yii\base\Exception('Module ' . $this->module->id . ' is core, so it can\'t be uninstalled.'); } $app_record->delete(); $app_record = NULL; } else { throw new yii\base\Exception('No installed APP named ' . $this->module->id . ' found.'); } }
/** * Retrieves all the Configs assigned to the filtered Apps using AppConnections * as junction table. * * @return \yii\db\ActiveQuery */ public function getApp() { return $this->hasOne(App::className(), ['id' => 'app_id'])->via('appConnections', function ($query) { $query->where(['type' => Config::className()]); }); }
/** * Retrieves all the Configs assigned to the filtered Apps using AppConnections * as junction table. * * @return \yii\db\ActiveQuery */ public function getApp() { return $this->hasOne(App::className(), ['id' => 'app_id'])->via('appConnections', function ($query) { $query->where(['type' => \cyneek\yii2\menu\models\MenuItem::className()]); }); }
private function appsTableName() { return \atuin\apps\models\App::tableName(); }