From ec454e7c2ba342c246cd5b039eda3a269f99fe2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Tue, 26 Jan 2021 10:26:10 +0100 Subject: Fix valid storages removed when cleaning remote storages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The remote URL of a share is always stored in the database with a trailing slash. However, when a cloud ID is generated trailing slashes are removed. The ID of a remote storage is generated from the cloud ID, but the "cleanup-remote-storage" command directly used the remote URL stored in the database. Due to this, even if the remote storage was valid, its ID did not match the ID of the remote share generated by the command and ended being removed. Now the command generates the ID of remote shares using the cloud ID instead, just like done by the remote storage, so there is no longer a mismatch. Signed-off-by: Daniel Calviño Sánchez --- apps/files_sharing/lib/Command/CleanupRemoteStorages.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'apps/files_sharing/lib') diff --git a/apps/files_sharing/lib/Command/CleanupRemoteStorages.php b/apps/files_sharing/lib/Command/CleanupRemoteStorages.php index 259e55ff620..ab63df4559c 100644 --- a/apps/files_sharing/lib/Command/CleanupRemoteStorages.php +++ b/apps/files_sharing/lib/Command/CleanupRemoteStorages.php @@ -25,6 +25,7 @@ namespace OCA\Files_Sharing\Command; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Federation\ICloudIdManager; use OCP\IDBConnection; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -42,8 +43,14 @@ class CleanupRemoteStorages extends Command { */ protected $connection; - public function __construct(IDBConnection $connection) { + /** + * @var ICloudIdManager + */ + private $cloudIdManager; + + public function __construct(IDBConnection $connection, ICloudIdManager $cloudIdManager) { $this->connection = $connection; + $this->cloudIdManager = $cloudIdManager; parent::__construct(); } @@ -166,14 +173,17 @@ class CleanupRemoteStorages extends Command { public function getRemoteShareIds() { $queryBuilder = $this->connection->getQueryBuilder(); - $queryBuilder->select(['id', 'share_token', 'remote']) + $queryBuilder->select(['id', 'share_token', 'owner', 'remote']) ->from('share_external'); $query = $queryBuilder->execute(); $remoteShareIds = []; while ($row = $query->fetch()) { - $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); + $cloudId = $this->cloudIdManager->getCloudId($row['owner'], $row['remote']); + $remote = $cloudId->getRemote(); + + $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $remote); } return $remoteShareIds; -- cgit v1.2.3