Skip to content

Commit b840163

Browse files
authored
Merge pull request #227 from PowerSync/develop
Develop
2 parents 5755af9 + cdcac00 commit b840163

File tree

18 files changed

+1290
-24
lines changed

18 files changed

+1290
-24
lines changed

Model/Entity/SalesforceIdStorage.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,30 @@ public function __construct(
6767
Objects $resourceObjects,
6868
StoreManagerInterface $storeManager,
6969
Config $config
70-
)
71-
{
70+
) {
7271
$this->resourceObjects = $resourceObjects;
7372
$this->magentoType = $magentoType;
7473
$this->mappingAttribute = $mappingAttribute;
7574
$this->storeManager = $storeManager;
7675
$this->config = $config;
7776
}
7877

78+
/**
79+
* @return string
80+
*/
81+
public function getMagentoType()
82+
{
83+
return $this->magentoType;
84+
}
85+
86+
/**
87+
* @param string $magentoType
88+
*/
89+
public function setMagentoType(string $magentoType)
90+
{
91+
$this->magentoType = $magentoType;
92+
}
93+
7994
/**
8095
* @return array
8196
*/
@@ -214,7 +229,16 @@ public function saveStatus($entity, $status, $website = null)
214229
*/
215230
public function valueByAttribute($entity, $attributeName)
216231
{
217-
return $entity->getData($attributeName);
232+
$method = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $attributeName)));
233+
if (method_exists($entity, $method)) {
234+
return $entity->{$method}();
235+
} elseif (method_exists($entity, 'getData')) {
236+
return $entity->getData($attributeName);
237+
} else {
238+
$dump = $entity->__toArray();
239+
return $dump[$attributeName];
240+
}
241+
return null;
218242
}
219243

