|
| 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 | +} |
0 commit comments