/** * Handles updating plugins and themes * * @return bool True if the action was performed */ public function taskUpdate() { require_once __DIR__ . '/gpm.php'; $package = $this->route; $permissions = []; $type = $this->view === 'plugins' ? 'plugins' : 'themes'; // Update multi mode if (!$package) { $package = []; if ($this->view === 'plugins' || $this->view === 'update') { $package = $this->admin->gpm()->getUpdatablePlugins(); $permissions['plugins'] = ['admin.super', 'admin.plugins']; } if ($this->view === 'themes' || $this->view === 'update') { $package = array_merge($package, $this->admin->gpm()->getUpdatableThemes()); $permissions['themes'] = ['admin.super', 'admin.themes']; } } foreach ($permissions as $type => $p) { if (!$this->authorizeTask('update ' . $type, $p)) { return; } } $result = \Grav\Plugin\Admin\Gpm::update($package, ['theme' => $type == 'themes']); if ($this->view === 'update') { if ($result) { $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.EVERYTHING_UPDATED')]; } else { $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UPDATES_FAILED')]; } } else { 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 updating plugins and themes * * @return bool True is the action was performed */ public function taskUpdate() { require_once __DIR__ . '/gpm.php'; $package = $this->route; $permissions = []; // Update multi mode if (!$package) { $package = []; if ($this->view === 'plugins' || $this->view === 'update') { $package = $this->admin->gpm()->getUpdatablePlugins(); $permissions['plugins'] = ['admin.super', 'admin.plugins']; } if ($this->view === 'themes' || $this->view === 'update') { $package = array_merge($package, $this->admin->gpm()->getUpdatableThemes()); $permissions['themes'] = ['admin.super', 'admin.themes']; } } foreach ($permissions as $type => $p) { if (!$this->authoriseTask('update ' . $type, $p)) { return; } } $result = \Grav\Plugin\Admin\Gpm::update($package, []); if ($this->view === 'update') { if ($result) { $this->admin->json_response = ['status' => 'success', 'message' => 'Everything updated']; } else { $this->admin->json_response = ['status' => 'error', 'message' => 'Updates failed']; } } else { 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; }