diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2017-08-21 16:52:37 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2017-08-21 16:52:37 +0300 |
commit | 1f5a47070a433e389b2792aeb605c0cdbad79e44 (patch) | |
tree | 35f8b90aadeeef33737c2813f6b2d42069144a91 /lib | |
parent | 636cb5341855136fd83f3733f8ae2470889ec866 (diff) |
SharingFrame now use Circle insteal of circle_id/circle_name/circle_type
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Api/v1/Circles.php | 9 | ||||
-rw-r--r-- | lib/Circles/FileSharingBroadcaster.php | 4 | ||||
-rw-r--r-- | lib/Controller/SharesController.php | 11 | ||||
-rw-r--r-- | lib/Db/CirclesRequest.php | 10 | ||||
-rw-r--r-- | lib/Db/CirclesRequestBuilder.php | 58 | ||||
-rw-r--r-- | lib/Model/BaseMember.php | 2 | ||||
-rw-r--r-- | lib/Model/Circle.php | 22 | ||||
-rw-r--r-- | lib/Model/SharingFrame.php | 93 | ||||
-rw-r--r-- | lib/Service/BroadcastService.php | 2 | ||||
-rw-r--r-- | lib/Service/FederatedService.php | 21 | ||||
-rw-r--r-- | lib/Service/SharesService.php | 19 |
11 files changed, 138 insertions, 113 deletions
diff --git a/lib/Api/v1/Circles.php b/lib/Api/v1/Circles.php index ff51c575..9a9ffd2a 100644 --- a/lib/Api/v1/Circles.php +++ b/lib/Api/v1/Circles.php @@ -333,11 +333,10 @@ class Circles { $c = self::getContainer(); $frame = new SharingFrame((string)$source, (string)$type); - $frame->setCircleId($circleUniqueId); $frame->setPayload($payload); return $c->query('SharesService') - ->createFrame($frame, (string)$broadcaster); + ->createFrame($circleUniqueId, $frame, (string)$broadcaster); } @@ -421,9 +420,9 @@ class Circles { public static function generateCircleParameter(SharingFrame $frame) { return [ 'type' => 'circle', - 'id' => $frame->getCircleId(), - 'name' => $frame->getCircleName(), - 'link' => self::generateLink($frame->getCircleId()) + 'id' => $frame->getCircle()->getUniqueId(), + 'name' => $frame->getCircle()->getName(), + 'link' => self::generateLink($frame->getCircle()->getUniqueId()) ]; } }
\ No newline at end of file diff --git a/lib/Circles/FileSharingBroadcaster.php b/lib/Circles/FileSharingBroadcaster.php index 5d5c8b88..7c01e140 100644 --- a/lib/Circles/FileSharingBroadcaster.php +++ b/lib/Circles/FileSharingBroadcaster.php @@ -129,7 +129,7 @@ class FileSharingBroadcaster implements IBroadcaster { $share = $this->generateShare($payload['share']); if ($member->getType() === Member::TYPE_MAIL) { - $this->sharedByMail($frame->getCircleName(), $share, $member->getUserId()); + $this->sharedByMail($frame->getCircle()->getName(), $share, $member->getUserId()); } return true; @@ -239,7 +239,7 @@ class FileSharingBroadcaster implements IBroadcaster { $emailTemplate->addHeader(); $emailTemplate->addHeading($subject, false); - $emailTemplate->addBodyText($text . '\n ' . $this->l10n->t('Click the button below to open it.'), $text); + $emailTemplate->addBodyText($text . "\n " . $this->l10n->t('Click the button below to open it.'), $text); $emailTemplate->addBodyButton($this->l10n->t('Open »%s«', [$fileName]), $link); return $emailTemplate; diff --git a/lib/Controller/SharesController.php b/lib/Controller/SharesController.php index 7cac8335..dd632865 100644 --- a/lib/Controller/SharesController.php +++ b/lib/Controller/SharesController.php @@ -39,25 +39,24 @@ class SharesController extends BaseController { * @NoAdminRequired * @NoSubAdminRequired * - * @param string $uniqueId + * @param string $circleUniqueId * @param string $source * @param string $type * @param array $payload * * @return DataResponse */ - public function create($uniqueId, $source, $type, $payload) { + public function create($circleUniqueId, $source, $type, $payload) { try { $share = new SharingFrame($source, $type); - $share->setCircleId($uniqueId); $share->setPayload($payload); - $this->sharesService->createFrame($share); + $this->sharesService->createFrame($circleUniqueId, $share); } catch (\Exception $e) { return $this->fail( [ - 'circle_id' => $uniqueId, + 'circle_id' => $circleUniqueId, 'source' => $source, 'type' => $type, 'payload' => $payload, @@ -68,7 +67,7 @@ class SharesController extends BaseController { return $this->success( [ - 'circle_id' => $uniqueId, + 'circle_id' => $circleUniqueId, 'source' => $source, 'type' => $type, 'payload' => $payload diff --git a/lib/Db/CirclesRequest.php b/lib/Db/CirclesRequest.php index d05bd99a..3b50e029 100644 --- a/lib/Db/CirclesRequest.php +++ b/lib/Db/CirclesRequest.php @@ -289,9 +289,8 @@ class CirclesRequest extends CirclesRequestBuilder { * @param SharingFrame $frame */ public function saveFrame(SharingFrame $frame) { - $qb = $this->getSharesInsertSql(); - $qb->setValue('circle_id', $qb->createNamedParameter($frame->getCircleId())) + $qb->setValue('circle_id', $qb->createNamedParameter($frame->getCircle()->getUniqueId())) ->setValue('source', $qb->createNamedParameter($frame->getSource())) ->setValue('type', $qb->createNamedParameter($frame->getType())) ->setValue('headers', $qb->createNamedParameter($frame->getHeaders(true))) @@ -306,7 +305,7 @@ class CirclesRequest extends CirclesRequestBuilder { public function updateFrame(SharingFrame $frame) { $qb = $this->getSharesUpdateSql($frame->getUniqueId()); - $qb->set('circle_id', $qb->createNamedParameter($frame->getCircleId())) + $qb->set('circle_id', $qb->createNamedParameter($frame->getCircle()->getUniqueId())) ->set('source', $qb->createNamedParameter($frame->getSource())) ->set('type', $qb->createNamedParameter($frame->getType())) ->set('headers', $qb->createNamedParameter($frame->getHeaders(true))) @@ -364,13 +363,16 @@ class CirclesRequest extends CirclesRequestBuilder { $qb = $this->getSharesSelectSql(); $this->limitToUniqueId($qb, $frameUniqueId); $this->limitToCircleId($qb, $circleUniqueId); + $this->leftJoinCircle($qb); $cursor = $qb->execute(); $data = $cursor->fetch(); $cursor->closeCursor(); if ($data === false) { - throw new SharingFrameDoesNotExistException($this->l10n->t('Sharing Frame does not exist')); + throw new SharingFrameDoesNotExistException( + $this->l10n->t('Sharing Frame does not exist') + ); } $entry = $this->parseSharesSelectSql($data); diff --git a/lib/Db/CirclesRequestBuilder.php b/lib/Db/CirclesRequestBuilder.php index f6313bd1..b47137a1 100644 --- a/lib/Db/CirclesRequestBuilder.php +++ b/lib/Db/CirclesRequestBuilder.php @@ -181,7 +181,9 @@ class CirclesRequestBuilder extends CoreRequestBuilder { ->add( $expr->eq( $qb->createNamedParameter($circleUniqueId), - $qb->createFunction('SUBSTR(`c`.`unique_id`, 1, ' . Circle::UNIQUEID_SHORT_LENGTH . ')') + $qb->createFunction( + 'SUBSTR(`c`.`unique_id`, 1, ' . Circle::UNIQUEID_SHORT_LENGTH . ')' + ) ) ); @@ -263,7 +265,8 @@ class CirclesRequestBuilder extends CoreRequestBuilder { $expr->eq( 'u.circle_id', $qb->createFunction( - 'SUBSTR(' . $pf . '`unique_id`, 1, ' . Circle::UNIQUEID_SHORT_LENGTH . ')' + 'SUBSTR(' . $pf . '`unique_id`, 1, ' . Circle::UNIQUEID_SHORT_LENGTH + . ')' ) ), $expr->eq('u.user_id', $qb->createNamedParameter($userId)), @@ -295,7 +298,8 @@ class CirclesRequestBuilder extends CoreRequestBuilder { $expr->andX( $expr->eq( $qb->createFunction( - 'SUBSTR(' . $pf . '`unique_id`, 1, ' . Circle::UNIQUEID_SHORT_LENGTH . ')' + 'SUBSTR(' . $pf . '`unique_id`, 1, ' . Circle::UNIQUEID_SHORT_LENGTH + . ')' ) , 'o.circle_id' ), @@ -307,6 +311,30 @@ class CirclesRequestBuilder extends CoreRequestBuilder { /** + * Left Join circle table to get more information about the circle. + * + * @param IQueryBuilder $qb + */ + protected function leftJoinCircle(IQueryBuilder &$qb) { + + if ($qb->getType() !== QueryBuilder::SELECT) { + return; + } + + $expr = $qb->expr(); + $pf = $this->default_select_alias . '.'; + + /** @noinspection PhpMethodParametersCountMismatchInspection */ + $qb->selectAlias('lc.type', 'circle_type') + ->selectAlias('lc.name', 'circle_name') + ->leftJoin( + $this->default_select_alias, CoreRequestBuilder::TABLE_CIRCLES, 'lc', + $expr->eq($pf . 'circle_id', 'lc.id') + ); + } + + + /** * Base of the Sql Select request for Shares * * @return IQueryBuilder @@ -316,9 +344,9 @@ class CirclesRequestBuilder extends CoreRequestBuilder { /** @noinspection PhpMethodParametersCountMismatchInspection */ $qb->select('id', 'status', 'address', 'token', 'circle_id', 'unique_id', 'creation') - ->from(self::TABLE_LINKS, 's'); + ->from(self::TABLE_LINKS, 'l'); - $this->default_select_alias = 's'; + $this->default_select_alias = 'l'; return $qb; } @@ -334,8 +362,8 @@ class CirclesRequestBuilder extends CoreRequestBuilder { /** @noinspection PhpMethodParametersCountMismatchInspection */ $qb->select( - 'circle_id', 'source', 'type', 'author', 'cloud_id', 'payload', 'creation', 'headers', - 'unique_id' + 's.circle_id', 's.source', 's.type', 's.author', 's.cloud_id', 's.payload', + 's.creation', 's.headers', 's.unique_id' ) ->from(self::TABLE_SHARES, 's'); @@ -344,6 +372,7 @@ class CirclesRequestBuilder extends CoreRequestBuilder { return $qb; } + /** * Base of the Sql Insert request for Shares * @@ -424,7 +453,9 @@ class CirclesRequestBuilder extends CoreRequestBuilder { ->where( $qb->expr() ->eq( - $qb->createFunction('SUBSTR(`unique_id`, 1, ' . Circle::UNIQUEID_SHORT_LENGTH . ')'), + $qb->createFunction( + 'SUBSTR(`unique_id`, 1, ' . Circle::UNIQUEID_SHORT_LENGTH . ')' + ), $qb->createNamedParameter($circleUniqueId) ) ); @@ -492,7 +523,16 @@ class CirclesRequestBuilder extends CoreRequestBuilder { */ protected function parseSharesSelectSql($data) { $frame = new SharingFrame($data['source'], $data['type']); - $frame->setCircleId($data['circle_id']); + + $circle = new Circle(); + $circle->setUniqueId($data['circle_id']); + if (key_exists('circle_type', $data)) { + $circle->setType($data['circle_type']); + $circle->setName($data['circle_name']); + } + + $frame->setCircle($circle); + $frame->setAuthor($data['author']); $frame->setCloudId($data['cloud_id']); $frame->setPayload(json_decode($data['payload'], true)); diff --git a/lib/Model/BaseMember.php b/lib/Model/BaseMember.php index 8af54ee0..969f8568 100644 --- a/lib/Model/BaseMember.php +++ b/lib/Model/BaseMember.php @@ -229,7 +229,7 @@ class BaseMember implements \JsonSerializable { /** * @param $arr * - * 0.13.0 : remove both key_exists condition + * TODO: 0.15.0 : remove both key_exists condition * * @return null|Member */ diff --git a/lib/Model/Circle.php b/lib/Model/Circle.php index 22f35964..855850d7 100644 --- a/lib/Model/Circle.php +++ b/lib/Model/Circle.php @@ -87,14 +87,23 @@ class Circle extends BaseCircle implements \JsonSerializable { if ($this->lightJson) { $json['members'] = []; + $json['description'] = ''; $json['links'] = []; $json['groups'] = []; + $json['settings'] = []; } return $json; } + public function getArray($full = false, $light = false) { + $json = $this->getJson($full, $light); + + return json_decode($json, true); + } + + public function getJson($full = false, $light = false) { $this->fullJson = $full; $this->lightJson = $light; @@ -109,14 +118,13 @@ class Circle extends BaseCircle implements \JsonSerializable { /** * set all infos from an Array. * - * @param $l10n * @param $arr * * @deprecated * * @return $this */ - public static function fromArray($l10n, $arr) { + public static function fromArray($arr) { $circle = new Circle(); $circle->setId($arr['id']); @@ -132,13 +140,14 @@ class Circle extends BaseCircle implements \JsonSerializable { $circle->setType($arr['type']); $circle->setCreation($arr['creation']); - if (key_exists('user', $arr)) { + // TODO: 0.15.0 - remove condition is null + if (key_exists('user', $arr) && $arr['user'] !== null) { $viewer = Member::fromArray($arr['user']); $viewer->setType(Member::TYPE_USER); $circle->setViewer($viewer); } - if (key_exists('owner', $arr)) { + if (key_exists('owner', $arr) && $arr['owner'] !== null) { $owner = Member::fromArray($arr['owner']); $owner->setType(Member::TYPE_USER); $circle->setOwner($owner); @@ -149,14 +158,13 @@ class Circle extends BaseCircle implements \JsonSerializable { /** - * @param $l10n * @param $json * * @deprecated * @return Circle */ - public static function fromJSON($l10n, $json) { - return self::fromArray($l10n, json_decode($json, true)); + public static function fromJSON($json) { + return self::fromArray(json_decode($json, true)); } diff --git a/lib/Model/SharingFrame.php b/lib/Model/SharingFrame.php index 9843f405..8f2ba4a8 100644 --- a/lib/Model/SharingFrame.php +++ b/lib/Model/SharingFrame.php @@ -37,14 +37,8 @@ class SharingFrame implements \JsonSerializable { /** @var string */ private $type; - /** @var int */ - private $circleUniqueId; - - /** @var string */ - private $circleName; - - /** @var int */ - private $circleType; + /** @var Circle */ + private $circle; /** @var string */ private $author; @@ -85,47 +79,17 @@ class SharingFrame implements \JsonSerializable { } /** - * @param string $circleUniqueId + * @param Circle $circle */ - public function setCircleId($circleUniqueId) { - $this->circleUniqueId = $circleUniqueId; + public function setCircle($circle) { + $this->circle = $circle; } /** - * @return string + * @return Circle */ - public function getCircleId() { - return $this->circleUniqueId; - } - - - /** - * @param string $circleName - */ - public function setCircleName($circleName) { - $this->circleName = $circleName; - } - - /** - * @return string - */ - public function getCircleName() { - return $this->circleName; - } - - - /** - * @param int $circleType - */ - public function setCircleType($circleType) { - $this->circleType = $circleType; - } - - /** - * @return int - */ - public function getCircleType() { - return $this->circleType; + public function getCircle() { + return $this->circle; } @@ -286,7 +250,7 @@ class SharingFrame implements \JsonSerializable { /** * @return bool */ - public function isCircleZero() { + public function is0Circle() { return ($this->getCloudId() === null); } @@ -302,17 +266,15 @@ class SharingFrame implements \JsonSerializable { public function jsonSerialize() { return array( - 'circle_id' => $this->getCircleId(), - 'circle_name' => $this->getCircleName(), - 'circle_type' => $this->getCircleType(), - 'unique_id' => $this->getUniqueId(), - 'source' => $this->getSource(), - 'type' => $this->getType(), - 'author' => $this->getAuthor(), - 'cloud_id' => $this->getCloudId(), - 'headers' => $this->getHeaders(), - 'payload' => $this->getPayload(), - 'creation' => $this->getCreation(), + 'unique_id' => $this->getUniqueId(), + 'circle' => $this->getCircle()->getArray(false, true), + 'source' => $this->getSource(), + 'type' => $this->getType(), + 'author' => $this->getAuthor(), + 'cloud_id' => $this->getCloudId(), + 'headers' => $this->getHeaders(), + 'payload' => $this->getPayload(), + 'creation' => $this->getCreation(), ); } @@ -324,14 +286,23 @@ class SharingFrame implements \JsonSerializable { } $share = new SharingFrame($arr['source'], $arr['type']); - $share->setCircleId($arr['circle_id']); - if (key_exists('circle_name', $arr)) { - $share->setCircleName($arr['circle_name']); + + $circle = new Circle(); + if (key_exists('circle', $arr)) { + $circle = Circle::fromArray($arr['circle']); } + + // TODO 0.15.0 - remove those 3 conditions if (key_exists('circle_type', $arr)) { - $share->setCircleType($arr['circle_type']); + $circle->setType($arr['circle_type']); } - + if (key_exists('circle_name', $arr)) { + $circle->setName($arr['circle_name']); + } + if (key_exists('circle_id', $arr)) { + $circle->setId($arr['circle_id']); + } + $share->setCircle($circle); if (key_exists('headers', $arr)) { $share->setHeaders($arr['headers']); diff --git a/lib/Service/BroadcastService.php b/lib/Service/BroadcastService.php index 728b87c3..8b679ada 100644 --- a/lib/Service/BroadcastService.php +++ b/lib/Service/BroadcastService.php @@ -104,7 +104,7 @@ class BroadcastService { throw new BroadcasterIsNotCompatibleException(); } - $circle = $this->circlesRequest->forceGetCircle($frame->getCircleId()); + $circle = $this->circlesRequest->forceGetCircle($frame->getCircle()->getUniqueId()); $broadcaster->init(); if ($circle->getType() !== Circle::CIRCLES_PERSONAL) { diff --git a/lib/Service/FederatedService.php b/lib/Service/FederatedService.php index 98b6a877..47b00e44 100644 --- a/lib/Service/FederatedService.php +++ b/lib/Service/FederatedService.php @@ -716,9 +716,7 @@ class FederatedService { throw new CircleDoesNotExistException('unknown_circle'); } - $frame->setCircleId($link->getCircleId()); - $frame->setCircleName($circle->getName()); - $frame->setCircleType($circle->getType()); + $frame->setCircle($circle); $this->circlesRequest->saveFrame($frame); $this->broadcastService->broadcastFrame($frame->getHeader('broadcast'), $frame); @@ -790,14 +788,23 @@ class FederatedService { */ public function sendRemoteShare(SharingFrame $frame) { - $circle = $this->circlesRequest->forceGetCircle($frame->getCircleId()); - if ($circle === null) { - throw new Exception('unknown_circle'); + try { + $circle = $this->circlesRequest->forceGetCircle( + $frame->getCircle() + ->getUniqueId() + ); + } catch (CircleDoesNotExistException $e) { + throw new CircleDoesNotExistException('unknown_circle'); } - $links = $this->getLinksFromCircle($frame->getCircleId()); + $links = $this->getLinksFromCircle( + $frame->getCircle() + ->getUniqueId() + ); + foreach ($links AS $link) { + $args = [ 'apiVersion' => Circles::version(), 'token' => $link->getToken(true), diff --git a/lib/Service/SharesService.php b/lib/Service/SharesService.php index 8f5a8145..1889ce5f 100644 --- a/lib/Service/SharesService.php +++ b/lib/Service/SharesService.php @@ -94,21 +94,22 @@ class SharesService { * The Payload will be shared locally, and spread it live if a Broadcaster is set. * Function will also initiate the federated broadcast to linked circles. * + * @param string $circleUniqueId * @param SharingFrame $frame * @param string|null $broadcast * * @throws Exception + * @throws MemberDoesNotExistException */ - public function createFrame(SharingFrame $frame, $broadcast = null) { - - $circle = $this->circlesRequest->getCircle($frame->getCircleId(), $this->userId); - if ($circle->getHigherViewer() - ->getLevel() < Member::LEVEL_MEMBER - ) { - throw new MemberDoesNotExistException(); - } + public function createFrame($circleUniqueId, SharingFrame $frame, $broadcast = null) { try { + $circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); + $circle->getHigherViewer() + ->hasToBeMember(); + + $frame->setCircle($circle); + $this->generateHeaders($frame, $circle, $broadcast); $this->circlesRequest->saveFrame($frame); @@ -144,8 +145,6 @@ class SharesService { $frame->setHeader('circleUniqueId', $circle->getUniqueId()); $frame->setHeader('broadcast', (string)$broadcast); $frame->generateUniqueId(); - $frame->setCircleName($circle->getName()); - $frame->setCircleType($circle->getType()); } catch (Exception $e) { throw new $e; |