Skip to content

Commit e8d684d

Browse files
committed
fix(dav): change type of propertyvalue column to blob
The propertyvalue column can contain null 0x00 characters values because of serializing PHP objects since #30368. This truncates data in text fields, but not blob fields. We start by removing invalid value and altering the column to match the new type. That's what Sabre PDO's being doing in the first place 🙈 Closes #37754 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent 832695d commit e8d684d

File tree

6 files changed

+258
-0
lines changed

6 files changed

+258
-0
lines changed

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@
340340
'OCA\\DAV\\Migration\\Version1029Date20231004091403' => $baseDir . '/../lib/Migration/Version1029Date20231004091403.php',
341341
'OCA\\DAV\\Migration\\Version1030Date20240205103243' => $baseDir . '/../lib/Migration/Version1030Date20240205103243.php',
342342
'OCA\\DAV\\Migration\\Version1031Date20240610134258' => $baseDir . '/../lib/Migration/Version1031Date20240610134258.php',
343+
'OCA\\DAV\\Migration\\Version1032Date20230630084412' => $baseDir . '/../lib/Migration/Version1032Date20230630084412.php',
344+
'OCA\\DAV\\Migration\\Version1032Date20230630091518' => $baseDir . '/../lib/Migration/Version1032Date20230630091518.php',
345+
'OCA\\DAV\\Migration\\Version1032Date20230702074215' => $baseDir . '/../lib/Migration/Version1032Date20230702074215.php',
346+
'OCA\\DAV\\Migration\\Version1032Date20230702074341' => $baseDir . '/../lib/Migration/Version1032Date20230702074341.php',
343347
'OCA\\DAV\\Profiler\\ProfilerPlugin' => $baseDir . '/../lib/Profiler/ProfilerPlugin.php',
344348
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningNode.php',
345349
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ class ComposerStaticInitDAV
355355
'OCA\\DAV\\Migration\\Version1029Date20231004091403' => __DIR__ . '/..' . '/../lib/Migration/Version1029Date20231004091403.php',
356356
'OCA\\DAV\\Migration\\Version1030Date20240205103243' => __DIR__ . '/..' . '/../lib/Migration/Version1030Date20240205103243.php',
357357
'OCA\\DAV\\Migration\\Version1031Date20240610134258' => __DIR__ . '/..' . '/../lib/Migration/Version1031Date20240610134258.php',
358+
'OCA\\DAV\\Migration\\Version1032Date20230630084412' => __DIR__ . '/..' . '/../lib/Migration/Version1032Date20230630084412.php',
359+
'OCA\\DAV\\Migration\\Version1032Date20230630091518' => __DIR__ . '/..' . '/../lib/Migration/Version1032Date20230630091518.php',
360+
'OCA\\DAV\\Migration\\Version1032Date20230702074215' => __DIR__ . '/..' . '/../lib/Migration/Version1032Date20230702074215.php',
361+
'OCA\\DAV\\Migration\\Version1032Date20230702074341' => __DIR__ . '/..' . '/../lib/Migration/Version1032Date20230702074341.php',
358362
'OCA\\DAV\\Profiler\\ProfilerPlugin' => __DIR__ . '/..' . '/../lib/Profiler/ProfilerPlugin.php',
359363
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningNode.php',
360364
'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php',
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\DB\Types;
15+
use OCP\IConfig;
16+
use OCP\IDBConnection;
17+
use OCP\Migration\IOutput;
18+
use OCP\Migration\SimpleMigrationStep;
19+
use Doctrine\DBAL\Types\Type;
20+
21+
/**
22+
* Cleaning invalid serialized propertyvalues and converting the column type to blob
23+
*/
24+
class Version1032Date20230630084412 extends SimpleMigrationStep {
25+
26+
public function __construct(protected IDBConnection $connection, protected IConfig $config) {
27+
}
28+
29+
/**
30+
* @param IOutput $output
31+
* @param Closure(): ISchemaWrapper $schemaClosure
32+
* @param array $options
33+
*/
34+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
35+
/**
36+
* Cleaning the invalid serialized propertyvalues because of NULL values in a text field
37+
*/
38+
$query = $this->connection->getQueryBuilder();
39+
$query->delete('properties')
40+
->where($query->expr()->eq('valuetype', $query->createNamedParameter(3)))
41+
->executeStatement();
42+
}
43+
44+
/**
45+
* @param IOutput $output
46+
* @param Closure(): ISchemaWrapper $schemaClosure
47+
* @param array $options
48+
* @return null|ISchemaWrapper
49+
*/
50+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
51+
/** @var ISchemaWrapper $schema */
52+
$schema = $schemaClosure();
53+
$propertiesTable = $schema->getTable('properties');
54+
if ($propertiesTable->hasColumn('propertyvaluenew')) {
55+
return null;
56+
}
57+
$propertiesTable->addColumn('propertyvaluenew', Types::TEXT, [
58+
'notnull' => false
59+
]);
60+
61+
return $schema;
62+
}
63+
64+
/**
65+
* @param IOutput $output
66+
* @param Closure(): ISchemaWrapper $schemaClosure
67+
* @param array $options
68+
*/
69+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
70+
$query = $this->connection->getQueryBuilder();
71+
$query->update('properties')
72+
->set('propertyvaluenew', 'propertyvalue')
73+
->executeStatement();
74+
}
75+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
/**
18+
* Removing length limit on propertypath column
19+
*/
20+
class Version1032Date20230630091518 extends SimpleMigrationStep {
21+
22+
23+
/**
24+
* @param IOutput $output
25+
* @param Closure(): ISchemaWrapper $schemaClosure
26+
* @param array $options
27+
*/
28+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
29+
}
30+
31+
/**
32+
* @param IOutput $output
33+
* @param Closure(): ISchemaWrapper $schemaClosure
34+
* @param array $options
35+
* @return null|ISchemaWrapper
36+
*/
37+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
38+
/** @var ISchemaWrapper $schema */
39+
$schema = $schemaClosure();
40+
$propertiesTable = $schema->getTable('properties');
41+
42+
$propertiesTable->dropColumn('propertyvalue');
43+
44+
return $schema;
45+
}
46+
47+
/**
48+
* @param IOutput $output
49+
* @param Closure(): ISchemaWrapper $schemaClosure
50+
* @param array $options
51+
*/
52+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
53+
}
54+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\Migration;
11+
12+
use Closure;
13+
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
14+
use OCP\DB\ISchemaWrapper;
15+
use OCP\DB\Types;
16+
use OCP\IDBConnection;
17+
use OCP\Migration\IOutput;
18+
use OCP\Migration\SimpleMigrationStep;
19+
20+
/**
21+
* Auto-generated migration step: Please modify to your needs!
22+
*/
23+
class Version1032Date20230702074215 extends SimpleMigrationStep {
24+
25+
public function __construct(protected IDBConnection $connection) {
26+
}
27+
28+
/**
29+
* @param IOutput $output
30+
* @param Closure(): ISchemaWrapper $schemaClosure
31+
* @param array $options
32+
*/
33+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
34+
}
35+
36+
/**
37+
* @param IOutput $output
38+
* @param Closure(): ISchemaWrapper $schemaClosure
39+
* @param array $options
40+
* @return null|ISchemaWrapper
41+
*/
42+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
43+
/** @var ISchemaWrapper $schema */
44+
$schema = $schemaClosure();
45+
$propertiesTable = $schema->getTable('properties');
46+
$propertiesTable->addColumn('propertyvalue', Types::BLOB, [
47+
'notnull' => false
48+
]);
49+
return $schema;
50+
}
51+
52+
/**
53+
* @param IOutput $output
54+
* @param Closure(): ISchemaWrapper $schemaClosure
55+
* @param array $options
56+
*/
57+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
58+
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
59+
$this->connection->executeStatement('UPDATE `*prefix*properties` SET `propertyvalue` = propertyvaluenew::bytea');
60+
} else {
61+
$query = $this->connection->getQueryBuilder();
62+
$query->update('properties')
63+
->set('propertyvalue', 'propertyvaluenew')
64+
->executeStatement();
65+
}
66+
}
67+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
/**
18+
* Auto-generated migration step: Please modify to your needs!
19+
*/
20+
class Version1032Date20230702074341 extends SimpleMigrationStep {
21+
22+
/**
23+
* @param IOutput $output
24+
* @param Closure(): ISchemaWrapper $schemaClosure
25+
* @param array $options
26+
*/
27+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
28+
}
29+
30+
/**
31+
* @param IOutput $output
32+
* @param Closure(): ISchemaWrapper $schemaClosure
33+
* @param array $options
34+
* @return null|ISchemaWrapper
35+
*/
36+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
37+
/** @var ISchemaWrapper $schema */
38+
$schema = $schemaClosure();
39+
$propertiesTable = $schema->getTable('properties');
40+
$propertiesTable->changeColumn('propertyvalue', [
41+
'notnull' => true
42+
]);
43+
$propertiesTable->dropColumn('propertyvaluenew');
44+
return $schema;
45+
}
46+
47+
/**
48+
* @param IOutput $output
49+
* @param Closure(): ISchemaWrapper $schemaClosure
50+
* @param array $options
51+
*/
52+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
53+
}
54+
}

0 commit comments

Comments
 (0)