Merge pull request #24654 from nextcloud/backport/24247/stable20

[stable20] Use string for storing a OCM remote id
This commit is contained in:
Roeland Jago Douma 2020-12-14 15:31:12 +01:00 committed by GitHub
commit 209d4c0ff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 297 additions and 180 deletions

View File

@ -5,7 +5,7 @@
<name>Federated file sharing</name>
<summary>Provide federated file sharing across servers</summary>
<description>Provide federated file sharing across servers</description>
<version>1.10.1</version>
<version>1.10.2</version>
<licence>agpl</licence>
<author>Bjoern Schiessle</author>
<author>Roeland Jago Douma</author>

View File

@ -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',

View File

@ -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',

View File

@ -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())));
@ -493,7 +493,7 @@ class FederatedShareProvider implements IShareProvider {
throw new ShareNotFound();
}
return (int)$data['remote_id'];
return (string)$data['remote_id'];
}
/**

View File

@ -44,13 +44,13 @@ 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::INTEGER, [
'notnull' => true,
'length' => 4,
$table->addColumn('remote_id', Types::STRING, [
'notnull' => false,
'length' => 255,
'default' => '',
]);
$table->setPrimaryKey(['share_id'], 'federated_res_pk');
// $table->addUniqueIndex(['share_id'], 'share_id_index');

View File

@ -0,0 +1,71 @@
<?php
/*
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
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\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();
if ($schema->hasTable('federated_reshares')) {
$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('');
return $schema;
}
}
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();
}
}

View File

@ -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 int $shareId internal share Id
* @param string $id remote 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 bool
* @return array|false
* @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']
];
}
@ -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
*/
@ -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

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<database>
<name>*dbname*</name>
<create>true</create>
<overwrite>false</overwrite>
<charset>utf8</charset>
<table>
<name>*dbprefix*share_external</name>
<declaration>
<field>
<name>id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>4</length>
</field>
<field>
<name>parent</name>
<type>integer</type>
<default>-1</default>
<length>4</length>
</field>
<field>
<name>share_type</name>
<type>integer</type>
<length>4</length>
</field>
<field>
<name>remote</name>
<type>text</type>
<notnull>true</notnull>
<length>512</length>
<comments>Url of the remove owncloud instance</comments>
</field>
<field>
<name>remote_id</name>
<type>integer</type>
<default>-1</default>
<notnull>true</notnull>
<length>4</length>
</field>
<field>
<name>share_token</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
<comments>Public share token</comments>
</field>
<field>
<name>password</name>
<type>text</type>
<notnull>false</notnull>
<length>64</length>
<comments>Optional password for the public share</comments>
</field>
<field>
<name>name</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
<comments>Original name on the remote server</comments>
</field>
<field>
<name>owner</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
<comments>User that owns the public share on the remote server</comments>
</field>
<field>
<name>user</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
<comments>Local user which added the external share</comments>
</field>
<field>
<name>mountpoint</name>
<type>text</type>
<notnull>true</notnull>
<length>4000</length>
<comments>Full path where the share is mounted</comments>
</field>
<field>
<name>mountpoint_hash</name>
<type>text</type>
<notnull>true</notnull>
<length>32</length>
<comments>md5 hash of the mountpoint</comments>
</field>
<field>
<name>accepted</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<length>4</length>
</field>
<index>
<name>sh_external_user</name>
<field>
<name>user</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>sh_external_mp</name>
<unique>true</unique>
<field>
<name>user</name>
<sorting>ascending</sorting>
</field>
<field>
<name>mountpoint_hash</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>
</database>

View File

@ -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.
</description>
<version>1.12.0</version>
<version>1.12.1</version>
<licence>agpl</licence>
<author>Michael Gapczynski</author>
<author>Bjoern Schiessle</author>

View File

@ -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',

View File

@ -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',

View File

@ -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;
}

View File

@ -126,12 +126,12 @@ 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
*/
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);
@ -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
*/

View File

@ -0,0 +1,131 @@
<?php
declare(strict_types=1);
/*
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
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();
if (!$schema->hasTable('share_external')) {
$table = $schema->createTable('share_external');
$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('parent', Types::BIGINT, [
'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' => false,
'length' => 255,
'default' => '',
]);
$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->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();
}
}

View File

@ -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));

View File

@ -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'],
];

View File

@ -760,7 +760,7 @@
<InvalidReturnType occurrences="1">
<code>string[]</code>
</InvalidReturnType>
<NullableReturnStatement occurrences="9">
<NullableReturnStatement occurrences="8">
<code>null</code>
<code>$this-&gt;circleToPrincipal($name)</code>
<code>null</code>
@ -1211,33 +1211,22 @@
<code>$qb-&gt;createNamedParameter($this-&gt;supportedShareType, IQueryBuilder::PARAM_INT_ARRAY)</code>
<code>$qb-&gt;createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)</code>
</ImplicitToStringCast>
<InvalidArrayAccess occurrences="2">
<code>$token</code>
<code>$remoteId</code>
</InvalidArrayAccess>
<InvalidArrayOffset occurrences="1">
<code>list($token, $remoteId)</code>
</InvalidArrayOffset>
<InvalidReturnStatement occurrences="1">
<code>$shares</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="1">
<code>getSharesInFolder</code>
</InvalidReturnType>
<InvalidScalarArgument occurrences="6">
<InvalidScalarArgument occurrences="5">
<code>$shareId</code>
<code>$shareId</code>
<code>$shareId</code>
<code>$shareId</code>
<code>$share-&gt;getId()</code>
<code>(int)$data['id']</code>
</InvalidScalarArgument>
</file>
<file src="apps/federatedfilesharing/lib/Notifications.php">
<InvalidReturnStatement occurrences="2">
<code>[$ocmResult['token'], $ocmResult['providerId']]</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="4">
<InvalidReturnType occurrences="3">
<code>bool</code>
<code>bool</code>
<code>bool</code>
@ -1251,8 +1240,7 @@
<InvalidReturnType occurrences="1">
<code>string</code>
</InvalidReturnType>
<InvalidScalarArgument occurrences="7">
<code>$remoteId</code>
<InvalidScalarArgument occurrences="6">
<code>$id</code>
<code>$id</code>
<code>$id</code>
@ -3400,9 +3388,6 @@
<code>strtolower</code>
</RedundantCondition>
</file>
<file src="lib/private/AppFramework/ScopedPsrLogger.php">
<InvalidArgument occurrences="1"/>
</file>
<file src="lib/private/AppFramework/Services/AppConfig.php">
<MoreSpecificImplementedParamType occurrences="1">
<code>$default</code>
@ -4793,14 +4778,6 @@
<code>true</code>
</InvalidReturnType>
</file>
<file src="lib/private/Files/Stream/Encryption.php">
<InvalidScalarArgument occurrences="1">
<code>$position</code>
</InvalidScalarArgument>
<UndefinedInterfaceMethod occurrences="1">
<code>$cacheEntry</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/private/Files/Stream/SeekableHttpStream.php">
<FalsableReturnStatement occurrences="3">
<code>false</code>
@ -5529,7 +5506,7 @@
<code>'OCP\Share::postUnshareFromSelf'</code>
<code>$data</code>
</InvalidArgument>
<InvalidScalarArgument occurrences="3">
<InvalidScalarArgument occurrences="2">
<code>$this-&gt;shareApiLinkDefaultExpireDays()</code>
<code>$this-&gt;shareApiLinkDefaultExpireDays()</code>
<code>$id</code>

View File

@ -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'],
];
}

View File

@ -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();