220244
/**

Synchronize/Queue/Add.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public function __construct(
9292
PreQueue $resourcePreQueue,
9393
ManagerInterface $messageManager,
9494
State $state
95-
)
96-
{
95+
) {
9796
$this->resolves = $resolves;
9897
$this->entityType = $entityType;
9998
$this->storeManager = $storeManager;
@@ -114,7 +113,7 @@ public function __construct(
114113
*/
115114
public function addToQueue(array $entityIds)
116115
{
117-
$entityIds = array_filter($entityIds);
116+
// $entityIds = array_filter($entityIds);
118117
if (empty($entityIds)) {
119118
return;
120119
}
@@ -226,9 +225,7 @@ public function generateQueueObjects(
226225
&$dependencies,
227226
&$queuesUnique = [],
228227
$relatedUnitCode = null
229-
)
230-
{
231-
228+
) {
232229
$queues = [];
233230
$parents = $children = [];
234231

@@ -264,7 +261,6 @@ public function generateQueueObjects(
264261
}
265262
}
266263
} else {
267-
268264
$currentEntityIds = [];
269265
$currentByEntityLoad = [];
270266
foreach ([$current] as $relation) {
@@ -372,8 +368,7 @@ public function create(
372368
array $loadAdditional,
373369
$websiteId,
374370
$syncType
375-
)
376-
{
371+
) {
377372
$dependencies = [];
378373
/**
379374
* collect all queue objects and build dependencies
@@ -446,9 +441,7 @@ public function buildGraph($queueDataToSave, $dependencies)
446441
*/
447442
public function saveQueue($queueDataToSave)
448443
{
449-
450444
if (!empty($queueDataToSave)) {
451-
452445
$this
453446
->resourceQueue
454447
->getConnection()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace TNW\Salesforce\Synchronize\Transport\Calls\Delete;
4+
5+
/**
6+
* Unit interface
7+
*/
8+
interface InputInterface
9+
{
10+
/**
11+
* Do Unit syncronization to Salesforce object
12+
*
13+
* @param Transport\Input $input
14+
*/
15+
public function process(Transport\Input $input);
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace TNW\Salesforce\Synchronize\Transport\Calls\Delete;
4+
5+
/**
6+
* Unit interface
7+
*/
8+
interface OutputInterface
9+
{
10+
/**
11+
* Do Unit syncronization to Salesforce object
12+
*
13+
* @param Transport\Output $output
14+
*/
15+
public function process(Transport\Output $output);
16+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
3+
namespace TNW\Salesforce\Synchronize\Transport\Calls\Delete\Transport;
4+
5+
use SplObjectStorage;
6+
use function spl_object_hash;
7+
8+
/**
9+
* Upsert Transport Input
10+
*/
11+
class Input extends SplObjectStorage
12+
{
13+
/**
14+
* @var string
15+
*/
16+
protected $externalIdFieldName = '';
17+
/**
18+
* @var string
19+
*/
20+
protected $type = '';
21+
/**
22+
* @var array
23+
*/
24+
private $info = [];
25+
26+
/**
27+
* Data constructor.
28+
*
29+
* @param string $type
30+
* @param string $externalIdFieldName
31+
*/
32+
public function __construct($type = '', $externalIdFieldName = 'Id')
33+
{
34+
$this->type = $type;
35+
$this->externalIdFieldName = $externalIdFieldName;
36+
}
37+
38+
/**
39+
* External Id Field Name
40+
*
41+
* @return string
42+
*/
43+
public function externalIdFieldName()
44+
{
45+
return $this->externalIdFieldName;
46+
}
47+
48+
/**
49+
* Type
50+
*
51+
* @return string
52+
*/
53+
public function type()
54+
{
55+
return $this->type;
56+
}
57+
58+
/**
59+
* Offset Get
60+
*
61+
* @param object $object
62+
* @return array
63+
*/
64+
public function &offsetGet($object)
65+
{
66+
if (!$this->contains($object)) {
67+
$this->offsetSet($object, []);
68+
}
69+
70+
return $this->info[parent::offsetGet($object)];
71+
}
72+
73+
/**
74+
* Offset Set
75+
*
76+
* @param object $object
77+
* @param array $data
78+
*/
79+
public function offsetSet($object, $data = null)
80+
{
81+
$index = spl_object_hash($object);
82+
parent::offsetSet($object, $index);
83+
$this->info[$index] = $data;
84+
}
85+
86+
/**
87+
* Get Info
88+
*
89+
* @return array
90+
*/
91+
public function getInfo()
92+
{
93+
return $this->info[parent::getInfo()];
94+
}
95+
96+
/**
97+
* Set Info
98+
*
99+
* @param array $data
100+
*/
101+
public function setInfo($data)
102+
{
103+
$index = spl_object_hash($this->current());
104+
parent::setInfo($index);
105+
$this->info[$index] = $data;
106+
}
107+
108+
/**
109+
* Offset Unset
110+
*
111+
* @param object $object
112+
*/
113+
public function offsetUnset($object)
114+
{
115+
unset($this->info[parent::offsetGet($object)]);
116+
parent::offsetUnset($object);
117+
}
118+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
namespace TNW\Salesforce\Synchronize\Transport\Calls\Delete\Transport;
4+
5+
use SplObjectStorage;
6+
use function spl_object_hash;
7+
8+
/**
9+
* Upsert Transport Output
10+
*/
11+
class Output extends SplObjectStorage
12+
{
13+
/**
14+
* @var string
15+
*/
16+
protected $type;
17+
/**
18+
* @var
19+
*/
20+
protected $unit;
21+
/**
22+
* @var array
23+
*/
24+
private $info = [];
25+
26+
/**
27+
* Data constructor.
28+
*
29+
* @param string $type
30+
*/
31+
public function __construct($type = '')
32+
{
33+
$this->type = $type;
34+
}
35+
36+
/**
37+
* @return mixed
38+
*/
39+
public function getUnit()
40+
{
41+
return $this->unit;
42+
}
43+
44+
/**
45+
* @param mixed $unit
46+
*/
47+
public function setUnit($unit)
48+
{
49+
$this->unit = $unit;
50+
}
51+
52+
/**
53+
* Type
54+
*
55+
* @return string
56+
*/
57+
public function type()
58+
{
59+
return $this->type;
60+
}
61+
62+
/**
63+
* Offset Get
64+
*
65+
* @param object $object
66+
* @return array
67+
*/
68+
public function &offsetGet($object)
69+
{
70+
if (!$this->contains($object)) {
71+
$this->offsetSet($object, []);
72+
}
73+
74+
return $this->info[parent::offsetGet($object)];
75+
}
76+
77+
/**
78+
* Offset Set
79+
*
80+
* @param object $object
81+
* @param array $data
82+
*/
83+
public function offsetSet($object, $data = null)
84+
{
85+
$index = spl_object_hash($object);
86+
parent::offsetSet($object, $index);
87+
$this->info[$index] = $data;
88+
}
89+
90+
/**
91+
* Get Info
92+
*
93+
* @return array
94+
*/
95+
public function getInfo()
96+
{
97+
return $this->info[parent::getInfo()];
98+
}
99+
100+
/**
101+
* Set Info
102+
*
103+
* @param array $data
104+
*/
105+
public function setInfo($data)
106+
{
107+
$index = spl_object_hash($this->current());
108+
parent::setInfo($index);
109+
$this->info[$index] = $data;
110+
}
111+
112+
/**
113+
* Offset Unset
114+
*
115+
* @param object $object
116+
*/
117+
public function offsetUnset($object)
118+
{
119+
unset($this->info[parent::offsetGet($object)]);
120+
parent::offsetUnset($object);
121+
}
122+
}

0 commit comments

Comments
 (0)