Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 50 additions & 13 deletions application/src/Controller/Admin/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Omeka\Form\ConfirmForm;
use Omeka\Module\Exception\ModuleCannotInstallException;
use Omeka\Module\Manager as OmekaModuleManager;
use Omeka\Stdlib\PsrMessage;
use Laminas\ModuleManager\ModuleManager;
use Omeka\Mvc\Exception;
use Laminas\Form\Form;
Expand Down Expand Up @@ -50,7 +51,8 @@ public function browseAction()
$modules = array_merge(
$this->omekaModules->getModulesByState('not_found'),
$this->omekaModules->getModulesByState('invalid_module'),
$this->omekaModules->getModulesByState('invalid_ini')
$this->omekaModules->getModulesByState('invalid_ini'),
$this->omekaModules->getModulesByState('invalid_omeka_version')
);
} elseif ($state) {
$modules = $this->omekaModules->getModulesByState($state);
Expand Down Expand Up @@ -98,7 +100,7 @@ public function browseAction()
public function installAction()
{
if (!$this->getRequest()->isPost()) {
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'not_installed']], true);
}
$id = $this->params()->fromQuery('id');
$form = $this->getForm(ModuleStateChangeForm::class, [
Expand All @@ -117,7 +119,10 @@ public function installAction()
$this->omekaModules->install($module);
} catch (ModuleCannotInstallException $e) {
$this->messenger()->addError($e->getMessage());
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'not_installed']], true);
} catch (\Exception $e) {
$this->addModuleErrorMessage($e);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'not_installed']], true);
}
$this->messenger()->addSuccess('The module was successfully installed'); // @translate
if ($module->isConfigurable()) {
Expand All @@ -126,7 +131,7 @@ public function installAction()
['query' => ['id' => $module->getId()]], true
);
}
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'not_installed']], true);
}

public function uninstallConfirmAction()
Expand Down Expand Up @@ -175,7 +180,12 @@ public function uninstallAction()
if (!$module) {
throw new Exception\NotFoundException;
}
$this->omekaModules->uninstall($module);
try {
$this->omekaModules->uninstall($module);
} catch (\Exception $e) {
$this->addModuleErrorMessage($e);
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
}
$this->messenger()->addSuccess('The module was successfully uninstalled'); // @translate
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
}
Expand All @@ -186,7 +196,7 @@ public function uninstallAction()
public function activateAction()
{
if (!$this->getRequest()->isPost()) {
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'not_active']], true);
}
$id = $this->params()->fromQuery('id');
$form = $this->getForm(ModuleStateChangeForm::class, [
Expand All @@ -203,7 +213,7 @@ public function activateAction()
}
$this->omekaModules->activate($module);
$this->messenger()->addSuccess('The module was successfully activated'); // @translate
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'not_active']], true);
}

/**
Expand All @@ -212,7 +222,7 @@ public function activateAction()
public function deactivateAction()
{
if (!$this->getRequest()->isPost()) {
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'active']], true);
}
$id = $this->params()->fromQuery('id');
$form = $this->getForm(ModuleStateChangeForm::class, [
Expand All @@ -229,7 +239,7 @@ public function deactivateAction()
}
$this->omekaModules->deactivate($module);
$this->messenger()->addSuccess('The module was successfully deactivated'); // @translate
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'active']], true);
}

/**
Expand All @@ -238,7 +248,7 @@ public function deactivateAction()
public function upgradeAction()
{
if (!$this->getRequest()->isPost()) {
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'needs_upgrade']], true);
}
$id = $this->params()->fromQuery('id');
$form = $this->getForm(ModuleStateChangeForm::class, [
Expand All @@ -253,9 +263,14 @@ public function upgradeAction()
if (!$module) {
throw new Exception\NotFoundException;
}
$this->omekaModules->upgrade($module);
try {
$this->omekaModules->upgrade($module);
} catch (\Exception $e) {
$this->addModuleErrorMessage($e);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'needs_upgrade']], true);
}
$this->messenger()->addSuccess('The module was successfully upgraded'); // @translate
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'needs_upgrade']], true);
}

/**
Expand Down Expand Up @@ -285,7 +300,7 @@ public function configureAction()
unset($this->getRequest()->getPost()["{$formName}_csrf"]);
if (false !== $moduleObject->handleConfigForm($this)) {
$this->messenger()->addSuccess('The module was successfully configured'); // @translate
return $this->redirect()->toRoute(null, ['action' => 'browse'], true);
return $this->redirect()->toRoute(null, ['action' => 'browse'], ['query' => ['state' => 'active']], true);
}
$this->messenger()->addError('There was a problem during configuration'); // @translate
} else {
Expand Down Expand Up @@ -313,4 +328,26 @@ public function showDetailsAction()
$view->setVariable('module', $module);
return $view;
}

/**
* Add module error message to messenger.
*
* Display the hint about error logging and the exception short message.
*/
protected function addModuleErrorMessage(\Throwable $e): void
{
if (!ini_get('display_errors')) {
$message = new PsrMessage(
'To learn how to see more detailed information about this error, see the Omeka S User Manual page on {link}retrieving error messages{link_end}.', // @translate
['link' => '<a href="https://omeka.org/s/docs/user-manual/errorLogging/">', 'link_end' => '</a>']
);
$message->setEscapeHtml(false);
$this->messenger()->addError($message);
}
$this->messenger()->addError(sprintf(
'%s: %s', // @translate
get_class($e),
$e->getMessage()
));
}
}
Loading