From cbe52e57200a66522d88dfc5d5f46de8eb87ffb2 Mon Sep 17 00:00:00 2001
From: Frederic Guillot <fred@kanboard.net>
Date: Sun, 17 Jul 2016 18:47:06 -0400
Subject: File events refactoring

---
 app/Job/NotificationJob.php     |  7 +------
 app/Job/ProjectFileEventJob.php | 45 +++++++++++++++++++++++++++++++++++++++++
 app/Job/TaskFileEventJob.php    | 45 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 6 deletions(-)
 create mode 100644 app/Job/ProjectFileEventJob.php
 create mode 100644 app/Job/TaskFileEventJob.php

(limited to 'app/Job')

diff --git a/app/Job/NotificationJob.php b/app/Job/NotificationJob.php
index cfd0699d..ed568e47 100644
--- a/app/Job/NotificationJob.php
+++ b/app/Job/NotificationJob.php
@@ -70,13 +70,8 @@ class NotificationJob extends BaseJob
                 $values['subtask'] = $this->subtaskModel->getById($event['id'], true);
                 $values['task'] = $this->taskFinderModel->getDetails($values['subtask']['task_id']);
                 break;
-            case 'Kanboard\Event\FileEvent':
-                $values['file'] = $event;
-                $values['task'] = $this->taskFinderModel->getDetails($values['file']['task_id']);
-                break;
-            case 'Kanboard\Event\CommentEvent':
+            default:
                 $values = $event;
-                break;
         }
 
         return $values;
diff --git a/app/Job/ProjectFileEventJob.php b/app/Job/ProjectFileEventJob.php
new file mode 100644
index 00000000..d68949c5
--- /dev/null
+++ b/app/Job/ProjectFileEventJob.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\EventBuilder\ProjectFileEventBuilder;
+
+/**
+ * Class ProjectFileEventJob
+ *
+ * @package Kanboard\Job
+ * @author  Frederic Guillot
+ */
+class ProjectFileEventJob extends BaseJob
+{
+    /**
+     * Set job params
+     *
+     * @param  int    $fileId
+     * @param  string $eventName
+     * @return $this
+     */
+    public function withParams($fileId, $eventName)
+    {
+        $this->jobParams = array($fileId, $eventName);
+        return $this;
+    }
+
+    /**
+     * Execute job
+     *
+     * @param  int    $fileId
+     * @param  string $eventName
+     * @return $this
+     */
+    public function execute($fileId, $eventName)
+    {
+        $event = ProjectFileEventBuilder::getInstance($this->container)
+            ->withFileId($fileId)
+            ->build();
+
+        if ($event !== null) {
+            $this->dispatcher->dispatch($eventName, $event);
+        }
+    }
+}
diff --git a/app/Job/TaskFileEventJob.php b/app/Job/TaskFileEventJob.php
new file mode 100644
index 00000000..de2c40db
--- /dev/null
+++ b/app/Job/TaskFileEventJob.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\EventBuilder\TaskFileEventBuilder;
+
+/**
+ * Class TaskFileEventJob
+ *
+ * @package Kanboard\Job
+ * @author  Frederic Guillot
+ */
+class TaskFileEventJob extends BaseJob
+{
+    /**
+     * Set job params
+     *
+     * @param  int    $fileId
+     * @param  string $eventName
+     * @return $this
+     */
+    public function withParams($fileId, $eventName)
+    {
+        $this->jobParams = array($fileId, $eventName);
+        return $this;
+    }
+
+    /**
+     * Execute job
+     *
+     * @param  int    $fileId
+     * @param  string $eventName
+     * @return $this
+     */
+    public function execute($fileId, $eventName)
+    {
+        $event = TaskFileEventBuilder::getInstance($this->container)
+            ->withFileId($fileId)
+            ->build();
+
+        if ($event !== null) {
+            $this->dispatcher->dispatch($eventName, $event);
+        }
+    }
+}
-- 
cgit v1.2.3