Grav\Plugin\Admin\AdminController::taskInstallPackage PHP Method

taskInstallPackage() protected method

protected taskInstallPackage ( )
    protected function taskInstallPackage()
    {
        $data = $this->post;
        $package = isset($data['package']) ? $data['package'] : '';
        $type = isset($data['type']) ? $data['type'] : '';
        if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) {
            $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')];
            return false;
        }
        try {
            $result = Gpm::install($package, ['theme' => $type == 'theme']);
        } catch (\Exception $e) {
            $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
            return false;
        }
        if ($result) {
            $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate(is_string($result) ? $result : sprintf($this->admin->translate('PLUGIN_ADMIN.PACKAGE_X_INSTALLED_SUCCESSFULLY', null), $package))];
        } else {
            $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED')];
        }
        return true;
    }