PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Database / Repository / QueueJobRepository.php

QueueJobRepository.php in Depicter — Popup & Slider Builder trunk, at app/src/Database/Repository/QueueJobRepository.php

71 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Database\Repository;
4
5 use Depicter\Database\Entity\QueueJob;
6 use Depicter\Utility\Sanitize;
7
8 class QueueJobRepository
9 {
10
11 private QueueJob $job;
12
13 public function __construct(){
14 $this->job = QueueJob::new();
15 }
16
17 /**
18 * Access to an instance of Lead entity
19 *
20 * @return QueueJob
21 */
22 public function job(): QueueJob{
23 return QueueJob::new();
24 }
25
26 public function create( $queue, $payload ) {
27 return $this->job()->create([
28 'queue' => $queue,
29 'payload' => $payload,
30 'attempts' => 0,
31 ]);
32 }
33
34 public function update( $id, array $fields = [] ) {
35 if ( empty( $fields ) ) {
36 return false;
37 }
38
39 $job = $this->job()->findById( $id );
40
41 if ( $job && $job->count() ){
42 return $job->first()->update($fields);
43 }
44
45 return false;
46 }
47
48 public function delete( $id ): bool
49 {
50 $succeed = false;
51
52 if( is_array( $id ) ){
53 $ids = $id;
54 } elseif( false !== strpos( $id, ',' ) ){
55 $ids = explode(',', $id );
56 } else {
57 $ids = [$id];
58 }
59
60 foreach( $ids as $id ){
61 $id = Sanitize::int( $id );
62 if( $job = $this->job()->findById( $id ) ){
63 $job->delete();
64 $succeed = true;
65 }
66 }
67 return $succeed;
68 }
69
70 }
71