Add last_modified to board/stack database and add check on index methods

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-10-27 15:56:07 +02:00
parent 38bc02c07e
commit a068d6e1c6
12 changed files with 113 additions and 60 deletions

View File

@@ -46,6 +46,13 @@
<notnull>false</notnull> <notnull>false</notnull>
<unsigned>true</unsigned> <unsigned>true</unsigned>
</field> </field>
<field>
<name>last_modified</name>
<type>integer</type>
<default></default>
<notnull>false</notnull>
<unsigned>true</unsigned>
</field>
</declaration> </declaration>
</table> </table>
<table> <table>
@@ -85,6 +92,13 @@
<notnull>false</notnull> <notnull>false</notnull>
<unsigned>true</unsigned> <unsigned>true</unsigned>
</field> </field>
<field>
<name>last_modified</name>
<type>integer</type>
<default></default>
<notnull>false</notnull>
<unsigned>true</unsigned>
</field>
<index> <index>
<name>deck_stacks_board_id_index</name> <name>deck_stacks_board_id_index</name>
<field> <field>

View File

@@ -24,6 +24,7 @@
namespace OCA\Deck\Controller; namespace OCA\Deck\Controller;
use OCA\Deck\Db\ChangeHelper;
use OCP\AppFramework\ApiController; use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
@@ -60,9 +61,14 @@ class BoardApiController extends ApiController {
* Return all of the boards that the current user has access to. * Return all of the boards that the current user has access to.
*/ */
public function index() { public function index() {
$boards = $this->service->findAll(); $modified = $this->request->getHeader('If-Modified-Since');
if ($modified === '') {
$boards = $this->service->findAll();
} else {
$boards = $this->service->findAll(strtotime($modified));
}
return new DataResponse($boards, HTTP::STATUS_OK); return new DataResponse($boards, HTTP::STATUS_OK);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
@@ -87,8 +93,8 @@ class BoardApiController extends ApiController {
* *
* Create a board with the specified title and color. * Create a board with the specified title and color.
*/ */
public function create($title, $color) { public function create($title, $color) {
$board = $this->service->create($title, $this->userId, $color); $board = $this->service->create($title, $this->userId, $color);
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
} }
@@ -96,14 +102,14 @@ class BoardApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* @params $title * @params $title
* @params $color * @params $color
* @params $archived * @params $archived
* *
* Update a board with the specified boardId, title and color, and archived state. * Update a board with the specified boardId, title and color, and archived state.
*/ */
public function update($title, $color, $archived = false) { public function update($title, $color, $archived = false) {
$board = $this->service->update($this->request->getParam('boardId'), $title, $color, $archived); $board = $this->service->update($this->request->getParam('boardId'), $title, $color, $archived);
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
} }
@@ -112,7 +118,7 @@ class BoardApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* *
* Delete the board specified by $boardId. Return the board that was deleted. * Delete the board specified by $boardId. Return the board that was deleted.
*/ */
@@ -125,12 +131,12 @@ class BoardApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* *
* Undo the deletion of the board specified by $boardId. * Undo the deletion of the board specified by $boardId.
*/ */
public function undoDelete() { public function undoDelete() {
$board = $this->service->deleteUndo($this->request->getParam('boardId')); $board = $this->service->deleteUndo($this->request->getParam('boardId'));
return new DataResponse($board, HTTP::STATUS_OK); return new DataResponse($board, HTTP::STATUS_OK);
} }

View File

@@ -23,6 +23,7 @@
namespace OCA\Deck\Controller; namespace OCA\Deck\Controller;
use OCA\Deck\Db\ChangeHelper;
use OCP\AppFramework\ApiController; use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
@@ -35,8 +36,8 @@
* @package OCA\Deck\Controller * @package OCA\Deck\Controller
*/ */
class CardApiController extends ApiController { class CardApiController extends ApiController {
private $cardService; private $cardService;
private $userId; private $userId;
/** /**
* @param string $appName * @param string $appName
@@ -45,9 +46,9 @@ class CardApiController extends ApiController {
* @param $userId * @param $userId
*/ */
public function __construct($appName, IRequest $request, CardService $cardService, $userId) { public function __construct($appName, IRequest $request, CardService $cardService, $userId) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->cardService = $cardService; $this->cardService = $cardService;
$this->userId = $userId; $this->userId = $userId;
} }
/** /**
@@ -118,8 +119,8 @@ class CardApiController extends ApiController {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Assign a label to a card. * Assign a label to a card.
*/ */
public function removeLabel($labelId) { public function removeLabel($labelId) {
@@ -130,8 +131,8 @@ class CardApiController extends ApiController {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Unassign a label to a card. * Unassign a label to a card.
*/ */
public function unassignUser($userId) { public function unassignUser($userId) {
@@ -147,12 +148,12 @@ class CardApiController extends ApiController {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* Unassign a label to a card. * Unassign a label to a card.
*/ */
public function reorder($stackId, $order) { public function reorder($stackId, $order) {
$card = $this->cardService->reorder($this->request->getParam('cardId'), $stackId, $order); $card = $this->cardService->reorder($this->request->getParam('cardId'), $stackId, $order);
return new DataResponse($card, HTTP::STATUS_OK); return new DataResponse($card, HTTP::STATUS_OK);
} }
} }

View File

@@ -49,7 +49,7 @@ class StackApiController extends ApiController {
public function __construct($appName, IRequest $request, StackService $stackService, BoardService $boardService) { public function __construct($appName, IRequest $request, StackService $stackService, BoardService $boardService) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->stackService = $stackService; $this->stackService = $stackService;
$this->boardService = $boardService; $this->boardService = $boardService;
} }
/** /**
@@ -59,8 +59,13 @@ class StackApiController extends ApiController {
* *
* Return all of the stacks in the specified board. * Return all of the stacks in the specified board.
*/ */
public function index() { public function index() {
$stacks = $this->stackService->findAll($this->request->getParam('boardId')); $since = 0;
$modified = $this->request->getHeader('If-Modified-Since');
if ($modified !== '') {
$since = strtotime($modified);
}
$stacks = $this->stackService->findAll($this->request->getParam('boardId'), $since);
return new DataResponse($stacks, HTTP::STATUS_OK); return new DataResponse($stacks, HTTP::STATUS_OK);
} }
@@ -75,7 +80,7 @@ class StackApiController extends ApiController {
$stack = $this->stackService->find($this->request->getParam('stackId')); $stack = $this->stackService->find($this->request->getParam('stackId'));
return new DataResponse($stack, HTTP::STATUS_OK); return new DataResponse($stack, HTTP::STATUS_OK);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
@@ -95,13 +100,13 @@ class StackApiController extends ApiController {
* @NoAdminRequired * @NoAdminRequired
* @CORS * @CORS
* @NoCSRFRequired * @NoCSRFRequired
* *
* @params $title * @params $title
* @params $order * @params $order
* *
* Update a stack by the specified stackId and boardId with the values that were put. * Update a stack by the specified stackId and boardId with the values that were put.
*/ */
public function update($title, $order) { public function update($title, $order) {
$stack = $this->stackService->update($this->request->getParam('stackId'), $title, $this->request->getParam('boardId'), $order, 0); $stack = $this->stackService->update($this->request->getParam('stackId'), $title, $this->request->getParam('boardId'), $order, 0);
return new DataResponse($stack, HTTP::STATUS_OK); return new DataResponse($stack, HTTP::STATUS_OK);
} }
@@ -113,7 +118,7 @@ class StackApiController extends ApiController {
* *
* Delete the stack specified by $this->request->getParam('stackId'). * Delete the stack specified by $this->request->getParam('stackId').
*/ */
public function delete() { public function delete() {
$stack = $this->stackService->delete($this->request->getParam('stackId')); $stack = $this->stackService->delete($this->request->getParam('stackId'));
return new DataResponse($stack, HTTP::STATUS_OK); return new DataResponse($stack, HTTP::STATUS_OK);
} }

View File

@@ -5,20 +5,20 @@
* @author Julius Härtl <jus@bitgrid.net> * @author Julius Härtl <jus@bitgrid.net>
* *
* @license GNU AGPL version 3 or any later version * @license GNU AGPL version 3 or any later version
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
namespace OCA\Deck\Db; namespace OCA\Deck\Db;
@@ -35,12 +35,14 @@ class Board extends RelationalEntity {
protected $users = []; protected $users = [];
protected $shared; protected $shared;
protected $deletedAt = 0; protected $deletedAt = 0;
protected $lastModified = 0;
public function __construct() { public function __construct() {
$this->addType('id', 'integer'); $this->addType('id', 'integer');
$this->addType('shared', 'integer'); $this->addType('shared', 'integer');
$this->addType('archived', 'boolean'); $this->addType('archived', 'boolean');
$this->addType('deletedAt', 'integer'); $this->addType('deletedAt', 'integer');
$this->addType('lastModified', 'integer');
$this->addRelation('labels'); $this->addRelation('labels');
$this->addRelation('acl'); $this->addRelation('acl');
$this->addRelation('shared'); $this->addRelation('shared');
@@ -75,4 +77,4 @@ class Board extends RelationalEntity {
$this->acl[$a->id] = $a; $this->acl[$a->id] = $a;
} }
} }
} }

View File

@@ -62,7 +62,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
* @throws DoesNotExistException * @throws DoesNotExistException
*/ */
public function find($id, $withLabels = false, $withAcl = false) { public function find($id, $withLabels = false, $withAcl = false) {
$sql = 'SELECT id, title, owner, color, archived, deleted_at FROM `*PREFIX*deck_boards` ' . $sql = 'SELECT id, title, owner, color, archived, deleted_at, last_modified FROM `*PREFIX*deck_boards` ' .
'WHERE `id` = ?'; 'WHERE `id` = ?';
$board = $this->findEntity($sql, [$id]); $board = $this->findEntity($sql, [$id]);
@@ -89,11 +89,14 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
* @param null $offset * @param null $offset
* @return array * @return array
*/ */
public function findAllByUser($userId, $limit = null, $offset = null) { public function findAllByUser($userId, $limit = null, $offset = null, $since = 0) {
$sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared FROM `*PREFIX*deck_boards` WHERE owner = ? UNION ' . $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ? AND last_modified > ?';
'SELECT boards.id, title, owner, color, archived, deleted_at, 1 as shared FROM `*PREFIX*deck_boards` as boards ' . $entries = $this->findEntities($sql, [$userId, $since], $limit, $offset);
'JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=? AND boards.owner != ?';
$entries = $this->findEntities($sql, [$userId, $userId, Acl::PERMISSION_TYPE_USER, $userId], $limit, $offset); $sql = 'SELECT id, title, owner, color, archived, deleted_at, 0 as shared, last_modified FROM `*PREFIX*deck_boards` WHERE owner = ? AND last_modified > ? UNION ' .
'SELECT boards.id, title, owner, color, archived, deleted_at, 1 as shared, last_modified FROM `*PREFIX*deck_boards` as boards ' .
'JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=? AND boards.owner != ? AND last_modified > ?';
$entries = $this->findEntities($sql, [$userId, $since, $userId, Acl::PERMISSION_TYPE_USER, $userId, $since], $limit, $offset);
/* @var Board $entry */ /* @var Board $entry */
foreach ($entries as $entry) { foreach ($entries as $entry) {
$acl = $this->aclMapper->findAll($entry->id); $acl = $this->aclMapper->findAll($entry->id);
@@ -115,7 +118,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
if (count($groups) <= 0) { if (count($groups) <= 0) {
return []; return [];
} }
$sql = 'SELECT boards.id, title, owner, color, archived, deleted_at, 2 as shared FROM `*PREFIX*deck_boards` as boards ' . $sql = 'SELECT boards.id, title, owner, color, archived, deleted_at, 2 as shared, last_modified FROM `*PREFIX*deck_boards` as boards ' .
'INNER JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE owner != ? AND type=? AND ('; 'INNER JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE owner != ? AND type=? AND (';
for ($i = 0, $iMax = count($groups); $i < $iMax; $i++) { for ($i = 0, $iMax = count($groups); $i < $iMax; $i++) {
$sql .= 'acl.participant = ? '; $sql .= 'acl.participant = ? ';
@@ -141,7 +144,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
public function findToDelete() { public function findToDelete() {
// add buffer of 5 min // add buffer of 5 min
$timeLimit = time() - (60 * 5); $timeLimit = time() - (60 * 5);
$sql = 'SELECT id, title, owner, color, archived, deleted_at FROM `*PREFIX*deck_boards` ' . $sql = 'SELECT id, title, owner, color, archived, deleted_at, last_modified FROM `*PREFIX*deck_boards` ' .
'WHERE `deleted_at` > 0 AND `deleted_at` < ?'; 'WHERE `deleted_at` > 0 AND `deleted_at` < ?';
return $this->findEntities($sql, [$timeLimit]); return $this->findEntities($sql, [$timeLimit]);
} }

View File

@@ -118,10 +118,10 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
return $card; return $card;
} }
public function findAll($stackId, $limit = null, $offset = null) { public function findAll($stackId, $limit = null, $offset = null, $since = -1) {
$sql = 'SELECT * FROM `*PREFIX*deck_cards` $sql = 'SELECT * FROM `*PREFIX*deck_cards`
WHERE `stack_id` = ? AND NOT archived AND deleted_at = 0 ORDER BY `order`'; WHERE `stack_id` = ? AND NOT archived AND deleted_at = 0 AND last_modified > ? ORDER BY `order`';
return $this->findEntities($sql, [$stackId], $limit, $offset); return $this->findEntities($sql, [$stackId, $since], $limit, $offset);
} }
public function findDeleted($boardId, $limit = null, $offset = null) { public function findDeleted($boardId, $limit = null, $offset = null) {

View File

@@ -30,11 +30,13 @@ class Stack extends RelationalEntity {
protected $deletedAt = 0; protected $deletedAt = 0;
protected $cards = array(); protected $cards = array();
protected $order; protected $order;
protected $lastModified = 0;
public function __construct() { public function __construct() {
$this->addType('id', 'integer'); $this->addType('id', 'integer');
$this->addType('boardId', 'integer'); $this->addType('boardId', 'integer');
$this->addType('deletedAt', 'integer'); $this->addType('deletedAt', 'integer');
$this->addType('lastModified', 'integer');
$this->addType('order', 'integer'); $this->addType('order', 'integer');
} }

View File

@@ -31,6 +31,7 @@ use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Attachment; use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper; use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\InvalidAttachmentType; use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\NoPermissionException; use OCA\Deck\NoPermissionException;
use OCA\Deck\NotFoundException; use OCA\Deck\NotFoundException;
@@ -69,7 +70,7 @@ class AttachmentService {
* @param IL10N $l10n * @param IL10N $l10n
* @throws \OCP\AppFramework\QueryException * @throws \OCP\AppFramework\QueryException
*/ */
public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, PermissionService $permissionService, Application $application, ICacheFactory $cacheFactory, $userId, IL10N $l10n, ActivityManager $activityManager) { public function __construct(AttachmentMapper $attachmentMapper, CardMapper $cardMapper, ChangeHelper $changeHelper, PermissionService $permissionService, Application $application, ICacheFactory $cacheFactory, $userId, IL10N $l10n, ActivityManager $activityManager) {
$this->attachmentMapper = $attachmentMapper; $this->attachmentMapper = $attachmentMapper;
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
@@ -78,6 +79,7 @@ class AttachmentService {
$this->cache = $cacheFactory->createDistributed('deck-card-attachments-'); $this->cache = $cacheFactory->createDistributed('deck-card-attachments-');
$this->l10n = $l10n; $this->l10n = $l10n;
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->changeHelper = $changeHelper;
// Register shipped attachment services // Register shipped attachment services
// TODO: move this to a plugin based approach once we have different types of attachments // TODO: move this to a plugin based approach once we have different types of attachments
@@ -205,6 +207,7 @@ class AttachmentService {
} catch (InvalidAttachmentType $e) { } catch (InvalidAttachmentType $e) {
// just store the data // just store the data
} }
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_CREATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_CREATE);
return $attachment; return $attachment;
} }
@@ -290,6 +293,7 @@ class AttachmentService {
} catch (InvalidAttachmentType $e) { } catch (InvalidAttachmentType $e) {
// just store the data // just store the data
} }
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_UPDATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_UPDATE);
return $attachment; return $attachment;
} }
@@ -332,6 +336,7 @@ class AttachmentService {
// just delete without further action // just delete without further action
} }
$attachment = $this->attachmentMapper->delete($attachment); $attachment = $this->attachmentMapper->delete($attachment);
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_DELETE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_DELETE);
return $attachment; return $attachment;
} }
@@ -355,6 +360,7 @@ class AttachmentService {
if ($service->allowUndo()) { if ($service->allowUndo()) {
$attachment->setDeletedAt(0); $attachment->setDeletedAt(0);
$attachment = $this->attachmentMapper->update($attachment); $attachment = $this->attachmentMapper->update($attachment);
$this->changeHelper->cardChanged($attachment->getCardId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_RESTORE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_RESTORE);
return $attachment; return $attachment;
} }

View File

@@ -84,10 +84,10 @@ class BoardService {
/** /**
* @return array * @return array
*/ */
public function findAll() { public function findAll($since = 0) {
$userInfo = $this->getBoardPrerequisites(); $userInfo = $this->getBoardPrerequisites();
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']); $userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since);
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']); $groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since);
$complete = array_merge($userBoards, $groupBoards); $complete = array_merge($userBoards, $groupBoards);
$result = []; $result = [];
foreach ($complete as &$item) { foreach ($complete as &$item) {

View File

@@ -30,6 +30,7 @@ use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\Acl; use OCA\Deck\Db\Acl;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\StackMapper; use OCA\Deck\Db\StackMapper;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
@@ -54,6 +55,7 @@ class CardService {
private $currentUser; private $currentUser;
private $activityManager; private $activityManager;
private $commentsManager; private $commentsManager;
private $changeHelper;
public function __construct( public function __construct(
CardMapper $cardMapper, CardMapper $cardMapper,
@@ -68,6 +70,7 @@ class CardService {
ActivityManager $activityManager, ActivityManager $activityManager,
ICommentsManager $commentsManager, ICommentsManager $commentsManager,
IUserManager $userManager, IUserManager $userManager,
ChangeHelper $changeHelper,
$userId $userId
) { ) {
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
@@ -82,6 +85,7 @@ class CardService {
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->commentsManager = $commentsManager; $this->commentsManager = $commentsManager;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->changeHelper = $changeHelper;
$this->currentUser = $userId; $this->currentUser = $userId;
} }
@@ -176,6 +180,7 @@ class CardService {
$card->setOwner($owner); $card->setOwner($owner);
$card = $this->cardMapper->insert($card); $card = $this->cardMapper->insert($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_CREATE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_CREATE);
$this->changeHelper->cardChanged($card->getId(), false);
return $card; return $card;
} }
@@ -202,6 +207,7 @@ class CardService {
$card->setDeletedAt(time()); $card->setDeletedAt(time());
$this->cardMapper->update($card); $this->cardMapper->update($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_DELETE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_DELETE);
$this->changeHelper->cardChanged($card->getId(), false);
return $card; return $card;
} }
@@ -263,6 +269,7 @@ class CardService {
$changes->setAfter($card); $changes->setAfter($card);
$card = $this->cardMapper->update($card); $card = $this->cardMapper->update($card);
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_CARD, $changes, ActivityManager::SUBJECT_CARD_UPDATE); $this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_CARD, $changes, ActivityManager::SUBJECT_CARD_UPDATE);
$this->changeHelper->cardChanged($card->getId(), false);
return $card; return $card;
} }
@@ -295,6 +302,7 @@ class CardService {
throw new StatusException('Operation not allowed. This card is archived.'); throw new StatusException('Operation not allowed. This card is archived.');
} }
$card->setTitle($title); $card->setTitle($title);
$this->changeHelper->cardChanged($card->getId(), false);
return $this->cardMapper->update($card); return $this->cardMapper->update($card);
} }
@@ -349,7 +357,7 @@ class CardService {
$this->cardMapper->update($card); $this->cardMapper->update($card);
$result[$card->getOrder()] = $card; $result[$card->getOrder()] = $card;
} }
$this->changeHelper->cardChanged($id, false);
return $result; return $result;
} }
@@ -376,6 +384,7 @@ class CardService {
$card->setArchived(true); $card->setArchived(true);
$newCard = $this->cardMapper->update($card); $newCard = $this->cardMapper->update($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_ARCHIVE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_ARCHIVE);
$this->changeHelper->cardChanged($id, false);
return $newCard; return $newCard;
} }
@@ -402,6 +411,7 @@ class CardService {
$card->setArchived(false); $card->setArchived(false);
$newCard = $this->cardMapper->update($card); $newCard = $this->cardMapper->update($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_UNARCHIVE); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_UNARCHIVE);
$this->changeHelper->cardChanged($id, false);
return $newCard; return $newCard;
} }
@@ -434,6 +444,7 @@ class CardService {
} }
$label = $this->labelMapper->find($labelId); $label = $this->labelMapper->find($labelId);
$this->cardMapper->assignLabel($cardId, $labelId); $this->cardMapper->assignLabel($cardId, $labelId);
$this->changeHelper->cardChanged($cardId, false);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]);
} }
@@ -466,6 +477,7 @@ class CardService {
} }
$label = $this->labelMapper->find($labelId); $label = $this->labelMapper->find($labelId);
$this->cardMapper->removeLabel($cardId, $labelId); $this->cardMapper->removeLabel($cardId, $labelId);
$this->changeHelper->cardChanged($cardId, false);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]);
} }
@@ -505,6 +517,7 @@ class CardService {
$assignment->setCardId($cardId); $assignment->setCardId($cardId);
$assignment->setParticipant($userId); $assignment->setParticipant($userId);
$assignment = $this->assignedUsersMapper->insert($assignment); $assignment = $this->assignedUsersMapper->insert($assignment);
$this->changeHelper->cardChanged($cardId, false);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_ASSIGN, ['assigneduser' => $userId]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_ASSIGN, ['assigneduser' => $userId]);
return $assignment; return $assignment;
} }
@@ -535,6 +548,7 @@ class CardService {
$assignment = $this->assignedUsersMapper->delete($assignment); $assignment = $this->assignedUsersMapper->delete($assignment);
$card = $this->cardMapper->find($cardId); $card = $this->cardMapper->find($cardId);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]);
$this->changeHelper->cardChanged($cardId, false);
return $assignment; return $assignment;
} }
} }

