Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed May 9, 2022
1 parent 6f7969a commit 85636ca
Show file tree
Hide file tree
Showing 29 changed files with 2,517 additions and 437 deletions.
1 change: 1 addition & 0 deletions .php_cs.cache

Large diffs are not rendered by default.

493 changes: 493 additions & 0 deletions drafts/federated_sync.md

Large diffs are not rendered by default.

181 changes: 181 additions & 0 deletions lib/CircleSharesManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php

declare(strict_types=1);


/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <[email protected]>
* @copyright 2022
* @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\Circles;

use OCA\Circles\Exceptions\CircleSharesManagerException;
use OCA\Circles\Service\FederatedSyncService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
* Class CircleSharesManager
*
* @package OCA\Circles
*/
class CircleSharesManager implements ICircleSharesManager {


private FederatedSyncService $federatedSyncService;

/** @var IFederatedSyncManager[] */
private array $syncManager = [];
private string $originAppId;
private string $originItemType;


/**
* @param FederatedSyncService $federatedSyncService
*/
public function __construct(FederatedSyncService $federatedSyncService) {
$this->federatedSyncService = $federatedSyncService;
}


/**
* @param string $syncManager
* @param int $api
* @param int $apiLowerBackCompatibility
* @param bool $fullSupport
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function registerFederatedSyncManager(string $syncManager): void {
$federatedSyncManager = \OC::$server->get($syncManager);
if (!($federatedSyncManager instanceof IFederatedSyncManager)) {
// log something
return;
}

$this->syncManager[] = $federatedSyncManager;
}


/**
* @return IFederatedSyncManager[]
*/
public function getSyncManagers(): array {
return $this->syncManager;
}


/**
* @param string $itemId
* @param string $circleId
* @param array $extraData
*/
public function createShare(
string $itemId,
string $circleId,
array $extraData = []
): void {
$this->mustHaveOrigin();

$syncedItem = $this->federatedSyncService->getSyncedItem(
$this->originAppId,
$this->originItemType,
$itemId,
true
);

$this->federatedSyncService->createShare($syncedItem, $circleId);
// this->$this->federatedItemService->getSharedItem
}

/**
* @param string $itemId
* @param string $circleId
* @param array $extraData
*
* @throws CircleSharesManagerException
*/
public function updateShare(
string $itemId,
string $circleId,
array $extraData = []
): void {
$this->mustHaveOrigin();
}

/**
* @param string $itemId
* @param string $circleId
*
* @throws CircleSharesManagerException
*/
public function deleteShare(string $itemId, string $circleId): void {
$this->mustHaveOrigin();
}

/**
* @param string $itemId
* @param array $serializedData
*/
public function updateItem(
string $itemId,
array $serializedData
): void {
$this->mustHaveOrigin();
}

/**
* @param string $itemId
*
* @throws CircleSharesManagerException
*/
public function deleteItem(string $itemId): void {
$this->mustHaveOrigin();
}


/**
* @param string $appId
* @param string $itemType
*/
public function setOrigin(string $appId, string $itemType) {
$this->originAppId = $appId;
$this->originItemType = $itemType;
}

/**
* @throws CircleSharesManagerException
*/
private function mustHaveOrigin(): void {
if ($this->originAppId !== '' && $this->originItemType !== '') {
return;
}

throw new CircleSharesManagerException(
'ICirclesManager::getShareManager(appId, itemType) used empty params'
);
}
}
28 changes: 23 additions & 5 deletions lib/CirclesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,10 @@
use OCA\Circles\Service\MembershipService;
use OCA\Circles\Tools\Exceptions\InvalidItemException;

/**
* Class CirclesManager
*
* @package OCA\Circles
*/

