public function actionUninstall($package)
 {
     $this->stderr('Not working now');
     return 1;
     $extension = Extensions::findByName($package);
     if ($extension === null) {
         $this->stderr('[ Error ] Extension is not installed', Console::FG_RED);
         return 1;
     }
     if ($extension->deactivateExtension() === false) {
         $this->stderr('[ Error ] Could not deactivate extension', Console::FG_RED);
         return 2;
     }
     if ($this->checkInJson($package, true) === false) {
         // we don't remove packages in studio.json - only composer
         if ($extension->removeExtensionPackage() === false) {
             $this->stderr('[ Error ] Could not remove extension package', Console::FG_RED);
             return 3;
         }
     }
     $this->stdout('[ OK ] Extension uninstalled', Console::FG_RED);
 }
 public function actionRemoveExtension($name)
 {
     $extension = Extensions::findByName($name);
     if ($extension === null) {
         throw new NotFoundHttpException();
     }
     if ($extension->is_active) {
         if ($extension->deactivateExtension() === false) {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Can\'t deactivate extension.'));
             return $this->handleActionEnd();
         }
     }
     if ($extension->removeExtensionPackage() === true) {
         if ($extension->delete()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'Extension removed successfully.'));
         }
     }
     return $this->handleActionEnd();
 }
Beispiel #3
0
 public static function installStudioPackage($name, $path)
 {
     $extension = null;
     /** @var app\modules\core\helpers\UpdateHelper $updateHelper */
     if (Extensions::isPackageInstalled($name) === true) {
         // we should just activate it
         $extension = Extensions::findByName($name);
     } else {
         $extension = new Extensions();
         $extension->name = $name;
         $extension->current_package_version_timestamp = date('Y-m-d H:i:s');
         $extension->latest_package_version_timestamp = date('Y-m-d H:i:s');
         $composerPath = rtrim($path, '/') . '/composer.json';
         $data = Json::decode(file_get_contents($composerPath), true);
         $autoload = ArrayHelper::getValue($data, 'autoload', []);
         if (isset($autoload['psr-4'])) {
             $namespaces = array_keys($autoload['psr-4']);
             $prefix = array_shift($namespaces);
             if (isset(array_keys($autoload['psr-4'])[0])) {
                 $extension->namespace_prefix = $prefix;
             }
         }
         $extension->is_active = 0;
         if ($extension->save() === false) {
             throw new ErrorException(Yii::t('app', 'Unable to save extension to database'));
         }
         $loader = (require Yii::getAlias('@app/vendor/autoload.php'));
         $psr4 = (require Yii::getAlias('@app/vendor/composer/autoload_psr4.php'));
         foreach ($psr4 as $prefix => $paths) {
             $loader->setPsr4($prefix, $paths);
         }
     }
     //try {
     $result = $extension->activateExtension(false);
     //        } catch (\Exception $e) {
     //            throw new ErrorException(Yii::t('app', 'Unable to activate extension').': '.$e->getMessage());
     //        }
     if ($result) {
         $extension->is_active = 1;
         $extension->save();
     }
     return $extension;
 }