Skip to content

Commit

Permalink
FIX: Page Redirects for Manually Installed Plugins (by file)
Browse files Browse the repository at this point in the history
- #44
  • Loading branch information
aljawaid committed Apr 16, 2023
1 parent 8ce5967 commit 4027445
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Controller/PluginManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function installPlugin()
$this->installByFile($archiveFile);
}

$this->response->redirect($this->helper->url->to('PluginController', 'show'));
//$this->response->redirect($this->helper->url->to('PluginController', 'show'));
}

/**
Expand All @@ -56,6 +56,7 @@ private function installByURL(string $archiveUrl)
try {
$installer = new Installer($this->container);
$installer->install($archiveUrl);
$this->response->redirect($this->helper->url->to('PluginController', 'show'));
$this->flash->success(t('Plugin installed successfully'));
} catch (PluginInstallerException $e) {
$this->flash->failure($e->getMessage());
Expand All @@ -74,30 +75,36 @@ private function installByFile(string $archiveFile)

try {
if ($zip->open($archiveFile) !== true) {
$this->response->redirect($this->helper->url->to('PluginManagerController', 'showManualPlugins', array('plugin' => 'PluginManager')));
throw new PluginInstallerException(t('Unable to open plugin archive'));
}

if ($zip->numFiles === 0) {
$this->response->redirect($this->helper->url->to('PluginManagerController', 'showManualPlugins', array('plugin' => 'PluginManager')));
throw new PluginInstallerException(t('There is no file in the plugin archive'));
}

if ($zip->locateName('Plugin.php', ZipArchive::FL_NODIR) === false) {
$this->response->redirect($this->helper->url->to('PluginManagerController', 'showManualPlugins', array('plugin' => 'PluginManager')));
throw new PluginInstallerException(t('This file is not recognised as a plugin'));
}

if (!$zip->extractTo(PLUGINS_DIR)) {
$zip->close();
$this->response->redirect($this->helper->url->to('PluginManagerController', 'showManualPlugins', array('plugin' => 'PluginManager')));
throw new PluginInstallerException(t('Unable to extract plugin archive'));
}

$zip->close();
$this->response->redirect($this->helper->url->to('PluginController', 'show'));
$this->flash->success(t('Plugin installed successfully'));
} catch (PluginInstallerException $e) {
$this->flash->failure($e->getMessage());
}

unlink($archiveFile);
} else {
$this->response->redirect($this->helper->url->to('PluginManagerController', 'showManualPlugins', array('plugin' => 'PluginManager')));
$this->flash->failure(t('Plugin archive file not found'));
}
}
Expand Down

0 comments on commit 4027445

Please sign in to comment.