View File

@@ -74,10 +74,10 @@ class StackService {
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
} }
private function enrichStackWithCards($stack) { private function enrichStackWithCards($stack, $since = -1) {
$cards = $this->cardMapper->findAll($stack->getId()); $cards = $this->cardMapper->findAll($stack->getId(), null, null, $since);
if(is_null($cards)) { if(\count($cards) === 0) {
return; return;
} }
@@ -88,9 +88,9 @@ class StackService {
$stack->setCards($cards); $stack->setCards($cards);
} }
private function enrichStacksWithCards($stacks) { private function enrichStacksWithCards($stacks, $since = -1) {
foreach ($stacks as $stack) { foreach ($stacks as $stack) {
$this->enrichStackWithCards($stack); $this->enrichStackWithCards($stack, $since);
} }
} }
@@ -123,14 +123,14 @@ class StackService {
* @throws \OCA\Deck\NoPermissionException * @throws \OCA\Deck\NoPermissionException
* @throws BadRequestException * @throws BadRequestException
*/ */
public function findAll($boardId) { public function findAll($boardId, $since = 0) {
if (is_numeric($boardId) === false) { if (is_numeric($boardId) === false) {
throw new BadRequestException('boardId must be a number'); throw new BadRequestException('boardId must be a number');
} }
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ); $this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ);
$stacks = $this->stackMapper->findAll($boardId); $stacks = $this->stackMapper->findAll($boardId);
$this->enrichStacksWithCards($stacks); $this->enrichStacksWithCards($stacks, $since);
return $stacks; return $stacks;
} }