Issues (3627)

app/bundles/ChannelBundle/Entity/MessageQueue.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\ChannelBundle\Entity;
13
14
use Doctrine\ORM\Mapping as ORM;
15
use Mautic\CampaignBundle\Entity\Event;
16
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
17
use Mautic\LeadBundle\Entity\Lead;
18
19
/**
20
 * Class MessageQueue.
21
 */
22
class MessageQueue
23
{
24
    const STATUS_RESCHEDULED = 'rescheduled';
25
    const STATUS_PENDING     = 'pending';
26
    const STATUS_SENT        = 'sent';
27
    const STATUS_CANCELLED   = 'cancelled';
28
29
    const PRIORITY_NORMAL = 2;
30
    const PRIORITY_HIGH   = 1;
31
32
    /**
33
     * @var int
34
     */
35
    private $id;
36
37
    /**
38
     * @var string
39
     */
40
    private $channel;
41
42
    private $channelId;
43
44
    /**
45
     * @var Event
46
     */
47
    private $event;
48
49
    /**
50
     * @var \Mautic\LeadBundle\Entity\Lead
51
     */
52
    private $lead;
53
54
    /**
55
     * @var int
56
     */
57
    private $priority = 2;
58
59
    /**
60
     * @var int
61
     */
62
    private $maxAttempts = 3;
63
64
    /**
65
     * @var int
66
     */
67
    private $attempts = 0;
68
69
    /**
70
     * @var bool
71
     */
72
    private $success = false;
73
74
    /**
75
     * @var string
76
     */
77
    private $status = self::STATUS_PENDING;
78
79
    /**
80
     * @var \DateTime
81
     **/
82
    private $datePublished;
83
84
    /**
85
     * @var \DateTime|null
86
     */
87
    private $scheduledDate;
88
89
    /**
90
     * @var \DateTime|null
91
     */
92
    private $lastAttempt;
93
94
    /**
95
     * @var \DateTime|null
96
     */
97
    private $dateSent;
98
99
    private $options = [];
100
101
    /**
102
     * Used by listeners to note if the message had been processed in bulk.
103
     *
104
     * @var bool
105
     */
106
    private $processed = false;
107
108
    /**
109
     * Used by listeners to tell the event dispatcher the message needs to be retried in 15 minutes.
110
     *
111
     * @var bool
112
     */
113
    private $failed = false;
114
115
    /**
116
     * @var bool
117
     */
118
    private $metadataUpdated = false;
119
120
    public static function loadMetadata(ORM\ClassMetadata $metadata)
121
    {
122
        $builder = new ClassMetadataBuilder($metadata);
123
124
        $builder->setTable('message_queue')
125
            ->setCustomRepositoryClass('Mautic\ChannelBundle\Entity\MessageQueueRepository')
126
            ->addIndex(['status'], 'message_status_search')
127
            ->addIndex(['date_sent'], 'message_date_sent')
128
            ->addIndex(['scheduled_date'], 'message_scheduled_date')
129
            ->addIndex(['priority'], 'message_priority')
130
            ->addIndex(['success'], 'message_success')
131
            ->addIndex(['channel', 'channel_id'], 'message_channel_search');
132
133
        $builder->addBigIntIdField();
134
135
        $builder->addField('channel', 'string');
136
        $builder->addNamedField('channelId', 'integer', 'channel_id');
137
138
        $builder->createManyToOne('event', 'Mautic\CampaignBundle\Entity\Event')
139
            ->addJoinColumn('event_id', 'id', true, false, 'CASCADE')
140
            ->build();
141
142
        $builder->addLead(false, 'CASCADE', false);
0 ignored issues
show
Deprecated Code introduced by
The function Mautic\CoreBundle\Doctri...adataBuilder::addLead() has been deprecated: Use addContact instead; existing implementations will need a migration to rename lead_id to contact_id ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

142
        /** @scrutinizer ignore-deprecated */ $builder->addLead(false, 'CASCADE', false);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
143
144
        $builder->createField('priority', 'smallint')
145
            ->columnName('priority')
146
            ->build();
147
148
        $builder->createField('maxAttempts', 'smallint')
149
            ->columnName('max_attempts')
150
            ->build();
151
152
        $builder->createField('attempts', 'smallint')
153
            ->columnName('attempts')
154
            ->build();
155
156
        $builder->createField('success', 'boolean')
157
            ->columnName('success')
158
            ->build();
159
160
        $builder->createField('status', 'string')
161
            ->columnName('status')
162
            ->build();
163
164
        $builder->createField('datePublished', 'datetime')
165
            ->columnName('date_published')
166
            ->nullable()
167
            ->build();
168
169
        $builder->createField('scheduledDate', 'datetime')
170
            ->columnName('scheduled_date')
171
            ->nullable()
172
            ->build();
173
174
        $builder->createField('lastAttempt', 'datetime')
175
            ->columnName('last_attempt')
176
            ->nullable()
177
            ->build();
178
179
        $builder->createField('dateSent', 'datetime')
180
            ->columnName('date_sent')
181
            ->nullable()
182
            ->build();
183
184
        $builder->createField('options', 'array')
185
            ->nullable()
186
            ->build();
187
    }
188
189
    /**
190
     * @return int
191
     */
192
    public function getId()
193
    {
194
        return $this->id;
195
    }
196
197
    /**
198
     * @return int
199
     */
200
    public function getAttempts()
201
    {
202
        return $this->attempts;
203
    }
204
205
    /**
206
     * @param int $attempts
207
     */
208
    public function setAttempts($attempts)
209
    {
210
        $this->attempts = $attempts;
211
    }
212
213
    /**
214
     * @return array
215
     */
216
    public function getOptions()
217
    {
218
        return $this->options;
219
    }
220
221
    /**
222
     * @param array $options
223
     */
224
    public function setOptions($options)
225
    {
226
        $this->options[] = $options;
227
    }
228
229
    /**
230
     * @return string
231
     */
232
    public function getChannel()
233
    {
234
        return $this->channel;
235
    }
236
237
    /**
238
     * @param string $channel
239
     */
240
    public function setChannel($channel)
241
    {
242
        $this->channel = $channel;
243
    }
244
245
    /**
246
     * @return mixed
247
     */
248
    public function getChannelId()
249
    {
250
        return $this->channelId;
251
    }
252
253
    /**
254
     * @param mixed $channelId
255
     *
256
     * @return MessageQueue
257
     */
258
    public function setChannelId($channelId)
259
    {
260
        $this->channelId = $channelId;
261
262
        return $this;
263
    }
264
265
    /**
266
     * @return Event
267
     */
268
    public function getEvent()
269
    {
270
        return $this->event;
271
    }
272
273
    /**
274
     * @return MessageQueue
275
     */
276
    public function setEvent(Event $event)
277
    {
278
        $this->event = $event;
279
280
        return $this;
281
    }
282
283
    /**
284
     * @return \DateTime
285
     */
286
    public function getDatePublished()
287
    {
288
        return $this->datePublished;
289
    }
290
291
    /**
292
     * @param \DateTime $datePublished
293
     */
294
    public function setDatePublished($datePublished)
295
    {
296
        $this->datePublished = $datePublished;
297
    }
298
299
    /**
300
     * @return \DateTime
301
     */
302
    public function getDateSent()
303
    {
304
        return $this->dateSent;
305
    }
306
307
    /**
308
     * @param \DateTime $dateSent
309
     */
310
    public function setDateSent($dateSent)
311
    {
312
        $this->dateSent = $dateSent;
313
    }
314
315
    /**
316
     * @return \DateTime
317
     */
318
    public function getLastAttempt()
319
    {
320
        return $this->lastAttempt;
321
    }
322
323
    /**
324
     * @param \DateTime $lastAttempt
325
     */
326
    public function setLastAttempt($lastAttempt)
327
    {
328
        $this->lastAttempt = $lastAttempt;
329
    }
330
331
    /**
332
     * @return Lead
333
     */
334
    public function getLead()
335
    {
336
        return $this->lead;
337
    }
338
339
    public function setLead(Lead $lead)
340
    {
341
        $this->lead = $lead;
342
    }
343
344
    /**
345
     * @return int
346
     */
347
    public function getMaxAttempts()
348
    {
349
        return $this->maxAttempts;
350
    }
351
352
    /**
353
     * @param int $maxAttempts
354
     */
355
    public function setMaxAttempts($maxAttempts)
356
    {
357
        $this->maxAttempts = $maxAttempts;
358
    }
359
360
    /**
361
     * @return int
362
     */
363
    public function getPriority()
364
    {
365
        return $this->priority;
366
    }
367
368
    /**
369
     * @param int $priority
370
     */
371
    public function setPriority($priority)
372
    {
373
        $this->priority = $priority;
374
    }
375
376
    /**
377
     * @return \DateTime
378
     */
379
    public function getScheduledDate()
380
    {
381
        return $this->scheduledDate;
382
    }
383
384
    /**
385
     * @param mixed $scheduledDate
386
     */
387
    public function setScheduledDate($scheduledDate)
388
    {
389
        $this->scheduledDate = $scheduledDate;
390
    }
391
392
    /**
393
     * @return string
394
     */
395
    public function getStatus()
396
    {
397
        return $this->status;
398
    }
399
400
    /**
401
     * @param string $status
402
     */
403
    public function setStatus($status)
404
    {
405
        $this->status = $status;
406
    }
407
408
    /**
409
     * @return bool
410
     */
411
    public function getSuccess()
412
    {
413
        return $this->success;
414
    }
415
416
    /**
417
     * @return bool
418
     */
419
    public function isSuccess()
420
    {
421
        return $this->success;
422
    }
423
424
    /**
425
     * @param bool $success
426
     */
427
    public function setSuccess($success = true)
428
    {
429
        $this->success = $success;
430
    }
431
432
    /**
433
     * @return bool
434
     */
435
    public function isFailed()
436
    {
437
        return $this->failed;
438
    }
439
440
    /**
441
     * @param bool $failed
442
     *
443
     * @return MessageQueue
444
     */
445
    public function setFailed($failed = true)
446
    {
447
        $this->failed = $failed;
448
449
        return $this;
450
    }
451
452
    /**
453
     * @return bool
454
     */
455
    public function isProcessed()
456
    {
457
        return $this->processed;
458
    }
459
460
    /**
461
     * @param bool $processed
462
     *
463
     * @return MessageQueue
464
     */
465
    public function setProcessed($processed = true)
466
    {
467
        $this->processed = $processed;
468
469
        return $this;
470
    }
471
472
    /**
473
     * @return array|mixed
474
     */
475
    public function getMetadata()
476
    {
477
        return (isset($this->options['metadata'])) ? $this->options['metadata'] : [];
478
    }
479
480
    public function setMetadata(array $metadata = [])
481
    {
482
        $this->metadataUpdated     = true;
483
        $this->options['metadata'] = $metadata;
484
    }
485
486
    /**
487
     * @return bool
488
     */
489
    public function wasMetadataUpdated()
490
    {
491
        return $this->metadataUpdated;
492
    }
493
}
494