-
Notifications
You must be signed in to change notification settings - Fork 13
/
class.ext_update.php
169 lines (140 loc) · 6.17 KB
/
class.ext_update.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
use EWW\Dpf\Domain\Repository\DocumentRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use EWW\Dpf\Security\Security;
class ext_update {
// Ideally the version corresponds with the extension version
const NEW_VERSION = "v5.0.0";
// The version
const VERSION_4_0_0 = "v4.0.0";
public function access() {
$registry = GeneralUtility::makeInstance(Registry::class);
$version = $registry->get('tx_dpf','updatescript-'.self::NEW_VERSION);
// If the version has already been registered in the table sys_register the updatscript will be blocked.
if ($version) {
return FALSE;
}
return TRUE;
}
public function main() {
// This script registers itself into the sys_registry table to prevent a re-run with the same version number.
$registry = GeneralUtility::makeInstance(Registry::class);
$newVersion = $registry->get('tx_dpf','updatescript-'.self::NEW_VERSION);
if ($newVersion) {
return FALSE;
} else {
try {
// The necessary updates.
// 3->4: (new UpdateState)->execute();
// 3->4: (new UpdateAccessRestrictions)->execute();
// 3->4: (new UpdateVirtualType)->execute();
(new UpdateMetadataObjectValidator)->execute();
} catch (\Throwable $throwable) {
return "Error while updating the extension: ".($throwable->getMessage());
}
$registry->set('tx_dpf','updatescript-'.self::NEW_VERSION, TRUE);
return "The extension has been successfully updated.";
}
}
}
class UpdateState
{
const OBJECT_STATE_NEW = "NEW";
const OBJECT_STATE_ACTIVE = "ACTIVE";
const OBJECT_STATE_INACTIVE = "INACTIVE";
const OBJECT_STATE_DELETED = "DELETED";
const OBJECT_STATE_LOCALLY_DELETED = "LOCALLY_DELETED";
public function execute()
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$documentRepository = $objectManager->get(DocumentRepository::class);
$documents = $documentRepository->crossClientFindAll();
foreach ($documents as $oldDocument) {
$oldState = $oldDocument['state'];
$objectIdentifier = $oldDocument['objectIdentifier'];
$newDocument = $documentRepository->findByUid($oldDocument['uid']);
switch ($oldState) {
case self::OBJECT_STATE_NEW:
$newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_NEW_NONE);
break;
case self::OBJECT_STATE_ACTIVE:
$newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE);
break;
case self::OBJECT_STATE_INACTIVE:
$newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_IN_PROGRESS_INACTIVE);
break;
case self::OBJECT_STATE_DELETED:
$newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_IN_PROGRESS_DELETED);
break;
case self::OBJECT_STATE_LOCALLY_DELETED:
$newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_NONE_NONE);
break;
}
$documentRepository->update($newDocument);
}
}
}
class UpdateAccessRestrictions
{
public function execute() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$repositories[] = $objectManager->get(\EWW\Dpf\Domain\Repository\MetadataObjectRepository::class);
$repositories[] = $objectManager->get(\EWW\Dpf\Domain\Repository\MetadataGroupRepository::class);
$repositories[] = $objectManager->get(\EWW\Dpf\Domain\Repository\MetadataPageRepository::class);
foreach ($repositories as $repository) {
foreach ($repository->crossClientFindAll() as $record) {
if ($record['backend_only']) {
$recordObject = $repository->findByUid($record['uid']);
$recordObject->setAccessRestrictionRoles(array(Security::ROLE_LIBRARIAN, Security::ROLE_RESEARCHER));
$repository->update($recordObject);
}
}
}
}
}
class UpdateVirtualType
{
public function execute() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$repository = $objectManager->get(\EWW\Dpf\Domain\Repository\DocumentTypeRepository::class);
foreach ($repository->crossClientFindAll() as $record) {
if ($record['virtual']) {
$recordObject = $repository->findByUid($record['uid']);
$recordObject->setVirtualType($record['virtual'] === 1);
$repository->update($recordObject);
}
}
// $GLOBALS['TYPO3_DB']->sql_query("ALTER TABLE tx_dpf_domain_model_documenttype CHANGE virtual zzz_deleted_virtual SMALLINT UNSIGNED DEFAULT 0 NOT NULL");
}
}
class UpdateMetadataObjectValidator
{
public function execute() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$repository = $objectManager->get(\EWW\Dpf\Domain\Repository\MetadataObjectRepository::class);
foreach ($repository->crossClientFindAll() as $record) {
if ($record['data_type']) {
$recordObject = $repository->findByUid($record['uid']);
$recordObject->setValidator($record['data_type']);
$repository->update($recordObject);
}
}
}
}