/
Version480Update.php
238 lines (201 loc) · 7.05 KB
/
Version480Update.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
declare(strict_types=1);
/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/
namespace Contao\InstallationBundle\Database;
use Contao\File;
use Contao\StringUtil;
class Version480Update extends AbstractVersionUpdate
{
/**
* {@inheritdoc}
*/
public function shouldBeRun(): bool
{
$schemaManager = $this->connection->getSchemaManager();
if (!$schemaManager->tablesExist(['tl_layout'])) {
return false;
}
$columns = $schemaManager->listTableColumns('tl_layout');
return isset($columns['picturefill']);
}
/**
* {@inheritdoc}
*/
public function run(): void
{
$this->connection->query('
ALTER TABLE
tl_layout
DROP
picturefill
');
$statement = $this->connection->query('
SELECT
id, jquery, scripts
FROM
tl_layout
');
// Remove the "j_mediaelement" and "js_mediaelement" templates
while (false !== ($row = $statement->fetch(\PDO::FETCH_OBJ))) {
if ($row->jquery) {
$jquery = StringUtil::deserialize($row->jquery);
if (\is_array($jquery) && false !== ($i = array_search('j_mediaelement', $jquery, true))) {
unset($jquery[$i]);
$stmt = $this->connection->prepare('
UPDATE
tl_layout
SET
jquery = :jquery
WHERE
id = :id
');
$stmt->execute([':jquery' => serialize(array_values($jquery)), ':id' => $row->id]);
}
}
if ($row->scripts) {
$scripts = StringUtil::deserialize($row->scripts);
if (\is_array($scripts) && false !== ($i = array_search('js_mediaelement', $scripts, true))) {
unset($scripts[$i]);
$stmt = $this->connection->prepare('
UPDATE
tl_layout
SET
scripts = :scripts
WHERE
id = :id
');
$stmt->execute([':scripts' => serialize(array_values($scripts)), ':id' => $row->id]);
}
}
}
$this->connection->query("
ALTER TABLE
tl_image_size
ADD
skipIfDimensionsMatch char(1) NOT NULL default ''
");
// Enable the "skipIfDimensionsMatch" option for existing image sizes (backwards compatibility)
$this->connection->query("
UPDATE
tl_image_size
SET
skipIfDimensionsMatch = '1'
");
$this->connection->query('
ALTER TABLE
tl_files
CHANGE
importantPartX importantPartX DOUBLE PRECISION DEFAULT 0 NOT NULL,
CHANGE
importantPartY importantPartY DOUBLE PRECISION DEFAULT 0 NOT NULL,
CHANGE
importantPartWidth importantPartWidth DOUBLE PRECISION DEFAULT 0 NOT NULL,
CHANGE
importantPartHeight importantPartHeight DOUBLE PRECISION DEFAULT 0 NOT NULL
');
$statement = $this->connection->query('
SELECT
id, path, importantPartX, importantPartY, importantPartWidth, importantPartHeight
FROM
tl_files
WHERE
importantPartWidth > 0 OR importantPartHeight > 0
');
$rootDir = $this->container->getParameter('kernel.project_dir');
// Convert the important part to relative values as fractions
while (false !== ($file = $statement->fetch(\PDO::FETCH_OBJ))) {
if (!file_exists($rootDir.'/'.$file->path) || is_dir($rootDir.'/'.$file->path)) {
continue;
}
$imageSize = (new File($file->path))->imageViewSize;
if (empty($imageSize[0]) || empty($imageSize[1])) {
continue;
}
$stmt = $this->connection->prepare('
UPDATE
tl_files
SET
importantPartX = :x,
importantPartY = :y,
importantPartWidth = :width,
importantPartHeight = :height
WHERE
id = :id
');
$stmt->execute([
':id' => $file->id,
':x' => $file->importantPartX / $imageSize[0],
':y' => $file->importantPartY / $imageSize[1],
':width' => $file->importantPartWidth / $imageSize[0],
':height' => $file->importantPartHeight / $imageSize[1],
]);
}
$this->connection->query('
ALTER TABLE
tl_module
ADD
minKeywordLength smallint(5) unsigned NOT NULL default 4 AFTER contextLength
');
// Disable the minimum keyword length for existing modules (backwards compatibility)
$this->connection->query("
UPDATE
tl_module
SET
minKeywordLength = 0
WHERE
type = 'search'
");
$this->connection->query("
ALTER TABLE
tl_module
CHANGE
contextLength contextLength varchar(64) NOT NULL default ''
");
$statement = $this->connection->query("
SELECT
id, contextLength, totalLength
FROM
tl_module
WHERE
type = 'search'
");
// Consolidate the search context fields
while (false !== ($row = $statement->fetch(\PDO::FETCH_OBJ))) {
$stmt = $this->connection->prepare('
UPDATE
tl_module
SET
contextLength = :context
WHERE
id = :id
');
$stmt->execute([
':id' => $row->id,
':context' => serialize([$row->contextLength, $row->totalLength]),
]);
}
$this->connection->query("
ALTER TABLE
tl_layout
ADD
defaultImageDensities varchar(255) NOT NULL default ''
");
// Move the default image densities to the page layout
$this->connection->query('
UPDATE
tl_layout l
SET
defaultImageDensities = (SELECT defaultImageDensities FROM tl_theme t WHERE t.id = l.pid)
');
// Since rememberme is broken in Contao 4.7 and there are no valid
// cookies out there, we can simply drop the old table here and let the
// install tool create the new one
$this->connection->query('DROP TABLE tl_remember_me');
}
}