Skip to content

Commit 42a21f3

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 <[email protected]>
1 parent 832695d commit 42a21f3

6 files changed

Lines changed: 326 additions & 0 deletions

File tree

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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Your name <[email protected]>
7+
*
8+
* @author Your name <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\DAV\Migration;
28+
29+
use Closure;
30+
use OCP\DB\ISchemaWrapper;
31+
use OCP\DB\Types;
32+
use OCP\IConfig;
33+
use OCP\IDBConnection;
34+
use OCP\Migration\IOutput;
35+
use OCP\Migration\SimpleMigrationStep;
36+
use Doctrine\DBAL\Types\Type;
37+
38+
/**
39+
* Cleaning invalid serialized propertyvalues and converting the column type to blob
40+
*/
41+
class Version1028Date20230630084412 extends SimpleMigrationStep {
42+
43+
public function __construct(protected IDBConnection $connection, protected IConfig $config) {
44+
}
45+
46+
/**
47+
* @param IOutput $output
48+
* @param Closure(): ISchemaWrapper $schemaClosure
49+
* @param array $options
50+
*/
51+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
52+
/**
53+
* Cleaning the invalid serialized propertyvalues because of NULL values in a text field
54+
*/
55+
$query = $this->connection->getQueryBuilder();
56+
$query->delete('properties')
57+
->where($query->expr()->eq('valuetype', $query->createNamedParameter(3)))
58+
->executeStatement();
59+
}
60+
61+
/**
62+
* @param IOutput $output
63+
* @param Closure(): ISchemaWrapper $schemaClosure
64+
* @param array $options
65+
* @return null|ISchemaWrapper
66+
*/
67+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
68+
/** @var ISchemaWrapper $schema */
69+
$schema = $schemaClosure();
70+
$propertiesTable = $schema->getTable('properties');
71+
if ($propertiesTable->hasColumn('propertyvaluenew')) {
72+
return null;
73+
}
74+
$propertiesTable->addColumn('propertyvaluenew', Types::TEXT, [
75+
'notnull' => false
76+
]);
77+
78+
return $schema;
79+
}
80+
81+
/**
82+
* @param IOutput $output
83+
* @param Closure(): ISchemaWrapper $schemaClosure
84+
* @param array $options
85+
*/
86+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
87+
$query = $this->connection->getQueryBuilder();
88+
$query->update('properties')
89+
->set('propertyvaluenew', 'propertyvalue')
90+
->executeStatement();
91+
}
92+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Your name <[email protected]>
7+
*
8+
* @author Your name <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\DAV\Migration;
28+
29+
use Closure;
30+
use OCP\DB\ISchemaWrapper;
31+
use OCP\Migration\IOutput;
32+
use OCP\Migration\SimpleMigrationStep;
33+
34+
/**
35+
* Removing length limit on propertypath column
36+
*/
37+
class Version1028Date20230630091518 extends SimpleMigrationStep {
38+
39+
40+
/**
41+
* @param IOutput $output
42+
* @param Closure(): ISchemaWrapper $schemaClosure
43+
* @param array $options
44+
*/
45+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
46+
}
47+
48+
/**
49+
* @param IOutput $output
50+
* @param Closure(): ISchemaWrapper $schemaClosure
51+
* @param array $options
52+
* @return null|ISchemaWrapper
53+
*/
54+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
55+
/** @var ISchemaWrapper $schema */
56+
$schema = $schemaClosure();
57+
$propertiesTable = $schema->getTable('properties');
58+
59+
$propertiesTable->dropColumn('propertyvalue');
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+
}
71+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Your name <[email protected]>
7+
*
8+
* @author Your name <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\DAV\Migration;
28+
29+
use Closure;
30+
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
31+
use OCP\DB\ISchemaWrapper;
32+
use OCP\DB\Types;
33+
use OCP\IDBConnection;
34+
use OCP\Migration\IOutput;
35+
use OCP\Migration\SimpleMigrationStep;
36+
37+
/**
38+
* Auto-generated migration step: Please modify to your needs!
39+
*/
40+
class Version1028Date20230702074215 extends SimpleMigrationStep {
41+
42+
public function __construct(protected IDBConnection $connection) {
43+
}
44+
45+
/**
46+
* @param IOutput $output
47+
* @param Closure(): ISchemaWrapper $schemaClosure
48+
* @param array $options
49+
*/
50+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
51+
}
52+
53+
/**
54+
* @param IOutput $output
55+
* @param Closure(): ISchemaWrapper $schemaClosure
56+
* @param array $options
57+
* @return null|ISchemaWrapper
58+
*/
59+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
60+
/** @var ISchemaWrapper $schema */
61+
$schema = $schemaClosure();
62+
$propertiesTable = $schema->getTable('properties');
63+
$propertiesTable->addColumn('propertyvalue', Types::BLOB, [
64+
'notnull' => false
65+
]);
66+
return $schema;
67+
}
68+
69+
/**
70+
* @param IOutput $output
71+
* @param Closure(): ISchemaWrapper $schemaClosure
72+
* @param array $options
73+
*/
74+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
75+
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
76+
$this->connection->executeStatement('UPDATE `*prefix*properties` SET `propertyvalue` = propertyvaluenew::bytea');
77+
} else {
78+
$query = $this->connection->getQueryBuilder();
79+
$query->update('properties')
80+
->set('propertyvalue', 'propertyvaluenew')
81+
->executeStatement();
82+
}
83+
}
84+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Your name <[email protected]>
7+
*
8+
* @author Your name <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\DAV\Migration;
28+
29+
use Closure;
30+
use OCP\DB\ISchemaWrapper;
31+
use OCP\Migration\IOutput;
32+
use OCP\Migration\SimpleMigrationStep;
33+
34+
/**
35+
* Auto-generated migration step: Please modify to your needs!
36+
*/
37+
class Version1028Date20230702074341 extends SimpleMigrationStep {
38+
39+
/**
40+
* @param IOutput $output
41+
* @param Closure(): ISchemaWrapper $schemaClosure
42+
* @param array $options
43+
*/
44+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
45+
}
46+
47+
/**
48+
* @param IOutput $output
49+
* @param Closure(): ISchemaWrapper $schemaClosure
50+
* @param array $options
51+
* @return null|ISchemaWrapper
52+
*/
53+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
54+
/** @var ISchemaWrapper $schema */
55+
$schema = $schemaClosure();
56+
$propertiesTable = $schema->getTable('properties');
57+
$propertiesTable->changeColumn('propertyvalue', [
58+
'notnull' => true
59+
]);
60+
$propertiesTable->dropColumn('propertyvaluenew');
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+
}
71+
}

0 commit comments

Comments
 (0)