/**
  * @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]);
     }
 }
 /**
  * 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;
 }
 private function appsTableName()
 {
     return \atuin\apps\models\App::tableName();
 }