Completed
Push — develop ( 2d4f17...d5975b )
by Nate
05:25
created

SyncItemTo::getConfirmationMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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\fields\actions;
10
11
use Craft;
12
use craft\base\ElementInterface;
13
use flipbox\craft\hubspot\fields\ObjectsFieldInterface;
14
use flipbox\craft\integration\fields\actions\AbstractIntegrationItemAction;
15
use flipbox\craft\integration\fields\Integrations;
16
use flipbox\craft\integration\records\IntegrationAssociation;
17
18
class SyncItemTo extends AbstractIntegrationItemAction
19
{
20
    /**
21
     * @inheritdoc
22
     */
23
    public function getTriggerLabel(): string
24
    {
25
        return Craft::t('hubspot', 'Sync To HubSpot');
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function getConfirmationMessage()
32
    {
33
        return Craft::t('hubspot', "Performing a sync will transmit any unsaved data.  Please confirm to continue.");
34
    }
35
36
    /**
37
     * @inheritdoc
38
     * @throws \Throwable
39
     */
40
    public function performAction(Integrations $field, ElementInterface $element, IntegrationAssociation $record): bool
41
    {
42
        if (!$field instanceof ObjectsFieldInterface) {
43
            $this->setMessage("Invalid field type.");
44
            return false;
45
        }
46
47
        if (!$field->syncToHubSpot($element)) {
48
            $this->setMessage("Failed to sync to HubSpot");
49
            return false;
50
        }
51
52
        $this->setMessage("Sync to HubSpot executed successfully");
53
        return true;
54
    }
55
}
56