Skip to content

Commit 09f7d26

Browse files
Daniel BerthereauDaniel Berthereau
authored andcommitted
Added a task to upgrade table of contents for EasyAdmin.
1 parent de29f53 commit 09f7d26

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

Module.php

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use IiifServer\Form\ConfigForm;
4040
use Laminas\EventManager\Event;
4141
use Laminas\EventManager\SharedEventManagerInterface;
42+
use Laminas\ModuleManager\ModuleManager;
4243
use Laminas\Mvc\Controller\AbstractController;
4344
use Laminas\Mvc\MvcEvent;
4445
use Laminas\View\Renderer\PhpRenderer;
@@ -55,14 +56,18 @@ class Module extends AbstractModule
5556
'Common',
5657
];
5758

58-
public function onBootstrap(MvcEvent $event): void
59+
public function init(ModuleManager $moduleManager): void
5960
{
60-
parent::onBootstrap($event);
61-
6261
// The autoload doesn’t work with GetId3.
6362
// @see \IiifServer\Service\ControllerPlugin\MediaDimensionFactory
6463
require_once __DIR__ . '/vendor/autoload.php';
64+
}
6565

66+
public function onBootstrap(MvcEvent $event): void
67+
{
68+
parent::onBootstrap($event);
69+
70+
/** @var \Omeka\Permissions\Acl $acl */
6671
$acl = $this->getServiceLocator()->get('Omeka\Acl');
6772
$acl
6873
->allow(
@@ -158,6 +163,18 @@ public function attachListeners(SharedEventManagerInterface $sharedEventManager)
158163
'api.delete.post',
159164
[$this, 'handleAfterDeleteItem']
160165
);
166+
167+
// Add a job to upgrade structure from v3.
168+
$sharedEventManager->attach(
169+
\EasyAdmin\Form\CheckAndFixForm::class,
170+
'form.add_elements',
171+
[$this, 'handleJobsForm']
172+
);
173+
$sharedEventManager->attach(
174+
\EasyAdmin\Controller\CheckAndFixController::class,
175+
'easyadmin.job',
176+
[$this, 'handleEasyAdminJobs']
177+
);
161178
}
162179

163180
public function getConfigForm(PhpRenderer $renderer)
@@ -316,6 +333,52 @@ public function handleAfterDeleteItem(Event $event): void
316333
}
317334
}
318335

336+
public function handleJobsForm(Event $event): void
337+
{
338+
/**
339+
* @var \EasyAdmin\Form\CheckAndFixForm $form
340+
* @var \Laminas\Form\Element\Radio $process
341+
*/
342+
$form = $event->getTarget();
343+
$fieldset = $form->get('module_tasks');
344+
$process = $fieldset->get('process');
345+
$valueOptions = $process->getValueOptions();
346+
$valueOptions['iiifserver_upgrade_structure'] = 'Upgrade old table of contents to new format with four columns (module IIIF Server)'; // @translate
347+
$process->setValueOptions($valueOptions);
348+
$fieldset
349+
->add([
350+
'type' => \Laminas\Form\Fieldset::class,
351+
'name' => 'iiifserver_upgrade_structure',
352+
'options' => [
353+
'label' => 'Options to upgrade table of contents', // @translate
354+
],
355+
'attributes' => [
356+
'class' => 'iiifserver_upgrade_structure',
357+
],
358+
]);
359+
$fieldset->get('iiifserver_upgrade_structure')
360+
->add([
361+
'name' => 'query',
362+
'type' => \Omeka\Form\Element\Query::class,
363+
'options' => [
364+
'label' => 'Limit upgrade of tables of contents to specific items', // @translate
365+
],
366+
'attributes' => [
367+
'id' => 'iiifserver_upgrade_structure-query',
368+
],
369+
]);
370+
}
371+
372+
public function handleEasyAdminJobs(Event $event): void
373+
{
374+
$process = $event->getParam('process');
375+
if ($process === 'iiifserver_upgrade_structure') {
376+
$params = $event->getParam('params');
377+
$event->setParam('job', \IiifServer\Job\UpgradeStructures::class);
378+
$event->setParam('args', $params['module_tasks']['iiifserver_upgrade_structure'] ?? []);
379+
}
380+
}
381+
319382
/**
320383
* Same in Iiif server and Image server.
321384
*

0 commit comments

Comments
 (0)