aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Collaboration
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-10-24 14:25:35 +0200
committerJulius Härtl <jus@bitgrid.net>2019-03-01 20:56:16 +0100
commit702dcfb72848b36921a310188aa019d810668ebc (patch)
tree449f8965032eda43db1a029f4f13bebedd83029a /lib/private/Collaboration
parent5dfc56e925309d637be6f5a69cc16d0baaf20d03 (diff)
downloadnextcloud-server-702dcfb72848b36921a310188aa019d810668ebc.tar.gz
nextcloud-server-702dcfb72848b36921a310188aa019d810668ebc.zip
Make names mandatory
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Collaboration')
-rw-r--r--lib/private/Collaboration/Resources/Collection.php43
-rw-r--r--lib/private/Collaboration/Resources/Manager.php31
-rw-r--r--lib/private/Collaboration/Resources/Resource.php7
3 files changed, 61 insertions, 20 deletions
diff --git a/lib/private/Collaboration/Resources/Collection.php b/lib/private/Collaboration/Resources/Collection.php
index e89f62c0518..54c009b917c 100644
--- a/lib/private/Collaboration/Resources/Collection.php
+++ b/lib/private/Collaboration/Resources/Collection.php
@@ -43,17 +43,42 @@ class Collection implements ICollection {
/** @var int */
protected $id;
+ /** @var string */
+ protected $name;
+
/** @var IResource[] */
protected $resources;
- public function __construct(IManager $manager, IDBConnection $connection, int $id) {
+ public function __construct(
+ IManager $manager,
+ IDBConnection $connection,
+ int $id,
+ string $name
+ ) {
$this->manager = $manager;
$this->connection = $connection;
$this->id = $id;
+ $this->name = $name;
$this->resources = [];
}
/**
+ * @return int
+ * @since 15.0.0
+ */
+ public function getId(): int {
+ return $this->id;
+ }
+
+ /**
+ * @return string
+ * @since 15.0.0
+ */
+ public function getName(): string {
+ return $this->name;
+ }
+
+ /**
* @return IResource[]
* @since 15.0.0
*/
@@ -90,10 +115,6 @@ class Collection implements ICollection {
$this->resources[] = $resource;
- if ($this->id === 0) {
- $this->makeCollectionPersistent();
- }
-
$query = $this->connection->getQueryBuilder();
$query->insert('collres_resources')
->values([
@@ -128,7 +149,7 @@ class Collection implements ICollection {
$query->execute();
if (empty($this->resources)) {
- $this->makeCollectionUnsteady();
+ $this->removeCollection();
}
}
@@ -154,15 +175,7 @@ class Collection implements ICollection {
$resource1->getId() === $resource2->getId();
}
- protected function makeCollectionPersistent() {
- $query = $this->connection->getQueryBuilder();
- $query->insert('collres_collections');
- $query->execute();
-
- $this->id = $query->getLastInsertId();
- }
-
- protected function makeCollectionUnsteady() {
+ protected function removeCollection() {
$query = $this->connection->getQueryBuilder();
$query->delete('collres_collections')
->where($query->expr()->eq('id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)));
diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php
index c091f5c5805..18301e0f2f5 100644
--- a/lib/private/Collaboration/Resources/Manager.php
+++ b/lib/private/Collaboration/Resources/Manager.php
@@ -23,11 +23,14 @@ declare(strict_types=1);
namespace OC\Collaboration\Resources;
+use OCA\Files\Collaboration\Resources\ResourceProvider;
+use OCP\Collaboration\Resources\CollectionException;
use OCP\Collaboration\Resources\ICollection;
use OCP\Collaboration\Resources\IManager;
use OCP\Collaboration\Resources\IProvider;
use OCP\Collaboration\Resources\IResource;
use OCP\Collaboration\Resources\ResourceException;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IUser;
@@ -43,18 +46,36 @@ class Manager implements IManager {
/**
* @param int $id
* @return ICollection
+ * @throws CollectionException when the collection could not be found
* @since 15.0.0
*/
public function getCollection(int $id): ICollection {
- return new Collection($this, $this->connection, $id);
+ $query = $this->connection->getQueryBuilder();
+ $query->select('*')
+ ->from('collres_collections')
+ ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
+ $result = $query->execute();
+ $row = $result->fetch();
+ $result->closeCursor();
+
+ if (!$row) {
+ throw new CollectionException('Collection not found');
+ }
+
+ return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name']);
}
/**
+ * @param string $name
* @return ICollection
* @since 15.0.0
*/
- public function newCollection(): ICollection {
- return new Collection($this, $this->connection, 0);
+ public function newCollection(string $name): ICollection {
+ $query = $this->connection->getQueryBuilder();
+ $query->insert('collres_collections');
+ $query->execute();
+
+ return new Collection($this, $this->connection, $query->getLastInsertId(), $name);
}
/**
@@ -72,7 +93,9 @@ class Manager implements IManager {
* @since 15.0.0
*/
public function getProviders(): array {
- return [];
+ return [
+ \OC::$server->query(ResourceProvider::class) // FIXME
+ ];
}
/**
diff --git a/lib/private/Collaboration/Resources/Resource.php b/lib/private/Collaboration/Resources/Resource.php
index 144af6d358e..3013f1f5c48 100644
--- a/lib/private/Collaboration/Resources/Resource.php
+++ b/lib/private/Collaboration/Resources/Resource.php
@@ -47,7 +47,12 @@ class Resource implements IResource {
/** @var string|null */
protected $name;
- public function __construct(IManager $manager, IDBConnection $connection, string $type, string $id) {
+ public function __construct(
+ IManager $manager,
+ IDBConnection $connection,
+ string $type,
+ string $id
+ ) {
$this->manager = $manager;
$this->connection = $connection;
$this->type = $type;