-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
executable file
·149 lines (125 loc) · 5.59 KB
/
Module.php
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace DiigoImport;
if (!class_exists(\Generic\AbstractModule::class)) {
require file_exists(dirname(__DIR__) . '/Generic/AbstractModule.php')
? dirname(__DIR__) . '/Generic/AbstractModule.php'
: __DIR__ . '/src/Generic/AbstractModule.php';
}
use Generic\AbstractModule;
use Zend\EventManager\Event;
use Zend\EventManager\SharedEventManagerInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class Module extends AbstractModule
{
const NAMESPACE = __NAMESPACE__;
protected function preInstall()
{
$services = $this->getServiceLocator();
$module = $services->get('Omeka\ModuleManager')->getModule('Generic');
if ($module && version_compare($module->getIni('version'), '3.0.18', '<')) {
$translator = $services->get('MvcTranslator');
$message = new \Omeka\Stdlib\Message(
$translator->translate('This module requires the module "%s", version %s or above.'), // @translate
'Generic', '3.0.18'
);
throw new \Omeka\Module\Exception\ModuleCannotInstallException($message);
}
}
protected function postUninstall()
{
$services = $this->getServiceLocator();
if (!class_exists(\Generic\InstallResources::class)) {
require_once file_exists(dirname(__DIR__) . '/Generic/InstallResources.php')
? dirname(__DIR__) . '/Generic/InstallResources.php'
: __DIR__ . '/src/Generic/InstallResources.php';
}
$installResources = new \Generic\InstallResources($services);
$installResources = $installResources();
if (!empty($_POST['remove-vocabulary'])) {
$prefix = 'cito';
$installResources->removeVocabulary($prefix);
$prefix = 'skos';
$installResources->removeVocabulary($prefix);
$prefix = 'oa';
$installResources->removeVocabulary($prefix);
$prefix = 'schema';
$installResources->removeVocabulary($prefix);
$prefix = 'rdf';
$installResources->removeVocabulary($prefix);
$prefix = 'jdc';
$installResources->removeVocabulary($prefix);
}
if (!empty($_POST['remove-template'])) {
$resourceTemplate = 'Diigo highlight';
$installResources->removeResourceTemplate($resourceTemplate);
$resourceTemplate = 'Diigo note';
$installResources->removeResourceTemplate($resourceTemplate);
$resourceTemplate = 'Actant';
$installResources->removeResourceTemplate($resourceTemplate);
}
}
public function warnUninstall(Event $event)
{
$view = $event->getTarget();
$module = $view->vars()->module;
if ($module->getId() != __NAMESPACE__) {
return;
}
$serviceLocator = $this->getServiceLocator();
$t = $serviceLocator->get('MvcTranslator');
$vocabularyLabels = 'Citation Typing Ontology" / "Schema" / "SKOS" / "Web Annotation Ontology" / "The RDF Concepts Vocabulary (RDF)" / "Jardin des connaissances"';
$resourceTemplates = 'Diigo highlight / Diigo note / Actant';
$html = '<p>';
$html .= '<strong>';
$html .= $t->translate('WARNING'); // @translate
$html .= '</strong>' . ': ';
$html .= '</p>';
$html .= '<p>';
$html .= sprintf(
$t->translate('If checked, the values of the vocabularies "%s" will be removed too. The class of the resources that use a class of these vocabularies will be reset.'), // @translate
$vocabularyLabels
);
$html .= '</p>';
$html .= '<label><input name="remove-vocabulary" type="checkbox" form="confirmform">';
$html .= sprintf($t->translate('Remove the vocabularies "%s"'), $vocabularyLabels); // @translate
$html .= '</label>';
$html .= '<p>';
$html .= sprintf(
$t->translate('If checked, the resource templates "%s" will be removed too. The resource template of the resources that use it will be reset.'), // @translate
$resourceTemplates
);
$html .= '</p>';
$html .= '<label><input name="remove-template" type="checkbox" form="confirmform">';
$html .= sprintf($t->translate('Remove the resource templates "%s"'), $resourceTemplates); // @translate
$html .= '</label>';
echo $html;
}
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
{
$sharedEventManager->attach(
\Omeka\Api\Adapter\ItemAdapter::class,
'api.search.query',
function (Event $event) {
$query = $event->getParam('request')->getContent();
if (isset($query['diigo_import_id'])) {
$qb = $event->getParam('queryBuilder');
$adapter = $event->getTarget();
$importItemAlias = $adapter->createAlias();
$qb->innerJoin(
\DiigoImport\Entity\DiigoImportItem::class, $importItemAlias,
'WITH', "$importItemAlias.item = omeka_root.id"
)->andWhere($qb->expr()->eq(
"$importItemAlias.import",
$adapter->createNamedParameter($qb, $query['diigo_import_id'])
));
}
}
);
// Display a warn before uninstalling.
$sharedEventManager->attach(
'Omeka\Controller\Admin\Module',
'view.details',
[$this, 'warnUninstall']
);
}
}