Esempio n. 1
0
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');
Route::post('apps/install/{AppMarketId}', 'apps/admin/apps/install', ['before' => ['before' => 'checkAppMarketId']]);
Route::post('apps/update/{id}', 'apps/admin/apps/update', ['before' => ['before' => 'checkAppId']]);
Esempio n. 2
0
 /**
  * Deletes the selected App passing its row id
  * @param $id
  *
  * @param $id
  * @return \yii\web\Response
  * @throws BadRequestHttpException
  */
 public function actionDelete($id)
 {
     // Must be a post call
     if (Yii::$app->request->getIsPost() === FALSE) {
         throw new BadRequestHttpException(Yii::t('admin', "Bad call method."));
     }
     $modelApp = new ModelApp();
     $modelApp->deleteApp($id);
     return $this->redirect('@web/apps/market');
 }
 /**
  * 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;
 }
Esempio n. 4
0
 public function getIsUpdated()
 {
     if (is_null($this->_isUpdated)) {
         $appData = ModelApp::getAppMarketData($this->app_id);
         if (!empty($appData) && $appData[$this->app_id]['version'] !== $this->version) {
             $this->_isUpdated = FALSE;
         } else {
             $this->_isUpdated = TRUE;
         }
     }
     return $this->_isUpdated;
 }