From f68f67f354a163574c56b55245d3473ebba79cea 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 1/8] 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 1374c8b0ee..c4d891d9c2 100644 --- a/apps/federatedfilesharing/composer/composer/autoload_classmap.php +++ b/apps/federatedfilesharing/composer/composer/autoload_classmap.php @@ -16,6 +16,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 52c7e01c9e..25e8c027d9 100644 --- a/apps/federatedfilesharing/composer/composer/autoload_static.php +++ b/apps/federatedfilesharing/composer/composer/autoload_static.php @@ -31,6 +31,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 395d34cc7e..ffd76784bc 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 3dfb5de723..63acc648d5 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 87146dd426..7a2578ef05 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 bb21e87d2321af184f720200b4f8826892f00055 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 2/8] 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 f15f52d184..887e77ef47 100644 --- a/apps/files_sharing/composer/composer/autoload_classmap.php +++ b/apps/files_sharing/composer/composer/autoload_classmap.php @@ -63,6 +63,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 4d52456550..a3499b4125 100644 --- a/apps/files_sharing/composer/composer/autoload_static.php +++ b/apps/files_sharing/composer/composer/autoload_static.php @@ -78,6 +78,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 8f6c2ec357dd9fcc71f2f8fb69a325004b36b98b 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 3/8] 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 7929e9c396..348228629b 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -627,12 +627,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 1b52e978e95ece068382ebba9f9fe93c17273dd9 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 4/8] 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 98deb1bd071f9de1d307fd83f7fd8c11f5e426a6 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 5/8] 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 aefe8262023f5f3daaa33a33e6b31c8e12e33112 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 6/8] 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 ++-- apps/files_sharing/lib/External/Manager.php | 2 +- .../Version11300Date20201120141438.php | 46 ++++++++++++++++++- .../tests/External/ManagerTest.php | 5 +- 7 files changed, 73 insertions(+), 11 deletions(-) diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php index ffd76784bc..0dc344ec9c 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 63acc648d5..c683c8de8b 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/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index 7a2578ef05..d02ac97ba3 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); 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 4f927721b2183ca45d2c5211ac341f67c9bc62d6 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 7/8] 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 b7326046c6395c50a6083b57f5f919882f5098b7 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 8/8] 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 | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 9539709e42..8fba63b22e 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -1113,21 +1113,13 @@ - - $remoteId - $token - - - list($token, $remoteId) - $shares getSharesInFolder - - $share->getId() + $shareId $shareId $shareId @@ -1136,10 +1128,7 @@ - - [$ocmResult['token'], $ocmResult['providerId']] - - + bool bool bool @@ -1153,13 +1142,12 @@ string - + $id $id $id $id $id - $remoteId (int)$share['id']