Completed
Push — master ( 53e590...136153 )
by Nate
16:58 queued 14:19
created

SyncItemFrom   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 34
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

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