|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Updates; |
|
14
|
|
|
|
|
15
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
16
|
|
|
use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression; |
|
17
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
|
18
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
19
|
|
|
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite; |
|
20
|
|
|
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class MigrateSettings |
|
24
|
|
|
* @internal |
|
25
|
|
|
*/ |
|
26
|
|
|
class MigrateSettings implements UpgradeWizardInterface |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Return the identifier for this wizard |
|
31
|
|
|
* This should be the same string as used in the ext_localconf class registration |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getIdentifier(): string |
|
36
|
|
|
{ |
|
37
|
|
|
return self::class; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Return the speaking name of this wizard |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getTitle(): string |
|
46
|
|
|
{ |
|
47
|
|
|
return 'Migrate Kitodo.Presentation plugins to use Extbase settings naming scheme'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Return the description for this wizard |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getDescription(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return 'This wizard migrates existing front end plugins of the extension Kitodo.Presentation (dlf) to' . |
|
58
|
|
|
' make use of the Extbase naming scheme. Therefore it updates the field values' . |
|
59
|
|
|
' "pi_flexform" within the tt_content table'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Execute the update |
|
64
|
|
|
* |
|
65
|
|
|
* Called when a wizard reports that an update is necessary |
|
66
|
|
|
* |
|
67
|
|
|
* @return bool |
|
68
|
|
|
*/ |
|
69
|
|
|
public function executeUpdate(): bool |
|
70
|
|
|
{ |
|
71
|
|
|
// Get all tt_content data of Kitodo.Presentation and update their flexforms settings |
|
72
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content'); |
|
73
|
|
|
|
|
74
|
|
|
/** @var QueryBuilder $queryBuilder */ |
|
75
|
|
|
$queryBuilder = $connection->createQueryBuilder(); |
|
76
|
|
|
$statement = $queryBuilder->select('uid') |
|
77
|
|
|
->addSelect('pi_flexform') |
|
78
|
|
|
->from('tt_content') |
|
79
|
|
|
->where( |
|
80
|
|
|
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('list')), |
|
81
|
|
|
$queryBuilder->expr()->like('list_type', $queryBuilder->createNamedParameter('dlf_%')) |
|
82
|
|
|
) |
|
83
|
|
|
->execute(); |
|
84
|
|
|
|
|
85
|
|
|
// Update the found record sets |
|
86
|
|
|
while ($record = $statement->fetch()) { |
|
|
|
|
|
|
87
|
|
|
$queryBuilder = $connection->createQueryBuilder(); |
|
88
|
|
|
$updateResult = $queryBuilder->update('tt_content') |
|
89
|
|
|
->where( |
|
90
|
|
|
$queryBuilder->expr()->eq( |
|
91
|
|
|
'uid', |
|
92
|
|
|
$queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT) |
|
93
|
|
|
) |
|
94
|
|
|
) |
|
95
|
|
|
->set('pi_flexform', $this->migrateFlexFormSettings($record['pi_flexform'])) |
|
96
|
|
|
->execute(); |
|
97
|
|
|
|
|
98
|
|
|
// exit if at least one update statement is not successful |
|
99
|
|
|
if (!((bool) $updateResult)) { |
|
100
|
|
|
return false; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return true; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Is an update necessary? |
|
109
|
|
|
* |
|
110
|
|
|
* Looks for fe plugins in tt_content table to be migrated |
|
111
|
|
|
* |
|
112
|
|
|
* @return bool |
|
113
|
|
|
*/ |
|
114
|
|
|
public function updateNecessary(): bool |
|
115
|
|
|
{ |
|
116
|
|
|
$oldSettingsFound = false; |
|
117
|
|
|
|
|
118
|
|
|
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content'); |
|
119
|
|
|
|
|
120
|
|
|
/** @var QueryBuilder $queryBuilder */ |
|
121
|
|
|
$queryBuilder = $connection->createQueryBuilder(); |
|
122
|
|
|
$statement = $queryBuilder->select('uid') |
|
123
|
|
|
->addSelect('pi_flexform') |
|
124
|
|
|
->from('tt_content') |
|
125
|
|
|
->where( |
|
126
|
|
|
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('list')), |
|
127
|
|
|
$queryBuilder->expr()->like('list_type', $queryBuilder->createNamedParameter('dlf_%')) |
|
128
|
|
|
) |
|
129
|
|
|
->execute(); |
|
130
|
|
|
|
|
131
|
|
|
// Update the found record sets |
|
132
|
|
|
while ($record = $statement->fetch()) { |
|
|
|
|
|
|
133
|
|
|
$oldSettingsFound = $this->checkForOldSettings($record['pi_flexform']); |
|
134
|
|
|
if ($oldSettingsFound === true) { |
|
135
|
|
|
// We found at least one field to be updated --> break here |
|
136
|
|
|
break; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $oldSettingsFound; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Returns an array of class names of Prerequisite classes |
|
145
|
|
|
* |
|
146
|
|
|
* This way a wizard can define dependencies like "database up-to-date" or |
|
147
|
|
|
* "reference index updated" |
|
148
|
|
|
* |
|
149
|
|
|
* @return string[] |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getPrerequisites(): array |
|
152
|
|
|
{ |
|
153
|
|
|
return [ |
|
154
|
|
|
DatabaseUpdatedPrerequisite::class |
|
155
|
|
|
]; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param string $oldValue |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
|
|
protected function migrateFlexFormSettings(string $oldValue): string |
|
164
|
|
|
{ |
|
165
|
|
|
$xml = simplexml_load_string($oldValue); |
|
166
|
|
|
|
|
167
|
|
|
// get all field elements |
|
168
|
|
|
$fields = $xml->xpath("//field"); |
|
169
|
|
|
|
|
170
|
|
|
foreach ($fields as $field) { |
|
171
|
|
|
// change the index attribute if it doesn't start with 'settings.' yet |
|
172
|
|
|
if (strpos($field['index'], 'settings.') === false) { |
|
173
|
|
|
$field['index'] = 'settings.' . $field['index']; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
return $xml->asXML(); |
|
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param string $flexFormXml |
|
183
|
|
|
* @return bool |
|
184
|
|
|
*/ |
|
185
|
|
|
protected function checkForOldSettings(string $flexFormXml): bool |
|
186
|
|
|
{ |
|
187
|
|
|
$xml = simplexml_load_string($flexFormXml); |
|
188
|
|
|
|
|
189
|
|
|
// get all field elements with value of attribute index not containing "settings." |
|
190
|
|
|
$fields = $xml->xpath("//field[not(starts-with(@index, 'settings.'))]"); |
|
191
|
|
|
|
|
192
|
|
|
return (bool) $fields; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
} |
|
196
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.