1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Canvas\Cli\Tasks; |
4
|
|
|
|
5
|
|
|
use Phalcon\Cli\Task as PhTask; |
|
|
|
|
6
|
|
|
use Canvas\Models\Users; |
7
|
|
|
use Canvas\Queue\Queue; |
8
|
|
|
use RuntimeException; |
9
|
|
|
use Canvas\Notifications\Notification; |
10
|
|
|
use Phalcon\Mvc\Model; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* CLI To send push ontification and pusher msg. |
14
|
|
|
* |
15
|
|
|
* @package Canvas\Cli\Tasks |
16
|
|
|
* |
17
|
|
|
* @property Config $config |
18
|
|
|
* @property \Pusher\Pusher $pusher |
19
|
|
|
* @property \Monolog\Logger $log |
20
|
|
|
* @property Channel $channel |
21
|
|
|
* @property Queue $queue |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
class QueueTask extends PhTask |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Queue action for mobile notifications. |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function mainAction(array $params): void |
31
|
|
|
{ |
32
|
|
|
echo "Canvas Ecosystem Queue Jobs: events | notifications".PHP_EOL; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Queue to process internal Canvas Events. |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function eventsAction() |
41
|
|
|
{ |
42
|
|
|
$callback = function ($msg) { |
43
|
|
|
//we get the data from our event trigger and unserialize |
44
|
|
|
$event = unserialize($msg->body); |
45
|
|
|
|
46
|
|
|
//overwrite the user who is running this process |
47
|
|
|
if (isset($event['userData']) && $event['userData'] instanceof Users) { |
48
|
|
|
$this->di->setShared('userData', $event['userData']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
//lets fire the event |
52
|
|
|
$this->events->fire($event['event'], $event['source'], $event['data']); |
53
|
|
|
|
54
|
|
|
echo "Event Fired ({$event['event']}) - Process ID " . $msg->delivery_info['consumer_tag'].PHP_EOL; |
55
|
|
|
$this->log->info("Notification ({$event['event']}) - Process ID " . $msg->delivery_info['consumer_tag']); |
56
|
|
|
}; |
57
|
|
|
|
58
|
|
|
Queue::process(QUEUE::EVENTS, $callback); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Queue to process internal Canvas Events. |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function notificationsAction() |
67
|
|
|
{ |
68
|
|
|
$callback = function ($msg) { |
69
|
|
|
//we get the data from our event trigger and unserialize |
70
|
|
|
$notification = unserialize($msg->body); |
71
|
|
|
|
72
|
|
|
//overwrite the user who is running this process |
73
|
|
|
if ($notification['from'] instanceof Users) { |
74
|
|
|
$this->di->setShared('userData', $notification['from']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (!$notification['to'] instanceof Users) { |
78
|
|
|
echo 'Attribute TO has to be a User'.PHP_EOL; |
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (!class_exists($notification['notification'])) { |
83
|
|
|
echo 'Attribute notification has to be a Notificatoin'.PHP_EOL; |
84
|
|
|
return; |
85
|
|
|
} |
86
|
|
|
$notificationClass = $notification['notification']; |
87
|
|
|
|
88
|
|
|
if (!$notification['entity'] instanceof Model) { |
89
|
|
|
echo 'Attribute entity has to be a Model'.PHP_EOL; |
90
|
|
|
return; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$user = $notification['to']; |
94
|
|
|
|
95
|
|
|
//instance notification and pass the entity |
96
|
|
|
$notification = new $notification['notification']($notification['entity']); |
97
|
|
|
//disable the queue so we process it now |
98
|
|
|
$notification->disableQueue(); |
99
|
|
|
|
100
|
|
|
//run notify for the specifiy user |
101
|
|
|
$user->notify($notification); |
102
|
|
|
|
103
|
|
|
echo "Notification ({$notificationClass}) sent to {$user->email} - Process ID " . $msg->delivery_info['consumer_tag'].PHP_EOL; |
104
|
|
|
$this->log->info("Notification ({$notificationClass}) sent to {$user->email} - Process ID " . $msg->delivery_info['consumer_tag']); |
105
|
|
|
}; |
106
|
|
|
|
107
|
|
|
Queue::process(QUEUE::NOTIFICATIONS, $callback); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths