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

SyncItemTo::performAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 6
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\force\criteria\SObjectCriteria;
14
use flipbox\hubspot\records\ObjectAssociation;
15
use flipbox\force\fields\SObjects;
16
use flipbox\force\Force;
17
use flipbox\hubspot\fields\Objects;
18
use flipbox\hubspot\HubSpot;
19
use flipbox\hubspot\transformers\collections\TransformerCollection;
20
21
class SyncItemTo extends AbstractObjectItemAction
22
{
23
    /**
24
     * @inheritdoc
25
     */
26
    public function getTriggerLabel(): string
27
    {
28
        return Craft::t('hubspot', 'Sync To HubSpot');
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function getConfirmationMessage()
35
    {
36
        return Craft::t('hubspot', "Performing a sync will transmit any unsaved data.  Please confirm to continue.");
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function performAction(Objects $field, ElementInterface $element, ObjectAssociation $record): bool
43
    {
44
        $resource = $field->getResource();
45
46
        if (!$resource->syncUp($element, $field, null, null, new TransformerCollection())) {
47
            $this->setMessage("Failed to sync to HubSpot Object");
48
            return false;
49
        }
50
51
        $this->setMessage("Sync to HubSpot executed successfully");
52
        return true;
53
    }
54
}
55