Skip to content
Merged
Prev Previous commit
Next Next commit
Adjust default
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Dec 14, 2020
commit 3cf7041c94a8b02fd815a58798ff04918e4d5d63
2 changes: 1 addition & 1 deletion apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public function getRemoteId(IShare $share): string {
throw new ShareNotFound();
}

return (int)$data['remote_id'];
return (string)$data['remote_id'];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
'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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@
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();
Expand All @@ -41,6 +50,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$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('');
Expand All @@ -50,4 +60,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

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();
}
}
8 changes: 4 additions & 4 deletions apps/federatedfilesharing/lib/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ public function sendRemoteShare($token, $shareWith, $name, $remoteId, $owner, $o
*
* @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
*/
Expand Down Expand Up @@ -182,7 +182,7 @@ public function requestReShare($token, $id, $shareId, $remote, $shareWith, $perm
* 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
*/
Expand All @@ -194,7 +194,7 @@ public function sendRemoteUnShare($remote, $id, $token) {
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,48 @@

declare(strict_types=1);

/*
* @copyright Copyright (c) 2020 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @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();
Expand All @@ -35,9 +67,9 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
'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,
Expand Down Expand Up @@ -79,11 +111,21 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$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();
}
}
5 changes: 3 additions & 2 deletions apps/files_sharing/tests/External/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function testAddShare() {
'shareType' => IShare::TYPE_USER,
'accepted' => false,
'user' => $this->uid,
'remote_id' => '2342'
];
$shareData2 = $shareData1;
$shareData2['token'] = 'token2';
Expand All @@ -158,8 +159,8 @@ public function testAddShare() {
$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));
Expand Down