This commit is contained in:
Patrick Niebeling
2025-03-12 11:11:19 +01:00
parent 4e4ae2b372
commit 7f683fcec1
16 changed files with 211 additions and 154 deletions

View File

@ -1,32 +0,0 @@
<?php
namespace OCA\Deckflow\AppInfo;
use OCP\AppFramework\App;
use OCA\Deckflow\Controller\SettingsController;
use OCA\Deckflow\Cron\MoveOverdueCardsJob;
use OCP\IContainer;
class Application extends App {
public function __construct(array $urlParams = []) {
parent::__construct('deckflow', $urlParams);
$container = $this->getContainer();
// Routen für das Backend
$container->registerService('SettingsController', function(IContainer $c) {
return new SettingsController(
$c->query('OCP\IRequest'),
$c->query('OCP\IUserSession'),
$c->query('OCA\Deckflow\Service\WorkflowService'),
$c->query('OCP\IDBConnection')
);
});
// CronJob registrieren
$container->registerService('MoveOverdueCardsJob', function(IContainer $c) {
return new MoveOverdueCardsJob(
$c->query('OCA\Deckflow\Service\WorkflowService')
);
});
}
}

View File

@ -1,21 +0,0 @@
<?php
namespace OCA\Deckflow\DB;
use OCP\DB\ISQLiteConnection;
class Migration {
/**
* Erstellt die Tabelle für Workflow-Konfigurationen
* @param ISQLiteConnection $connection
*/
public function createWorkflowConfigTable(ISQLiteConnection $connection) {
$connection->query("CREATE TABLE IF NOT EXISTS *PREFIX*deckflow_workflows (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT NOT NULL,
deck_id TEXT NOT NULL,
source_stack_id TEXT NOT NULL,
target_stack_id TEXT NOT NULL
)");
}
}

View File

@ -1,27 +0,0 @@
<?php
namespace OCA\Deckflow\Cron;
use OCP\BackgroundJob\TimedJob;
use OCA\Deckflow\Service\WorkflowService;
class MoveOverdueCardsJob extends TimedJob {
private $workflowService;
public function __construct(WorkflowService $workflowService) {
parent::__construct();
$this->workflowService = $workflowService;
}
/**
* Ausführen des Cronjobs
*/
protected function run($argument) {
try {
// Überfällige Karten verschieben
$this->workflowService->moveOverdueCards();
} catch (\Exception $e) {
\OCP\Util::writeLog('deckflow', 'Fehler beim Ausführen des Cronjobs: ' . $e->getMessage(), \OCP\Util::ERROR);
}
}
}

View File

@ -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.");
}
}