-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathModule.php
More file actions
executable file
·109 lines (95 loc) · 3.71 KB
/
Module.php
File metadata and controls
executable file
·109 lines (95 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace DomainManager;
use Laminas\Mvc\MvcEvent;
use Laminas\ModuleManager\ModuleManager;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\Mvc\Controller\AbstractController;
use Laminas\View\Renderer\PhpRenderer;
use Omeka\Module\AbstractModule;
use Omeka\Stdlib\Message;
use Omeka\Module\Exception\ModuleCannotInstallException;
use DomainManager\Api\DomainMapper;
class Module extends AbstractModule
{
private $domainMapper;
/**
* modules are loaded alphabetical in ascending order, which means
* modules that are lexicographically greater than this module will not be mapped.
*
* in order for us to map dynamically created routes, we must then listen to
* the route event and then generate the route based on that context
*/
public function init(ModuleManager $manager)
{
$eventManager = $manager->getEventManager();
$sharedEventManager = $eventManager->getSharedManager();
$sharedEventManager->attach('Laminas\Mvc\Application', MvcEvent::EVENT_ROUTE, function(MvcEvent $event) {
$this->domainMapper->createRoute($event->getRouter()->getRoutes());
}, 100);
}
public function onBootstrap(MvcEvent $event)
{
parent::onBootstrap($event);
$this->domainMapper = new DomainMapper($event);
$this->domainMapper->init();
}
public function getConfig()
{
return include __DIR__.'/config/module.config.php';
}
public function getConfigForm(PhpRenderer $renderer)
{
return $this->domainMapper->configurePlugin($renderer);
}
public function handleConfigForm(AbstractController $controller)
{
return $this->domainMapper->saveConfiguration($controller);
}
public function install(ServiceLocatorInterface $serviceLocator)
{
$connection = $serviceLocator->get('Omeka\Connection');
$sql = '
CREATE TABLE `domain_site_mapping` (
`id` INT NOT NULL AUTO_INCREMENT,
`site_id` INT NOT NULL,
`domain` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `DOMAIN_SITE_MAPPING_SITE_ID_UNIQUE` (`site_id` ASC),
UNIQUE INDEX `DOMAIN_SITE_MAPPING_DOMAIN_UNIQUE` (`domain` ASC),
CONSTRAINT `FK_DOMAIN_SITE_MAPPING_SITE_ID`
FOREIGN KEY (`site_id`)
REFERENCES `site` (`id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT)
DEFAULT CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
ENGINE = InnoDB
';
$connection->exec($sql);
}
public function uninstall(ServiceLocatorInterface $serviceLocator)
{
$sqls = [
'ALTER TABLE domain_site_mapping DROP FOREIGN KEY FK_DOMAIN_SITE_MAPPING_SITE_ID',
'DROP TABLE domain_site_mapping',
];
$connection = $serviceLocator->get('Omeka\Connection');
foreach ($sqls as $sql) {
$connection->exec($sql);
}
}
public function upgrade($oldVersion, $newVersion, ServiceLocatorInterface $serviceLocator)
{
$connection = $serviceLocator->get('Omeka\Connection');
if (version_compare($oldVersion, "1.2", "<")) {
if (count($connection->query("SHOW COLUMNS FROM domain_site_mapping LIKE 'site_page_id'")->fetchAll())) {
try {
$connection->exec("ALTER TABLE domain_site_mapping DROP FOREIGN KEY FK_DOMAIN_SITE_MAPPING_SITE_PAGE_ID");
$connection->exec("ALTER TABLE `domain_site_mapping` DROP `site_page_id`");
}
catch (\Exception $e) {
}
}
}
}
}