Reuse single board transfer for all user boards
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -77,12 +77,14 @@ final class TransferOwnership extends Command {
|
|||||||
|
|
||||||
if ($boardId) {
|
if ($boardId) {
|
||||||
$this->boardService->transferBoardOwnership($boardId, $newOwner, $remapAssignment);
|
$this->boardService->transferBoardOwnership($boardId, $newOwner, $remapAssignment);
|
||||||
$output->writeln("Board " . $board->getTitle() . " from ". $board->getOwner() ." transferred to $newOwner completed");
|
$output->writeln("<info>Board " . $board->getTitle() . " from ". $board->getOwner() ." transferred to $newOwner completed</info>");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->boardService->transferOwnership($owner, $newOwner, $remapAssignment);
|
foreach ($this->boardService->transferOwnership($owner, $newOwner, $remapAssignment) as $board) {
|
||||||
$output->writeln("All boards from $owner to $newOwner transferred");
|
$output->writeln(" - " . $board->getTitle() . " transferred");
|
||||||
|
}
|
||||||
|
$output->writeln("<info>All boards from $owner to $newOwner transferred</info>");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -678,42 +678,32 @@ class BoardService {
|
|||||||
return $newBoard;
|
return $newBoard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transferBoardOwnership(int $boardId, string $newOwner, $changeContent = false): void {
|
public function transferBoardOwnership(int $boardId, string $newOwner, bool $changeContent = false): Board {
|
||||||
$board = $this->boardMapper->find($boardId);
|
\OC::$server->getDatabaseConnection()->beginTransaction();
|
||||||
$previousOwner = $board->getOwner();
|
try {
|
||||||
$this->clearBoardFromCache($board);
|
$board = $this->boardMapper->find($boardId);
|
||||||
$this->aclMapper->deleteParticipantFromBoard($boardId, Acl::PERMISSION_TYPE_USER, $newOwner);
|
$previousOwner = $board->getOwner();
|
||||||
$this->boardMapper->transferOwnership($previousOwner, $newOwner, $boardId);
|
$this->clearBoardFromCache($board);
|
||||||
|
$this->aclMapper->deleteParticipantFromBoard($boardId, Acl::PERMISSION_TYPE_USER, $newOwner);
|
||||||
|
$this->boardMapper->transferOwnership($previousOwner, $newOwner, $boardId);
|
||||||
|
|
||||||
// Optionally also change user assignments and card owner information
|
// Optionally also change user assignments and card owner information
|
||||||
if ($changeContent) {
|
if ($changeContent) {
|
||||||
$this->assignedUsersMapper->remapAssignedUser($boardId, $previousOwner, $newOwner);
|
$this->assignedUsersMapper->remapAssignedUser($boardId, $previousOwner, $newOwner);
|
||||||
$this->cardMapper->remapCardOwner($boardId, $previousOwner, $newOwner);
|
$this->cardMapper->remapCardOwner($boardId, $previousOwner, $newOwner);
|
||||||
|
}
|
||||||
|
\OC::$server->getDatabaseConnection()->commit();
|
||||||
|
return $this->boardMapper->find($boardId);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
\OC::$server->getDatabaseConnection()->rollBack();
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transferOwnership(string $owner, string $newOwner, $changeContent = false): void {
|
public function transferOwnership(string $owner, string $newOwner, bool $changeContent = false): \Generator {
|
||||||
\OC::$server->getDatabaseConnection()->beginTransaction();
|
$boards = $this->boardMapper->findAllByUser($owner);
|
||||||
try {
|
foreach ($boards as $board) {
|
||||||
$boards = $this->boardMapper->findAllByUser($owner);
|
yield $this->transferBoardOwnership($board->getId(), $newOwner, $changeContent);
|
||||||
foreach ($boards as $board) {
|
|
||||||
$this->clearBoardFromCache($board);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->boardMapper->transferOwnership($owner, $newOwner);
|
|
||||||
// Optionally also change user assignments and card owner information
|
|
||||||
if ($changeContent) {
|
|
||||||
foreach ($boards as $board) {
|
|
||||||
$this->clearBoardFromCache($board);
|
|
||||||
$this->aclMapper->deleteParticipantFromBoard($board->getId(), Acl::PERMISSION_TYPE_USER, $newOwner);
|
|
||||||
$this->assignedUsersMapper->remapAssignedUser($board->getId(), $owner, $newOwner);
|
|
||||||
$this->cardMapper->remapCardOwner($board->getId(), $owner, $newOwner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
\OC::$server->getDatabaseConnection()->commit();
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
\OC::$server->getDatabaseConnection()->rollBack();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user