From 62ecb57c7f314260dbf6f31940e7b3405498c5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 20 Nov 2020 13:29:36 +0100 Subject: [PATCH 01/11] Move remoteId of remote reshares to string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + .../lib/FederatedShareProvider.php | 6 +-- .../Version1010Date20200630191755.php | 4 +- .../Version1011Date20201120125158.php | 51 +++++++++++++++++++ .../lib/Notifications.php | 22 ++++---- apps/files_sharing/lib/External/Manager.php | 6 +-- 7 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php diff --git a/apps/federatedfilesharing/composer/composer/autoload_classmap.php b/apps/federatedfilesharing/composer/composer/autoload_classmap.php index 8d1364c0d6..0b07303e71 100644 --- a/apps/federatedfilesharing/composer/composer/autoload_classmap.php +++ b/apps/federatedfilesharing/composer/composer/autoload_classmap.php @@ -15,6 +15,7 @@ return array( 'OCA\\FederatedFileSharing\\FederatedShareProvider' => $baseDir . '/../lib/FederatedShareProvider.php', 'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/LoadAdditionalScriptsListener.php', 'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => $baseDir . '/../lib/Migration/Version1010Date20200630191755.php', + 'OCA\\FederatedFileSharing\\Migration\\Version1011Date20201120125158' => $baseDir . '/../lib/Migration/Version1011Date20201120125158.php', 'OCA\\FederatedFileSharing\\Notifications' => $baseDir . '/../lib/Notifications.php', 'OCA\\FederatedFileSharing\\Notifier' => $baseDir . '/../lib/Notifier.php', 'OCA\\FederatedFileSharing\\OCM\\CloudFederationProviderFiles' => $baseDir . '/../lib/OCM/CloudFederationProviderFiles.php', diff --git a/apps/federatedfilesharing/composer/composer/autoload_static.php b/apps/federatedfilesharing/composer/composer/autoload_static.php index 6e352d6f32..97ff383b90 100644 --- a/apps/federatedfilesharing/composer/composer/autoload_static.php +++ b/apps/federatedfilesharing/composer/composer/autoload_static.php @@ -30,6 +30,7 @@ class ComposerStaticInitFederatedFileSharing 'OCA\\FederatedFileSharing\\FederatedShareProvider' => __DIR__ . '/..' . '/../lib/FederatedShareProvider.php', 'OCA\\FederatedFileSharing\\Listeners\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadAdditionalScriptsListener.php', 'OCA\\FederatedFileSharing\\Migration\\Version1010Date20200630191755' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191755.php', + 'OCA\\FederatedFileSharing\\Migration\\Version1011Date20201120125158' => __DIR__ . '/..' . '/../lib/Migration/Version1011Date20201120125158.php', 'OCA\\FederatedFileSharing\\Notifications' => __DIR__ . '/..' . '/../lib/Notifications.php', 'OCA\\FederatedFileSharing\\Notifier' => __DIR__ . '/..' . '/../lib/Notifier.php', 'OCA\\FederatedFileSharing\\OCM\\CloudFederationProviderFiles' => __DIR__ . '/..' . '/../lib/OCM/CloudFederationProviderFiles.php', diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index 2e2f0d8adb..4d60744fe3 100644 --- a/apps/federatedfilesharing/lib/FederatedShareProvider.php +++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php @@ -462,7 +462,7 @@ class FederatedShareProvider implements IShareProvider { * @param $shareId * @param $remoteId */ - public function storeRemoteId($shareId, $remoteId) { + public function storeRemoteId(int $shareId, string $remoteId): void { $query = $this->dbConnection->getQueryBuilder(); $query->insert('federated_reshares') ->values( @@ -478,10 +478,10 @@ class FederatedShareProvider implements IShareProvider { * get share ID on remote server for federated re-shares * * @param IShare $share - * @return int + * @return string * @throws ShareNotFound */ - public function getRemoteId(IShare $share) { + public function getRemoteId(IShare $share): string { $query = $this->dbConnection->getQueryBuilder(); $query->select('remote_id')->from('federated_reshares') ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); diff --git a/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php b/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php index bf0d0f8eec..b8d498f322 100644 --- a/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php +++ b/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php @@ -48,9 +48,9 @@ class Version1010Date20200630191755 extends SimpleMigrationStep { 'notnull' => true, 'length' => 4, ]); - $table->addColumn('remote_id', Types::INTEGER, [ + $table->addColumn('remote_id', Types::STRING, [ 'notnull' => true, - 'length' => 4, + 'length' => 255, ]); $table->setPrimaryKey(['share_id'], 'federated_res_pk'); // $table->addUniqueIndex(['share_id'], 'share_id_index'); diff --git a/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php b/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php new file mode 100644 index 0000000000..c3fc22db8e --- /dev/null +++ b/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php @@ -0,0 +1,51 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +declare(strict_types=1); + +namespace OCA\FederatedFileSharing\Migration; + +use Closure; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +class Version1011Date20201120125158 extends SimpleMigrationStep { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if ($schema->hasTable('federated_reshares')) { + $table = $schema->getTable('federated_reshares'); + $remoteIdColumn = $table->getColumn('remote_id'); + if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { + $remoteIdColumn->setType(Type::getType(Types::STRING)); + $remoteIdColumn->setOptions(['length' => 255]); + } + } + + return $schema; + } +} diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php index 61513cd229..5df3c4af89 100644 --- a/apps/federatedfilesharing/lib/Notifications.php +++ b/apps/federatedfilesharing/lib/Notifications.php @@ -83,7 +83,7 @@ class Notifications { * @param string $token * @param string $shareWith * @param string $name - * @param int $remote_id + * @param string $remoteId * @param string $owner * @param string $ownerFederatedId * @param string $sharedBy @@ -93,7 +93,7 @@ class Notifications { * @throws \OC\HintException * @throws \OC\ServerNotAvailableException */ - public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId, $shareType) { + public function sendRemoteShare($token, $shareWith, $name, $remoteId, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId, $shareType) { list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); if ($user && $remote) { @@ -103,7 +103,7 @@ class Notifications { 'shareWith' => $user, 'token' => $token, 'name' => $name, - 'remoteId' => $remote_id, + 'remoteId' => $remoteId, 'owner' => $owner, 'ownerFederatedId' => $ownerFederatedId, 'sharedBy' => $sharedBy, @@ -132,13 +132,13 @@ class Notifications { * ask owner to re-share the file with the given user * * @param string $token - * @param int $id remote Id + * @param string $id remote Id * @param int $shareId internal share Id * @param string $remote remote address of the owner * @param string $shareWith * @param int $permission * @param string $filename - * @return bool + * @return array * @throws \OC\HintException * @throws \OC\ServerNotAvailableException */ @@ -151,7 +151,7 @@ class Notifications { ]; $ocmFields = $fields; - $ocmFields['remoteId'] = $id; + $ocmFields['remoteId'] = (string)$id; $ocmFields['localId'] = $shareId; $ocmFields['name'] = $filename; @@ -171,7 +171,7 @@ class Notifications { if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { return [ $status['ocs']['data']['token'], - (int)$status['ocs']['data']['remoteId'] + $status['ocs']['data']['remoteId'] ]; } @@ -206,7 +206,7 @@ class Notifications { * send notification to remote server if the permissions was changed * * @param string $remote - * @param int $remoteId + * @param string $remoteId * @param string $token * @param int $permissions * @return bool @@ -219,7 +219,7 @@ class Notifications { * forward accept reShare to remote server * * @param string $remote - * @param int $remoteId + * @param string $remoteId * @param string $token */ public function sendAcceptShare($remote, $remoteId, $token) { @@ -230,7 +230,7 @@ class Notifications { * forward decline reShare to remote server * * @param string $remote - * @param int $remoteId + * @param string $remoteId * @param string $token */ public function sendDeclineShare($remote, $remoteId, $token) { @@ -242,7 +242,7 @@ class Notifications { * * @param string $remote * @param string $token - * @param int $remoteId Share id on the remote host + * @param string $remoteId Share id on the remote host * @param string $action possible actions: accept, decline, unshare, revoke, permissions * @param array $data * @param int $try diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index 526e4fcce4..e59c98b07c 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -126,7 +126,7 @@ class Manager { * @param int $shareType * @param boolean $accepted * @param string $user - * @param int $remoteId + * @param string $remoteId * @param int $parent * @return Mount|null * @throws \Doctrine\DBAL\DBALException @@ -347,7 +347,7 @@ class Manager { * * @param string $remote * @param string $token - * @param int $remoteId Share id on the remote host + * @param string $remoteId Share id on the remote host * @param string $feedback * @return boolean */ @@ -388,7 +388,7 @@ class Manager { * * @param string $remoteDomain * @param string $token - * @param $remoteId id of the share + * @param string $remoteId id of the share * @param string $feedback * @return bool */ From 40a8bb53b1c231876a09e0d43737905234416e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 20 Nov 2020 15:30:36 +0100 Subject: [PATCH 02/11] Migrate files_sharing to migrations and move remote_id to a string in share_external MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../Version1011Date20201120125158.php | 6 +- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + .../Version11300Date20201120141438.php | 90 +++++++++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 apps/files_sharing/lib/Migration/Version11300Date20201120141438.php diff --git a/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php b/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php index c3fc22db8e..1f32f2cced 100644 --- a/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php +++ b/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php @@ -36,16 +36,18 @@ class Version1011Date20201120125158 extends SimpleMigrationStep { public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - + if ($schema->hasTable('federated_reshares')) { $table = $schema->getTable('federated_reshares'); $remoteIdColumn = $table->getColumn('remote_id'); if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { $remoteIdColumn->setType(Type::getType(Types::STRING)); $remoteIdColumn->setOptions(['length' => 255]); + $remoteIdColumn->setDefault(''); + return $schema; } } - return $schema; + return null; } } diff --git a/apps/files_sharing/composer/composer/autoload_classmap.php b/apps/files_sharing/composer/composer/autoload_classmap.php index 4ba8d1659a..a29e3879e0 100644 --- a/apps/files_sharing/composer/composer/autoload_classmap.php +++ b/apps/files_sharing/composer/composer/autoload_classmap.php @@ -62,6 +62,7 @@ return array( 'OCA\\Files_Sharing\\Migration\\OwncloudGuestShareType' => $baseDir . '/../lib/Migration/OwncloudGuestShareType.php', 'OCA\\Files_Sharing\\Migration\\SetAcceptedStatus' => $baseDir . '/../lib/Migration/SetAcceptedStatus.php', 'OCA\\Files_Sharing\\Migration\\SetPasswordColumn' => $baseDir . '/../lib/Migration/SetPasswordColumn.php', + 'OCA\\Files_Sharing\\Migration\\Version11300Date20201120141438' => $baseDir . '/../lib/Migration/Version11300Date20201120141438.php', 'OCA\\Files_Sharing\\MountProvider' => $baseDir . '/../lib/MountProvider.php', 'OCA\\Files_Sharing\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php', 'OCA\\Files_Sharing\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', diff --git a/apps/files_sharing/composer/composer/autoload_static.php b/apps/files_sharing/composer/composer/autoload_static.php index 4376ad0b82..523f2bc194 100644 --- a/apps/files_sharing/composer/composer/autoload_static.php +++ b/apps/files_sharing/composer/composer/autoload_static.php @@ -77,6 +77,7 @@ class ComposerStaticInitFiles_Sharing 'OCA\\Files_Sharing\\Migration\\OwncloudGuestShareType' => __DIR__ . '/..' . '/../lib/Migration/OwncloudGuestShareType.php', 'OCA\\Files_Sharing\\Migration\\SetAcceptedStatus' => __DIR__ . '/..' . '/../lib/Migration/SetAcceptedStatus.php', 'OCA\\Files_Sharing\\Migration\\SetPasswordColumn' => __DIR__ . '/..' . '/../lib/Migration/SetPasswordColumn.php', + 'OCA\\Files_Sharing\\Migration\\Version11300Date20201120141438' => __DIR__ . '/..' . '/../lib/Migration/Version11300Date20201120141438.php', 'OCA\\Files_Sharing\\MountProvider' => __DIR__ . '/..' . '/../lib/MountProvider.php', 'OCA\\Files_Sharing\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php', 'OCA\\Files_Sharing\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', diff --git a/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php b/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php new file mode 100644 index 0000000000..84c8721dec --- /dev/null +++ b/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php @@ -0,0 +1,90 @@ +hasTable('share_external')) { + $table = $schema->createTable('share_external'); + $table->addColumn('id', Types::INTEGER, [ + 'autoincrement' => true, + 'notnull' => true, + ]); + $table->addColumn('parent', Types::INTEGER, [ + 'notnull' => false, + 'default' => -1, + ]); + $table->addColumn('share_type', Types::INTEGER, [ + 'notnull' => false, + 'length' => 4, + ]); + $table->addColumn('remote', Types::STRING, [ + 'notnull' => true, + 'length' => 512, + ]); + $table->addColumn('remote_id', Types::STRING, [ + 'notnull' => true, + 'length' => 255, + 'default' => -1, + ]); + $table->addColumn('share_token', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $table->addColumn('password', Types::STRING, [ + 'notnull' => false, + 'length' => 64, + ]); + $table->addColumn('name', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $table->addColumn('owner', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $table->addColumn('user', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + ]); + $table->addColumn('mountpoint', Types::STRING, [ + 'notnull' => true, + 'length' => 4000, + ]); + $table->addColumn('mountpoint_hash', Types::STRING, [ + 'notnull' => true, + 'length' => 32, + ]); + $table->addColumn('accepted', Types::INTEGER, [ + 'notnull' => true, + 'length' => 4, + 'default' => 0, + ]); + $table->setPrimaryKey(['id']); + $table->addIndex(['user'], 'sh_external_user'); + $table->addUniqueIndex(['user', 'mountpoint_hash'], 'sh_external_mp'); + } else { + $table = $schema->getTable('share_external'); + $remoteIdColumn = $table->getColumn('remote_id'); + if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { + $remoteIdColumn->setType(Type::getType(Types::STRING)); + $remoteIdColumn->setOptions(['length' => 255]); + } + } + + return $schema; + } + +} From 58f6238af268db46b37a9c28c90d01944f6e6c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 20 Nov 2020 15:38:59 +0100 Subject: [PATCH 03/11] Move columns to bigint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../lib/Migration/Version1010Date20200630191755.php | 3 +-- .../lib/Migration/Version11300Date20201120141438.php | 5 ++--- apps/settings/lib/Controller/CheckSetupController.php | 2 ++ core/Command/Db/ConvertFilecacheBigInt.php | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php b/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php index b8d498f322..7376c8d9e7 100644 --- a/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php +++ b/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php @@ -44,9 +44,8 @@ class Version1010Date20200630191755 extends SimpleMigrationStep { if (!$schema->hasTable('federated_reshares')) { $table = $schema->createTable('federated_reshares'); - $table->addColumn('share_id', Types::INTEGER, [ + $table->addColumn('share_id', Types::BIGINT, [ 'notnull' => true, - 'length' => 4, ]); $table->addColumn('remote_id', Types::STRING, [ 'notnull' => true, diff --git a/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php b/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php index 84c8721dec..6183324982 100644 --- a/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php +++ b/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php @@ -18,11 +18,11 @@ class Version11300Date20201120141438 extends SimpleMigrationStep { if (!$schema->hasTable('share_external')) { $table = $schema->createTable('share_external'); - $table->addColumn('id', Types::INTEGER, [ + $table->addColumn('id', Types::BIGINT, [ 'autoincrement' => true, 'notnull' => true, ]); - $table->addColumn('parent', Types::INTEGER, [ + $table->addColumn('parent', Types::BIGINT, [ 'notnull' => false, 'default' => -1, ]); @@ -86,5 +86,4 @@ class Version11300Date20201120141438 extends SimpleMigrationStep { return $schema; } - } diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 8a0536c29f..19d932ecc4 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -630,12 +630,14 @@ Raw output 'activity_mq' => ['mail_id'], 'authtoken' => ['id'], 'bruteforce_attempts' => ['id'], + 'federated_reshares' => ['share_id'], 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'], 'filecache_extended' => ['fileid'], 'file_locks' => ['id'], 'jobs' => ['id'], 'mimetypes' => ['id'], 'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'], + 'share_external' => ['id', 'parent'], 'storages' => ['numeric_id'], ]; diff --git a/core/Command/Db/ConvertFilecacheBigInt.php b/core/Command/Db/ConvertFilecacheBigInt.php index 6b5b0dc9c8..6575d41d3b 100644 --- a/core/Command/Db/ConvertFilecacheBigInt.php +++ b/core/Command/Db/ConvertFilecacheBigInt.php @@ -64,12 +64,14 @@ class ConvertFilecacheBigInt extends Command { 'activity_mq' => ['mail_id'], 'authtoken' => ['id'], 'bruteforce_attempts' => ['id'], + 'federated_reshares' => ['share_id'], 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'], 'filecache_extended' => ['fileid'], 'file_locks' => ['id'], 'jobs' => ['id'], 'mimetypes' => ['id'], 'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'], + 'share_external' => ['id', 'parent'], 'storages' => ['numeric_id'], ]; } From e97897cfa5210025daeaa160e6337b9501e21e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 20 Nov 2020 15:40:30 +0100 Subject: [PATCH 04/11] Get rid of database.xml in files_sharing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files_sharing/appinfo/database.xml | 120 ------------------------ 1 file changed, 120 deletions(-) delete mode 100644 apps/files_sharing/appinfo/database.xml diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml deleted file mode 100644 index c3cfb9e1c8..0000000000 --- a/apps/files_sharing/appinfo/database.xml +++ /dev/null @@ -1,120 +0,0 @@ - - - *dbname* - true - false - utf8 - - *dbprefix*share_external - - - id - integer - 0 - true - 1 - 4 - - - parent - integer - -1 - 4 - - - share_type - integer - 4 - - - remote - text - true - 512 - Url of the remove owncloud instance - - - remote_id - integer - -1 - true - 4 - - - share_token - text - true - 64 - Public share token - - - password - text - false - 64 - Optional password for the public share - - - name - text - true - 64 - Original name on the remote server - - - owner - text - true - 64 - User that owns the public share on the remote server - - - user - text - true - 64 - Local user which added the external share - - - mountpoint - text - true - 4000 - Full path where the share is mounted - - - mountpoint_hash - text - true - 32 - md5 hash of the mountpoint - - - accepted - integer - 0 - true - 4 - - - sh_external_user - - user - ascending - - - - sh_external_mp - true - - user - ascending - - - mountpoint_hash - ascending - - - -
-
From ff544a288092e32a85211250b20726239135a783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 3 Dec 2020 16:08:41 +0100 Subject: [PATCH 05/11] Do not register share menu in cases where the files app has not been registered yet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files_sharing/lib/AppInfo/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index fd71f58f12..078a0a5f59 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -168,7 +168,7 @@ class Application extends App { protected function setupSharingMenus() { $config = \OC::$server->getConfig(); - if ($config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { + if ($config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes' || !class_exists('\OCA\Files\App')) { return; } From 3cf7041c94a8b02fd815a58798ff04918e4d5d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 3 Dec 2020 17:39:56 +0100 Subject: [PATCH 06/11] Adjust default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../lib/FederatedShareProvider.php | 2 +- .../Version1010Date20200630191755.php | 3 +- .../Version1011Date20201120125158.php | 18 ++++++++ .../lib/Notifications.php | 8 ++-- .../Version11300Date20201120141438.php | 46 ++++++++++++++++++- .../tests/External/ManagerTest.php | 5 +- 6 files changed, 72 insertions(+), 10 deletions(-) diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index 4d60744fe3..13348a1d7b 100644 --- a/apps/federatedfilesharing/lib/FederatedShareProvider.php +++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php @@ -493,7 +493,7 @@ class FederatedShareProvider implements IShareProvider { throw new ShareNotFound(); } - return (int)$data['remote_id']; + return (string)$data['remote_id']; } /** diff --git a/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php b/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php index 7376c8d9e7..afd41c20f6 100644 --- a/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php +++ b/apps/federatedfilesharing/lib/Migration/Version1010Date20200630191755.php @@ -48,8 +48,9 @@ class Version1010Date20200630191755 extends SimpleMigrationStep { 'notnull' => true, ]); $table->addColumn('remote_id', Types::STRING, [ - 'notnull' => true, + 'notnull' => false, 'length' => 255, + 'default' => '', ]); $table->setPrimaryKey(['share_id'], 'federated_res_pk'); // $table->addUniqueIndex(['share_id'], 'share_id_index'); diff --git a/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php b/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php index 1f32f2cced..e89838c06f 100644 --- a/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php +++ b/apps/federatedfilesharing/lib/Migration/Version1011Date20201120125158.php @@ -29,10 +29,19 @@ use Closure; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use OCP\DB\ISchemaWrapper; +use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; class Version1011Date20201120125158 extends SimpleMigrationStep { + + /** @var IDBConnection */ + private $connection; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); @@ -41,6 +50,7 @@ class Version1011Date20201120125158 extends SimpleMigrationStep { $table = $schema->getTable('federated_reshares'); $remoteIdColumn = $table->getColumn('remote_id'); if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { + $remoteIdColumn->setNotnull(false); $remoteIdColumn->setType(Type::getType(Types::STRING)); $remoteIdColumn->setOptions(['length' => 255]); $remoteIdColumn->setDefault(''); @@ -50,4 +60,12 @@ class Version1011Date20201120125158 extends SimpleMigrationStep { return null; } + + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + $qb = $this->connection->getQueryBuilder(); + $qb->update('federated_reshares') + ->set('remote_id', $qb->createNamedParameter('')) + ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter('-1'))); + $qb->execute(); + } } diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php index 5df3c4af89..b0add6befb 100644 --- a/apps/federatedfilesharing/lib/Notifications.php +++ b/apps/federatedfilesharing/lib/Notifications.php @@ -133,12 +133,12 @@ class Notifications { * * @param string $token * @param string $id remote Id - * @param int $shareId internal share Id + * @param string $shareId internal share Id * @param string $remote remote address of the owner * @param string $shareWith * @param int $permission * @param string $filename - * @return array + * @return array|false * @throws \OC\HintException * @throws \OC\ServerNotAvailableException */ @@ -182,7 +182,7 @@ class Notifications { * send server-to-server unshare to remote server * * @param string $remote url - * @param int $id share id + * @param string $id share id * @param string $token * @return bool */ @@ -194,7 +194,7 @@ class Notifications { * send server-to-server unshare to remote server * * @param string $remote url - * @param int $id share id + * @param string $id share id * @param string $token * @return bool */ diff --git a/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php b/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php index 6183324982..dfc5bc68a0 100644 --- a/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php +++ b/apps/files_sharing/lib/Migration/Version11300Date20201120141438.php @@ -2,16 +2,48 @@ declare(strict_types=1); +/* + * @copyright Copyright (c) 2020 Julius Härtl + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + namespace OCA\Files_Sharing\Migration; use Closure; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use OCP\DB\ISchemaWrapper; +use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; class Version11300Date20201120141438 extends SimpleMigrationStep { + + /** @var IDBConnection */ + private $connection; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); @@ -35,9 +67,9 @@ class Version11300Date20201120141438 extends SimpleMigrationStep { 'length' => 512, ]); $table->addColumn('remote_id', Types::STRING, [ - 'notnull' => true, + 'notnull' => false, 'length' => 255, - 'default' => -1, + 'default' => '', ]); $table->addColumn('share_token', Types::STRING, [ 'notnull' => true, @@ -79,11 +111,21 @@ class Version11300Date20201120141438 extends SimpleMigrationStep { $table = $schema->getTable('share_external'); $remoteIdColumn = $table->getColumn('remote_id'); if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { + $remoteIdColumn->setNotnull(false); $remoteIdColumn->setType(Type::getType(Types::STRING)); $remoteIdColumn->setOptions(['length' => 255]); + $remoteIdColumn->setDefault(''); } } return $schema; } + + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + $qb = $this->connection->getQueryBuilder(); + $qb->update('share_external') + ->set('remote_id', $qb->createNamedParameter('')) + ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter('-1'))); + $qb->execute(); + } } diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index 22005c8fc6..2734e3cce6 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -149,6 +149,7 @@ class ManagerTest extends TestCase { 'shareType' => IShare::TYPE_USER, 'accepted' => false, 'user' => $this->uid, + 'remote_id' => '2342' ]; $shareData2 = $shareData1; $shareData2['token'] = 'token2'; @@ -158,8 +159,8 @@ class ManagerTest extends TestCase { $this->userManager->expects($this->any())->method('get')->willReturn($this->user); $this->groupManager->expects($this->any())->method(('getUserGroups'))->willReturn([]); - $this->manager->expects($this->at(0))->method('tryOCMEndPoint')->with('http://localhost', 'token1', -1, 'accept')->willReturn(false); - $this->manager->expects($this->at(1))->method('tryOCMEndPoint')->with('http://localhost', 'token3', -1, 'decline')->willReturn(false); + $this->manager->expects($this->at(0))->method('tryOCMEndPoint')->with('http://localhost', 'token1', '2342', 'accept')->willReturn(false); + $this->manager->expects($this->at(1))->method('tryOCMEndPoint')->with('http://localhost', 'token3', '2342', 'decline')->willReturn(false); // Add a share for "user" $this->assertSame(null, call_user_func_array([$this->manager, 'addShare'], $shareData1)); From ace90466d600f18fd9f37e9758b3a01aed9e88a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 4 Dec 2020 08:23:12 +0100 Subject: [PATCH 07/11] Add temporary test for migrating int to string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- tests/lib/DB/MigratorTest.php | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index b5021dcccf..52b0b0ff03 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -13,6 +13,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaConfig; +use OC\DB\SchemaWrapper; use OCP\IConfig; /** @@ -94,6 +95,26 @@ class MigratorTest extends \Test\TestCase { return [$startSchema, $endSchema]; } + /** + * @return \Doctrine\DBAL\Schema\Schema[] + */ + private function getChangedTypeSchema($from, $to) { + $startSchema = new Schema([], [], $this->getSchemaConfig()); + $table = $startSchema->createTable($this->tableName); + $table->addColumn('id', $from); + $table->addColumn('name', 'string'); + $table->addIndex(['id'], $this->tableName . '_id'); + + $endSchema = new Schema([], [], $this->getSchemaConfig()); + $table = $endSchema->createTable($this->tableName); + $table->addColumn('id', $to); + $table->addColumn('name', 'string'); + $table->addIndex(['id'], $this->tableName . '_id'); + + return [$startSchema, $endSchema]; + } + + private function getSchemaConfig() { $config = new SchemaConfig(); $config->setName($this->connection->getDatabase()); @@ -123,6 +144,34 @@ class MigratorTest extends \Test\TestCase { $this->fail('checkMigrate should have failed'); } + public function testChangeToString() { + list($startSchema, $endSchema) = $this->getChangedTypeSchema('integer', 'string'); + $migrator = $this->manager->getMigrator(); + $migrator->migrate($startSchema); + $schema = new SchemaWrapper($this->connection); + $table = $schema->getTable(substr($this->tableName, 3)); + $this->assertEquals('integer', $table->getColumn('id')->getType()->getName()); + + $this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']); + $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); + $this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']); + + $migrator->checkMigrate($endSchema); + $migrator->migrate($endSchema); + $this->addToAssertionCount(1); + + $qb = $this->connection->getQueryBuilder(); + $result = $qb->select('*')->from(substr($this->tableName, 3))->execute(); + $this->assertEquals([ + ['id' => 1, 'name' => 'foo'], + ['id' => 2, 'name' => 'bar'], + ['id' => 3, 'name' => 'qwerty'] + ], $result->fetchAll()); + $schema = new SchemaWrapper($this->connection); + $table = $schema->getTable(substr($this->tableName, 3)); + $this->assertEquals('string', $table->getColumn('id')->getType()->getName()); + } + public function testUpgrade() { list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); $migrator = $this->manager->getMigrator(); From 0bbc0dde10934d6d2f2c3dd1be28c2b45cb0c6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 4 Dec 2020 09:13:17 +0100 Subject: [PATCH 08/11] Update psalm baseline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- build/psalm-baseline.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index d00ea631e5..2d0c71a3d2 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -1234,10 +1234,7 @@ - - [$ocmResult['token'], $ocmResult['providerId']] - - + bool bool bool From e155943a3b623f0f331485e1646d074876b1470f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 11 Dec 2020 08:11:54 +0100 Subject: [PATCH 09/11] Resolve conflict in addShare parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files_sharing/lib/External/Manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index e59c98b07c..e4b28804fc 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -131,7 +131,7 @@ class Manager { * @return Mount|null * @throws \Doctrine\DBAL\DBALException */ - public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { + public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted = false, $user = null, $remoteId = '', $parent = -1) { $user = $user ? $user : $this->uid; $accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING; $name = Filesystem::normalizePath('/' . $name); From 05919a27b8f004b18fb1f9461198bcd4dee657f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 11 Dec 2020 13:29:22 +0100 Subject: [PATCH 10/11] Update psalm baseline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- build/psalm-baseline.xml | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 2d0c71a3d2..d6c0ce573a 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -760,7 +760,7 @@ string[] - + null $this->circleToPrincipal($name) null @@ -1211,25 +1211,17 @@ $qb->createNamedParameter($this->supportedShareType, IQueryBuilder::PARAM_INT_ARRAY) $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY) - - $token - $remoteId - - - list($token, $remoteId) - $shares getSharesInFolder - + $shareId $shareId $shareId $shareId - $share->getId() (int)$data['id'] @@ -1248,8 +1240,7 @@ string - - $remoteId + $id $id $id @@ -3397,9 +3388,6 @@ strtolower - - - $default @@ -4790,14 +4778,6 @@ true - - - $position - - - $cacheEntry - - false @@ -5526,7 +5506,7 @@ 'OCP\Share::postUnshareFromSelf' $data - + $this->shareApiLinkDefaultExpireDays() $this->shareApiLinkDefaultExpireDays() $id From 5c0e8c648b552fc4c1a51f92c960b956e3ef1bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 14 Dec 2020 11:11:56 +0100 Subject: [PATCH 11/11] Bump app versions for federatedfilesharing and files_sharing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/federatedfilesharing/appinfo/info.xml | 2 +- apps/files_sharing/appinfo/info.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/federatedfilesharing/appinfo/info.xml b/apps/federatedfilesharing/appinfo/info.xml index b30656fa51..05badd3bd7 100644 --- a/apps/federatedfilesharing/appinfo/info.xml +++ b/apps/federatedfilesharing/appinfo/info.xml @@ -5,7 +5,7 @@ Federated file sharing Provide federated file sharing across servers Provide federated file sharing across servers - 1.10.1 + 1.10.2 agpl Bjoern Schiessle Roeland Jago Douma diff --git a/apps/files_sharing/appinfo/info.xml b/apps/files_sharing/appinfo/info.xml index e9576dd1ad..492b34859b 100644 --- a/apps/files_sharing/appinfo/info.xml +++ b/apps/files_sharing/appinfo/info.xml @@ -9,7 +9,7 @@ Turning the feature off removes shared files and folders on the server for all share recipients, and also on the sync clients and mobile apps. More information is available in the Nextcloud Documentation. - 1.12.0 + 1.12.1 agpl Michael Gapczynski Bjoern Schiessle