Completed
Push — develop ( 9a2d03...4f224f )
by Nate
09:22
created

Update::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\actions\visitors;
10
11
use Craft;
12
use flipbox\craft\ember\actions\models\UpdateModel;
13
use flipbox\craft\hubspot\HubSpot;
14
use flipbox\craft\hubspot\records\Visitor;
15
use yii\base\Model;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.1.0
20
 */
21
class Update extends UpdateModel
22
{
23
    /**
24
     * @var array
25
     */
26
    public $validBodyParams = [
27
        'status'
28
    ];
29
30
    /**
31
     * @param int|string $identifier
32
     * @return Visitor|mixed|null
33
     */
34
    protected function find($identifier)
35
    {
36
        return Visitor::findOne($identifier);
37
    }
38
39
    /**
40
     * @inheritDoc
41
     * @param Visitor $record
42
     */
43
    protected function performAction(Model $record): bool
44
    {
45
        if (!$record->save()) {
46
            return false;
47
        }
48
49
        if ($record->status == Visitor::STATUS_PENDING && Craft::$app->getRequest()->getBodyParam('queue')) {
50
            HubSpot::getInstance()->getVisitor()->syncVisitor($record);
51
        }
52
53
        return true;
54
    }
55
}
56