Fix
This commit is contained in:
@ -1,60 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Deckflow\Service;
|
||||
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUserSession;
|
||||
use OCA\Deck\Service\DeckService;
|
||||
use OCP\ILogger;
|
||||
use OCA\Deckflow\DB\Migration;
|
||||
|
||||
class WorkflowService {
|
||||
|
||||
private $db;
|
||||
private $userSession;
|
||||
private $deckService;
|
||||
private $logger;
|
||||
private $db;
|
||||
|
||||
public function __construct(IUserSession $userSession, DeckService $deckService, ILogger $logger, \OCP\IDBConnection $db) {
|
||||
public function __construct(IDBConnection $db, IUserSession $userSession, DeckService $deckService) {
|
||||
$this->db = $db;
|
||||
$this->userSession = $userSession;
|
||||
$this->deckService = $deckService;
|
||||
$this->logger = $logger;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Workflows des aktuellen Benutzers
|
||||
* @return array
|
||||
*/
|
||||
private function getUserWorkflows() {
|
||||
$user = $this->userSession->getUser();
|
||||
$userId = $user ? $user->getUID() : null;
|
||||
// Speichert die Workflows
|
||||
public function saveWorkflows($deckId, $sourceStackId, $targetStackId) {
|
||||
$userId = $this->userSession->getUser()->getUID();
|
||||
$this->db->executeQuery("INSERT INTO *PREFIX*deckflow_workflows (user_id, deck_id, source_stack_id, target_stack_id)
|
||||
VALUES (?, ?, ?, ?)", [
|
||||
$userId,
|
||||
$deckId,
|
||||
$sourceStackId,
|
||||
$targetStackId
|
||||
]);
|
||||
}
|
||||
|
||||
// Hole alle Workflow-Konfigurationen des Benutzers aus der DB
|
||||
// Ruft alle Workflows für den aktuellen Benutzer ab
|
||||
public function getWorkflows() {
|
||||
$userId = $this->userSession->getUser()->getUID();
|
||||
$result = $this->db->executeQuery("SELECT * FROM *PREFIX*deckflow_workflows WHERE user_id = ?", [$userId]);
|
||||
return $result->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verschiebt überfällige Karten für alle Workflows
|
||||
*/
|
||||
public function moveOverdueCards() {
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user === null) {
|
||||
return;
|
||||
}
|
||||
// Webhook zur Ausführung des Workflows, Karten zu verschieben
|
||||
public function moveOverdueCards($deckId, $sourceStackId, $targetStackId) {
|
||||
$deck = $this->deckService->getDeckById($deckId);
|
||||
$sourceStack = $deck->getStackById($sourceStackId);
|
||||
$targetStack = $deck->getStackById($targetStackId);
|
||||
|
||||
$workflows = $this->getUserWorkflows();
|
||||
|
||||
foreach ($workflows as $workflow) {
|
||||
// Hole das Deck und die Stacks aus der Konfiguration
|
||||
$deck = $this->deckService->getDeckById($workflow['deck_id']);
|
||||
$sourceStack = $deck->getStackById($workflow['source_stack_id']);
|
||||
$targetStack = $deck->getStackById($workflow['target_stack_id']);
|
||||
|
||||
// Überprüfe alle Karten im Quellstapel auf Überfälligkeit
|
||||
foreach ($sourceStack->getCards() as $card) {
|
||||
if ($this->isCardOverdue($card)) {
|
||||
$this->moveCardToTargetStack($card, $targetStack);
|
||||
}
|
||||
foreach ($sourceStack->getCards() as $card) {
|
||||
if ($this->isCardOverdue($card)) {
|
||||
$this->moveCardToTargetStack($card, $targetStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -66,6 +57,5 @@ class WorkflowService {
|
||||
|
||||
private function moveCardToTargetStack($card, $targetStack) {
|
||||
$this->deckService->moveCardToStack($card, $targetStack);
|
||||
$this->logger->info("Card moved to target stack.");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user