class CirclesManager {

private CircleSharesManager $circleSharesManager;

/** @var FederatedUserService */
private $federatedUserService;
Expand All @@ -94,6 +91,7 @@ class CirclesManager {
/**
* CirclesManager constructor.
*
* @param CircleSharesManager $circleSharesManager
* @param FederatedUserService $federatedUserService
* @param CircleService $circleService
* @param MemberService $memberService
Expand All @@ -102,13 +100,15 @@ class CirclesManager {
* @param CirclesQueryHelper $circlesQueryHelper
*/
public function __construct(
CircleSharesManager $circleSharesManager,
FederatedUserService $federatedUserService,
CircleService $circleService,
MemberService $memberService,
MembershipService $membershipService,
ConfigService $configService,
CirclesQueryHelper $circlesQueryHelper
) {
$this->circleSharesManager = $circleSharesManager;
$this->federatedUserService = $federatedUserService;
$this->circleService = $circleService;
$this->memberService = $memberService;
Expand All @@ -118,6 +118,24 @@ public function __construct(
}


/**
* @param string $appId
* @param string $itemType
*
* @return CircleSharesManager
*/
public function getShareManager(string $appId = '', string $itemType = ''): ICircleSharesManager {
if ($appId === '') {
return $this->circleSharesManager;
}

$clone = clone $this->circleSharesManager;
$clone->setOrigin($appId, $itemType);

return $clone;
}


/**
* @param string $federatedId
* @param int $type
Expand Down
10 changes: 9 additions & 1 deletion lib/Db/CoreQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class CoreQueryBuilder extends ExtendedQueryBuilder {
public const TOKEN = 'tk';
public const OPTIONS = 'pt';
public const HELPER = 'hp';
public const SYNC_ITEM = 'si';
public const SYNC_SHARE = 'ss';
public const SYNC_LOCK = 'sl';
public const DEBUG = 'bg';


public static $SQL_PATH = [
Expand Down Expand Up @@ -227,7 +231,11 @@ class CoreQueryBuilder extends ExtendedQueryBuilder {
self::BASED_ON
]
]
]
],
self::SYNC_ITEM => [],
self::SYNC_SHARE => [],
self::SYNC_LOCK => [],
self::DEBUG => []
];


Expand Down
34 changes: 31 additions & 3 deletions lib/Db/CoreRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ class CoreRequestBuilder {
public const TABLE_MOUNT = 'circles_mount';
public const TABLE_MOUNTPOINT = 'circles_mountpoint';

// wip
public const TABLE_SHARE_LOCK = 'circles_share_lock';
public const TABLE_SYNC_ITEM = 'circles_item';
public const TABLE_SYNC_SHARE = 'circles_share';
public const TABLE_SYNC_LOCK = 'circles_lock';

public const TABLE_HISTORY = 'circles_history';

public const TABLE_TOKEN = 'circles_token';

public const TABLE_GSSHARES = 'circle_gsshares'; // rename ?
Expand Down Expand Up @@ -139,7 +143,31 @@ class CoreRequestBuilder {
'mountpoint_hash'
],
self::TABLE_MOUNTPOINT => [],
self::TABLE_SHARE_LOCK => [],
self::TABLE_SYNC_ITEM => [
'id',
'single_id',
'instance',
'app_id',
'item_type',
'item_id',
'checksum'
],
self::TABLE_SYNC_SHARE => [
'id',
'single_id',
'circle_id'
],
self::TABLE_SYNC_LOCK => [
'id',
'single_id',
'update_type',
'update_type_id',
'time'
],
self::TABLE_HISTORY => [
'id',
'time'
],
self::TABLE_TOKEN => [
'id',
'share_id',
Expand Down
61 changes: 61 additions & 0 deletions lib/Db/SyncedItemLockRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);


/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <[email protected]>
* @copyright 2022
* @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\Circles\Db;

use OCA\Circles\Exceptions\InvalidIdException;
use OCA\Circles\Model\SyncedItemLock;

/**
* Class SyncedItemLockRequest
*
* @package OCA\Circles\Db
*/
class SyncedItemLockRequest extends SyncedItemLockRequestBuilder {


/**
* @param SyncedItemLock $lock
*
* @throws InvalidIdException
*/
public function save(SyncedItemLock $lock): void {
$this->confirmValidIds([$lock->getSingleId()]);

$qb = $this->getSyncedItemLockInsertSql();
$qb->setValue('single_id', $qb->createNamedParameter($lock->getSingleId()))
->setValue('update_type', $qb->createNamedParameter($lock->getUpdateType()))
->setValue('update_type_id', $qb->createNamedParameter($lock->getUpdateTypeId()))
->setValue('time', $qb->createNamedParameter($lock->getTime()));

$qb->execute();
}
}
Loading

0 comments on commit 85636ca

Please sign in to comment.