-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
executable file
·113 lines (103 loc) · 5.71 KB
/
Module.php
File metadata and controls
executable file
·113 lines (103 loc) · 5.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
110
111
112
113
<?php
namespace DataRepositoryConnector;
use Omeka\Module\AbstractModule;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\View\Renderer\PhpRenderer;
use Laminas\Mvc\Controller\AbstractController;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\MvcEvent;
use FedoraConnector\Form\ConfigForm;
use Composer\Semver\Comparator;
class Module extends AbstractModule
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function onBootstrap(MvcEvent $event)
{
parent::onBootstrap($event);
$acl = $this->getServiceLocator()->get('Omeka\Acl');
$acl->allow(
null,
['DataRepositoryConnector\Api\Adapter\DataRepositoryItemAdapter'],
['search', 'read']
);
}
public function install(ServiceLocatorInterface $serviceLocator)
{
$connection = $serviceLocator->get('Omeka\Connection');
$connection->exec("CREATE TABLE data_repository_item (id INT AUTO_INCREMENT NOT NULL, item_id INT NOT NULL, job_id INT NOT NULL, uri VARCHAR(255) NOT NULL, last_modified DATETIME NOT NULL, UNIQUE INDEX UNIQ_D984EBE1126F525E (item_id), INDEX IDX_D984EBE1BE04EA9 (job_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;");
$connection->exec("CREATE TABLE data_repository_import (id INT AUTO_INCREMENT NOT NULL, job_id INT NOT NULL, undo_job_id INT DEFAULT NULL, rerun_job_id INT DEFAULT NULL, added_count INT NOT NULL, updated_count INT NOT NULL, comment LONGTEXT DEFAULT NULL, UNIQUE INDEX UNIQ_72B61A47BE04EA9 (job_id), UNIQUE INDEX UNIQ_72B61A474C276F75 (undo_job_id), UNIQUE INDEX UNIQ_72B61A477071F49C (rerun_job_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;");
$connection->exec("ALTER TABLE data_repository_item ADD CONSTRAINT FK_D984EBE1126F525E FOREIGN KEY (item_id) REFERENCES item (id) ON DELETE CASCADE;");
$connection->exec("ALTER TABLE data_repository_item ADD CONSTRAINT FK_D984EBE1BE04EA9 FOREIGN KEY (job_id) REFERENCES job (id);");
$connection->exec("ALTER TABLE data_repository_import ADD CONSTRAINT FK_72B61A47BE04EA9 FOREIGN KEY (job_id) REFERENCES job (id)");
$connection->exec("ALTER TABLE data_repository_import ADD CONSTRAINT FK_72B61A474C276F75 FOREIGN KEY (undo_job_id) REFERENCES job (id);");
$connection->exec("ALTER TABLE data_repository_import ADD CONSTRAINT FK_72B61A477071F49C FOREIGN KEY (rerun_job_id) REFERENCES job (id);");
}
public function uninstall(ServiceLocatorInterface $serviceLocator)
{
$connection = $serviceLocator->get('Omeka\Connection');
$connection->exec("ALTER TABLE data_repository_item DROP FOREIGN KEY FK_D984EBE1126F525E;");
$connection->exec("ALTER TABLE data_repository_item DROP FOREIGN KEY FK_D984EBE1BE04EA9;");
$connection->exec("ALTER TABLE data_repository_import DROP FOREIGN KEY FK_72B61A47BE04EA9;");
$connection->exec("ALTER TABLE data_repository_import DROP FOREIGN KEY FK_72B61A474C276F75;");
$connection->exec('DROP TABLE data_repository_item');
$connection->exec('DROP TABLE data_repository_import');
}
public function upgrade($oldVersion, $newVersion, ServiceLocatorInterface $services)
{
$connection = $services->get('Omeka\Connection');
if (Comparator::lessThan($oldVersion, '1.2.0')) {
$connection->exec("ALTER TABLE data_repository_import ADD rerun_job_id INT DEFAULT NULL AFTER undo_job_id;");
$connection->exec("ALTER TABLE data_repository_import ADD CONSTRAINT FK_72B61A477071F49C FOREIGN KEY (rerun_job_id) REFERENCES job (id);");
}
if (Comparator::lessThan($oldVersion, '1.4.0')) {
$connection->exec("ALTER TABLE data_repository_import CHANGE comment comment LONGTEXT DEFAULT NULL;");
}
}
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
{
$sharedEventManager->attach(
'Omeka\Controller\Admin\Item',
'view.show.sidebar',
[$this, 'showSource']
);
$sharedEventManager->attach(
\Omeka\Api\Adapter\ItemAdapter::class,
'api.search.query',
[$this, 'importSearch']
);
}
public function showSource($event)
{
$view = $event->getTarget();
$item = $view->item;
$api = $this->getServiceLocator()->get('Omeka\ApiManager');
$response = $api->search('data_repo_items', ['item_id' => $item->id()]);
$dataItems = $response->getContent();
if ($dataItems) {
$dataItem = $dataItems[0];
echo '<div class="meta-group">';
echo '<h4>' . $view->translate('Original') . '</h4>';
echo '<div class="value"><a href="' . $dataItem->uri() . '" target="_blank">' . $view->translate('Link') . '</a></div>';
echo '<div class="value">' . $view->translate('Last Modified: ') . ' ' . $view->i18n()->dateFormat($dataItem->lastModified()) . '</div></div>';
}
}
public function importSearch($event)
{
$query = $event->getParam('request')->getContent();
if (isset($query['data_import_id'])) {
$qb = $event->getParam('queryBuilder');
$adapter = $event->getTarget();
$importItemAlias = $adapter->createAlias();
$qb->innerJoin(
\DataRepositoryConnector\Entity\DataRepositoryItem::class, $importItemAlias,
'WITH', "$importItemAlias.item = omeka_root.id"
)->andWhere($qb->expr()->eq(
"$importItemAlias.job",
$adapter->createNamedParameter($qb, $query['data_import_id'])
));
}
}
}