Implement attachment backend with a first module for app data file upload

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-06-11 10:03:28 +02:00
parent e4863b6d8d
commit 45c7241daf
13 changed files with 743 additions and 4 deletions

47
lib/Db/Attachment.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
/**
* @copyright Copyright (c) 2018 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\Deck\Db;
class Attachment extends RelationalEntity {
protected $cardId;
protected $type;
protected $data;
protected $lastModified;
protected $createdAt;
protected $createdBy;
protected $deletedAt;
protected $extendedData = [];
public function __construct() {
$this->addType('id', 'integer');
$this->addType('cardId', 'integer');
$this->addType('lastModified', 'integer');
$this->addType('createdAt', 'integer');
$this->addType('deletedAt', 'integer');
$this->addResolvable('createdBy');
$this->addRelation('extendedData');
}
}

126
lib/Db/AttachmentMapper.php Normal file
View File

@@ -0,0 +1,126 @@
<?php
/**
* @copyright Copyright (c) 2018 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\Deck\Db;
use OCP\AppFramework\Db\Entity;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IUserManager;
use PDO;
class AttachmentMapper extends DeckMapper implements IPermissionMapper {
private $cardMapper;
private $userManager;
public function __construct(IDBConnection $db, CardMapper $cardMapper, IUserManager $userManager) {
parent::__construct($db, 'deck_attachment', Attachment::class);
$this->cardMapper = $cardMapper;
$this->userManager = $userManager;
$this->qb = $this->db->getQueryBuilder();
}
/**
* @param $id
* @return Entity|Attachment
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
*/
public function find($id) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('deck_attachment')
->where($qb->expr()->eq('id', $id));
$cursor = $qb->execute();
$row = $cursor->fetch(PDO::FETCH_ASSOC);
$cursor->closeCursor();
return $this->mapRowToEntity($row);
}
/**
* Find all attachments for a card
*
* @param $cardId
* @return array
*/
public function findAll($cardId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('deck_attachment')
->where($qb->expr()->eq('card_id', $cardId, IQueryBuilder::PARAM_INT));
$entities = [];
$cursor = $qb->execute();
while($row = $cursor->fetch()){
$entities[] = $this->mapRowToEntity($row);
}
$cursor->closeCursor();
return $entities;
}
/**
* @param Attachment $attachment
* @throws \Exception
*/
public function mapParticipant(Attachment $attachment) {
$userManager = $this->userManager;
$attachment->resolveRelation('participant', function() use (&$userManager, &$attachment) {
$user = $userManager->get($attachment->getParticipant());
if ($user !== null) {
return new User($user);
}
return null;
});
}
/**
* Check if $userId is owner of Entity with $id
*
* @param $userId string userId
* @param $id int|string unique entity identifier
* @return boolean
*/
public function isOwner($userId, $id) {
// TODO: Implement isOwner() method.
}
/**
* Query boardId for Entity of given $id
*
* @param $id int|string unique entity identifier
* @return int|null id of Board
*/
public function findBoardId($id) {
try {
$attachment = $this->find($id);
} catch (\Exception $e) {
return null;
}
$this->cardMapper->findBoardId($attachment->getCardId());
}
}

View File

@@ -35,6 +35,7 @@ class Card extends RelationalEntity {
protected $createdAt;
protected $labels;
protected $assignedUsers;
protected $attachments;
protected $owner;
protected $order;
protected $archived = false;
@@ -58,6 +59,7 @@ class Card extends RelationalEntity {
$this->addType('notified', 'boolean');
$this->addRelation('labels');
$this->addRelation('assignedUsers');
$this->addRelation('attachments');
$this->addRelation('participants');
$this->addResolvable('owner');
}

View File

@@ -25,6 +25,13 @@ namespace OCA\Deck\Db;
use OCP\AppFramework\Db\Mapper;
/**
* Class DeckMapper
*
* @package OCA\Deck\Db
*
* TODO: Move to QBMapper once Nextcloud 14 is a minimum requirement
*/
abstract class DeckMapper extends Mapper {
/**