diff options
author | Sebastian Krupinski <165827823+SebastianKrupinski@users.noreply.github.com> | 2024-12-13 20:20:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-13 20:20:42 -0500 |
commit | dd89911b311d03627b710b157cbc5b5f7f9c7fe6 (patch) | |
tree | 5da57f123f7af2967d699762736d292b5e7df733 /lib | |
parent | 2bbc4f59886c8586c5de55956af68b7c7f8159fd (diff) | |
parent | c1dd8ddf591337c5fb5ca2da7d476a4f0fc254c5 (diff) | |
download | nextcloud-server-dd89911b311d03627b710b157cbc5b5f7f9c7fe6.tar.gz nextcloud-server-dd89911b311d03627b710b157cbc5b5f7f9c7fe6.zip |
Merge pull request #49528 from nextcloud/fix/issue-47879-property-serialization
fix: replace null character when serializing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/Repair.php | 2 | ||||
-rw-r--r-- | lib/private/Repair/RemoveBrokenProperties.php | 68 |
4 files changed, 72 insertions, 0 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index e515e3eff07..528bf3bb2da 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1876,6 +1876,7 @@ return array( 'OC\\Repair\\Owncloud\\MoveAvatarsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php', 'OC\\Repair\\Owncloud\\SaveAccountsTableData' => $baseDir . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', 'OC\\Repair\\Owncloud\\UpdateLanguageCodes' => $baseDir . '/lib/private/Repair/Owncloud/UpdateLanguageCodes.php', + 'OC\\Repair\\RemoveBrokenProperties' => $baseDir . '/lib/private/Repair/RemoveBrokenProperties.php', 'OC\\Repair\\RemoveLinkShares' => $baseDir . '/lib/private/Repair/RemoveLinkShares.php', 'OC\\Repair\\RepairDavShares' => $baseDir . '/lib/private/Repair/RepairDavShares.php', 'OC\\Repair\\RepairInvalidShares' => $baseDir . '/lib/private/Repair/RepairInvalidShares.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index cf2883c3070..43b5042c8b4 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1917,6 +1917,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Repair\\Owncloud\\MoveAvatarsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php', 'OC\\Repair\\Owncloud\\SaveAccountsTableData' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', 'OC\\Repair\\Owncloud\\UpdateLanguageCodes' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/UpdateLanguageCodes.php', + 'OC\\Repair\\RemoveBrokenProperties' => __DIR__ . '/../../..' . '/lib/private/Repair/RemoveBrokenProperties.php', 'OC\\Repair\\RemoveLinkShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RemoveLinkShares.php', 'OC\\Repair\\RepairDavShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RepairDavShares.php', 'OC\\Repair\\RepairInvalidShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RepairInvalidShares.php', diff --git a/lib/private/Repair.php b/lib/private/Repair.php index b1a824ba5e3..5b6daa36a03 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -50,6 +50,7 @@ use OC\Repair\Owncloud\MigrateOauthTables; use OC\Repair\Owncloud\MoveAvatars; use OC\Repair\Owncloud\SaveAccountsTableData; use OC\Repair\Owncloud\UpdateLanguageCodes; +use OC\Repair\RemoveBrokenProperties; use OC\Repair\RemoveLinkShares; use OC\Repair\RepairDavShares; use OC\Repair\RepairInvalidShares; @@ -206,6 +207,7 @@ class Repair implements IOutput { public static function getExpensiveRepairSteps() { return [ new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), + new RemoveBrokenProperties(\OCP\Server::get(IDBConnection::class)), new RepairMimeTypes( \OCP\Server::get(IConfig::class), \OCP\Server::get(IAppConfig::class), diff --git a/lib/private/Repair/RemoveBrokenProperties.php b/lib/private/Repair/RemoveBrokenProperties.php new file mode 100644 index 00000000000..85939b39e5e --- /dev/null +++ b/lib/private/Repair/RemoveBrokenProperties.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OC\Repair; + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class RemoveBrokenProperties implements IRepairStep { + /** + * RemoveBrokenProperties constructor. + * + * @param IDBConnection $db + */ + public function __construct( + private IDBConnection $db, + ) { + } + + /** + * @inheritdoc + */ + public function getName() { + return 'Remove broken DAV object properties'; + } + + /** + * @inheritdoc + */ + public function run(IOutput $output) { + // retrieve all object properties + $qb = $this->db->getQueryBuilder(); + $qb->select('id', 'propertyvalue') + ->from('properties') + ->where($qb->expr()->eq('valuetype', $qb->createNamedParameter('3', IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)); + $result = $qb->executeQuery(); + // find broken object properties + $brokenIds = []; + while ($entry = $result->fetch()) { + if (!empty($entry['propertyvalue'])) { + $object = @unserialize(str_replace('\x00', chr(0), $entry['propertyvalue'])); + if ($object === false) { + $brokenIds[] = $entry['id']; + } + } else { + $brokenIds[] = $entry['id']; + } + } + $result->closeCursor(); + // delete broken object properties + $qb = $this->db->getQueryBuilder(); + $qb->delete('properties') + ->where($qb->expr()->in('id', $qb->createParameter('ids'), IQueryBuilder::PARAM_STR_ARRAY)); + foreach (array_chunk($brokenIds, 1000) as $chunkIds) { + $qb->setParameter('ids', $chunkIds, IQueryBuilder::PARAM_STR_ARRAY); + $qb->executeStatement(); + } + $total = count($brokenIds); + $output->info("$total broken object properties removed"); + } +} |