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; }
/** * Handles installing plugins and themes * * @return bool True if the action was performed */ public function taskInstall() { $type = $this->view === 'plugins' ? 'plugins' : 'themes'; if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) { return; } require_once __DIR__ . '/gpm.php'; $package = $this->route; $result = \Grav\Plugin\Admin\Gpm::install($package, ['theme' => $type == 'themes']); if ($result) { $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_SUCCESSFUL'), 'info'); } else { $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.INSTALLATION_FAILED'), 'error'); } $this->post = array('_redirect' => $this->view . '/' . $this->route); return true; }
/** * Handles installing plugins and themes * * @return bool True is the action was performed */ public function taskInstall() { $type = $this->view === 'plugins' ? 'plugins' : 'themes'; if (!$this->authoriseTask('install ' . $type, ['admin.' . $type, 'admin.super'])) { return; } require_once __DIR__ . '/gpm.php'; $package = $this->route; $result = \Grav\Plugin\Admin\Gpm::install($package, []); if ($result) { $this->admin->setMessage("Installation successful.", 'info'); } else { $this->admin->setMessage("Installation failed.", 'error'); } $this->post = array('_redirect' => $this->view . '/' . $this->route); return true; }