You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.1 KiB

  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\ModelSaved;
  4. use App\Models\Activity;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Queue\InteractsWithQueue;
  7. use Illuminate\Support\Facades\Log;
  8. class ActivityRegistration implements ShouldQueue
  9. {
  10. /**
  11. * If your queue connection's after_commit configuration option is set to true,
  12. * indicate that a particular queued listener should be dispatched after all database transactions closed
  13. *
  14. * @var boolean
  15. */
  16. public $afterCommit = true;
  17. /**
  18. * The name of the connection the job should be sent to.
  19. *
  20. * @var string|null
  21. */
  22. public $connection = 'redis';
  23. /**
  24. * The name of the queue the job should be sent to.
  25. * It's just a name and if don't set it, laravel use default queue name in the connection
  26. *
  27. * @var string|null
  28. */
  29. public $queue = 'activities';
  30. /**
  31. * Create the event listener.
  32. *
  33. * @return void
  34. */
  35. public function __construct()
  36. {
  37. //
  38. }
  39. /**
  40. * Handle the event.
  41. *
  42. * @param ModelSaved $event
  43. * @return void
  44. */
  45. public function handle(ModelSaved $event)
  46. {
  47. Log::info('listener:'. json_encode($event->message));
  48. $message = json_decode($event->message);
  49. Activity::create([
  50. 'business_id' => $message->business,
  51. 'project_id' => $message->project,
  52. 'actor_id' => $message->auth,
  53. 'system_id' => $message->data->system_id,
  54. 'workflow_id' => $message->data->workflow_id,
  55. 'status_id' => $message->data->status_id,
  56. 'sprint_id' => $message->data->sprint_id,
  57. 'task_id' => $message->data->task_id ?? null,
  58. 'subject_id' => $message->data->subject_id ?? null,
  59. 'user_id' => $message->data->user_id,
  60. 'crud_id' => $message->data->crud_id,
  61. 'table_id' => enum('tables.'.$message->data->table_name.'.id'),
  62. 'original' => $message->data->original,
  63. 'diff' => $message->data->diff,
  64. ]);
  65. }
  66. }