Completed
Push — master ( 53e590...136153 )
by Nate
16:58 queued 14:19
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\force\fields\SObjects;
15
use flipbox\force\Force;
16
use flipbox\hubspot\fields\Objects;
17
use flipbox\hubspot\records\ObjectAssociation;
18
use flipbox\hubspot\transformers\collections\TransformerCollection;
19
20
class SyncItemTo extends AbstractObjectItemAction
21
{
22
    /**
23
     * @inheritdoc
24
     */
25
    public function getTriggerLabel(): string
26
    {
27
        return Craft::t('hubspot', 'Sync To HubSpot');
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function getConfirmationMessage()
34
    {
35
        return Craft::t('hubspot', "Performing a sync will transmit any unsaved data.  Please confirm to continue.");
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function performAction(Objects $field, ElementInterface $element, ObjectAssociation $record): bool
42
    {
43
        $resource = $field->getResource();
44
45
        if (!$resource->syncUp($element, $field, null, null, new TransformerCollection())) {
46
            $this->setMessage("Failed to sync to HubSpot Object");
47
            return false;
48
        }
49
50
        $this->setMessage("Sync to HubSpot executed successfully");
51
        return true;
52
    }
53
}
54