public function actionRunTask()
    {
        if (false === Yii::$app->request->isAjax) {
            throw new NotFoundHttpException('Page not found');
        }
        $module = ExtensionsManager::module();
        $packageName = Yii::$app->request->post('packageName');
        $extension = $module->getExtensions($packageName);
        $taskType = Yii::$app->request->post('taskType');
        if (true === empty($extension) && $taskType != ExtensionsManager::INSTALL_DEFERRED_TASK) {
            return self::runTask(
                [
                    realpath(Yii::getAlias('@app') . '/yii'),
                    'extension/dummy',
                    'Undefined extension: ' . $packageName,
                ],
                ExtensionsManager::EXTENSION_DUMMY_DEFERRED_GROUP
            );
        }
        if ($module->extensionIsCore($packageName)
            && !Yii::$app->user->can('extensions-manager-access-to-core-extension')
        ) {
            throw new ForbiddenHttpException;
        }
        $chain = new ReportingChain();
        switch ($taskType) {
            case ExtensionsManager::INSTALL_DEFERRED_TASK :
                if ($module->extensionIsCore($packageName)
                    || !Yii::$app->user->can('extensions-manager-install-extension')
                ) {
                    throw new ForbiddenHttpException;
                }
                return self::runTask(
                    [
                        $module->composerPath,
                        'require',
                        $packageName,
                        '--no-interaction',
                        '--no-ansi',
                        "--working-dir={$module->getLocalExtensionsPath()}",
                        '--prefer-dist',
                        '-o',
                        $module->verbose == 1 ? '-vvv' : '',
                    ],
                    ExtensionsManager::COMPOSER_INSTALL_DEFERRED_GROUP
                );
            case ExtensionsManager::UNINSTALL_DEFERRED_TASK :
                if ($module->extensionIsCore($packageName)
                    || !Yii::$app->user->can('extensions-manager-uninstall-extension')
                ) {
                    throw new ForbiddenHttpException;
                }
                self::uninstall($extension, $chain);
                break;
            case ExtensionsManager::ACTIVATE_DEFERRED_TASK :
                if (!Yii::$app->user->can('extensions-manager-activate-extension')) {
                    throw new ForbiddenHttpException;
                }
                self::activate($extension, $chain);
                break;
            case ExtensionsManager::DEACTIVATE_DEFERRED_TASK :
                if (!Yii::$app->user->can('extensions-manager-deactivate-extension')) {
                    throw new ForbiddenHttpException;
                }
                self::deactivate($extension, $chain);
                break;
            default:
                return self::runTask(
                    [
                        realpath(Yii::getAlias('@app') . '/yii'),
                        'extension/dummy',
                        'Unrecognized task!',
                    ],
                    ExtensionsManager::EXTENSION_DUMMY_DEFERRED_GROUP
                );
        }
        if (null !== $firstTaskId = $chain->registerChain()) {
            DeferredHelper::runImmediateTask($firstTaskId);
            Yii::$app->response->format = Response::FORMAT_JSON;
            return [
                'queueItemId' => $firstTaskId,
            ];
        } else {
            throw new ServerErrorHttpException("Unable to start chain");
        }
    }