/** * Handle removing a package * * @return bool */ protected function taskRemovePackage() { $data = $this->post; $package = isset($data['package']) ? $data['package'] : ''; $type = isset($data['type']) ? $data['type'] : ''; if (!$this->authorizeTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) { $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK')]; return false; } //check if there are packages that have this as a dependency. Abort and show which ones $dependent_packages = $this->admin->getPackagesThatDependOnPackage($package); if (count($dependent_packages) > 0) { if (count($dependent_packages) > 1) { $message = "The installed packages <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove those first."; } else { $message = "The installed package <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove it first."; } $this->admin->json_response = ['status' => 'error', 'message' => $message]; return false; } try { $dependencies = $this->admin->dependenciesThatCanBeRemovedWhenRemoving($package); $result = Gpm::uninstall($package, []); } catch (\Exception $e) { $this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()]; return false; } if ($result) { $this->admin->json_response = ['status' => 'success', 'dependencies' => $dependencies, 'message' => $this->admin->translate(is_string($result) ? $result : 'PLUGIN_ADMIN.UNINSTALL_SUCCESSFUL')]; } else { $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UNINSTALL_FAILED')]; } return true; }
/** * Handles uninstalling plugins and themes * * @return bool True if the action was performed */ public function taskUninstall() { $type = $this->view === 'plugins' ? 'plugins' : 'themes'; if (!$this->authorizeTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) { return; } require_once __DIR__ . '/gpm.php'; $package = $this->route; $result = \Grav\Plugin\Admin\Gpm::uninstall($package, []); if ($result) { $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UNINSTALL_SUCCESSFUL'), 'info'); } else { $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.UNINSTALL_FAILED'), 'error'); } $this->post = array('_redirect' => $this->view); return true; }
/** * Handles uninstalling plugins and themes * * @return bool True is the action was performed */ public function taskUninstall() { $type = $this->view === 'plugins' ? 'plugins' : 'themes'; if (!$this->authoriseTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) { return; } require_once __DIR__ . '/gpm.php'; $package = $this->route; $result = \Grav\Plugin\Admin\Gpm::uninstall($package, []); if ($result) { $this->admin->setMessage("Uninstall successful.", 'info'); } else { $this->admin->setMessage("Uninstall failed.", 'error'); } $this->post = array('_redirect' => $this->view); return true; }