Completed
Push — develop ( f7632c...dc861e )
by Nate
09:06
created

SyncItemFrom::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\hubspot\fields\actions;
10
11
use Craft;
12
use craft\base\ElementInterface;
13
use flipbox\hubspot\records\ObjectAssociation;
14
use flipbox\hubspot\transformers\collections\TransformerCollection;
15
use flipbox\hubspot\fields\Objects;
16
use flipbox\hubspot\HubSpot;
17
18
class SyncItemFrom extends AbstractObjectItemAction
19
{
20
    /**
21
     * @inheritdoc
22
     */
23
    public function getTriggerLabel(): string
24
    {
25
        return Craft::t('hubspot', 'Sync From HubSpot');
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function getConfirmationMessage()
32
    {
33
        return Craft::t('hubspot', "Performing a sync will override any unsaved data.  Please confirm to continue.");
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function performAction(Objects $field, ElementInterface $element, ObjectAssociation $record): bool
40
    {
41
        $resource = $field->getResource();
42
43
        if (!$resource->syncDown($element, $field, null, null, new TransformerCollection())) {
44
            $this->setMessage("Failed to sync from HubSpot Object");
45
            return false;
46
        }
47
48
        $this->setMessage("Sync from HubSpot executed successfully");
49
        return true;
50
    }
51
}
52