Skip to content

Commit

Permalink
Merge pull request #227 from PowerSync/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
eermolaev authored May 5, 2020
2 parents 5755af9 + cdcac00 commit b840163
Show file tree
Hide file tree
Showing 18 changed files with 1,290 additions and 24 deletions.
30 changes: 27 additions & 3 deletions Model/Entity/SalesforceIdStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,30 @@ public function __construct(
Objects $resourceObjects,
StoreManagerInterface $storeManager,
Config $config
)
{
) {
$this->resourceObjects = $resourceObjects;
$this->magentoType = $magentoType;
$this->mappingAttribute = $mappingAttribute;
$this->storeManager = $storeManager;
$this->config = $config;
}

/**
* @return string
*/
public function getMagentoType()
{
return $this->magentoType;
}

/**
* @param string $magentoType
*/
public function setMagentoType(string $magentoType)
{
$this->magentoType = $magentoType;
}

/**
* @return array
*/
Expand Down Expand Up @@ -214,7 +229,16 @@ public function saveStatus($entity, $status, $website = null)
*/
public function valueByAttribute($entity, $attributeName)
{
return $entity->getData($attributeName);
$method = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $attributeName)));
if (method_exists($entity, $method)) {
return $entity->{$method}();
} elseif (method_exists($entity, 'getData')) {
return $entity->getData($attributeName);
} else {
$dump = $entity->__toArray();
return $dump[$attributeName];
}
return null;
}

/**
Expand Down
15 changes: 4 additions & 11 deletions Synchronize/Queue/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public function __construct(
PreQueue $resourcePreQueue,
ManagerInterface $messageManager,
State $state
)
{
) {
$this->resolves = $resolves;
$this->entityType = $entityType;
$this->storeManager = $storeManager;
Expand All @@ -114,7 +113,7 @@ public function __construct(
*/
public function addToQueue(array $entityIds)
{
$entityIds = array_filter($entityIds);
// $entityIds = array_filter($entityIds);
if (empty($entityIds)) {
return;
}
Expand Down Expand Up @@ -226,9 +225,7 @@ public function generateQueueObjects(
&$dependencies,
&$queuesUnique = [],
$relatedUnitCode = null
)
{

) {
$queues = [];
$parents = $children = [];

Expand Down Expand Up @@ -264,7 +261,6 @@ public function generateQueueObjects(
}
}
} else {

$currentEntityIds = [];
$currentByEntityLoad = [];
foreach ([$current] as $relation) {
Expand Down Expand Up @@ -372,8 +368,7 @@ public function create(
array $loadAdditional,
$websiteId,
$syncType
)
{
) {
$dependencies = [];
/**
* collect all queue objects and build dependencies
Expand Down Expand Up @@ -446,9 +441,7 @@ public function buildGraph($queueDataToSave, $dependencies)
*/
public function saveQueue($queueDataToSave)
{

if (!empty($queueDataToSave)) {

$this
->resourceQueue
->getConnection()
Expand Down
16 changes: 16 additions & 0 deletions Synchronize/Transport/Calls/Delete/InputInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace TNW\Salesforce\Synchronize\Transport\Calls\Delete;

/**
* Unit interface
*/
interface InputInterface
{
/**
* Do Unit syncronization to Salesforce object
*
* @param Transport\Input $input
*/
public function process(Transport\Input $input);
}
16 changes: 16 additions & 0 deletions Synchronize/Transport/Calls/Delete/OutputInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace TNW\Salesforce\Synchronize\Transport\Calls\Delete;

/**
* Unit interface
*/
interface OutputInterface
{
/**
* Do Unit syncronization to Salesforce object
*
* @param Transport\Output $output
*/
public function process(Transport\Output $output);
}
118 changes: 118 additions & 0 deletions Synchronize/Transport/Calls/Delete/Transport/Input.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace TNW\Salesforce\Synchronize\Transport\Calls\Delete\Transport;

use SplObjectStorage;
use function spl_object_hash;

/**
* Upsert Transport Input
*/
class Input extends SplObjectStorage
{
/**
* @var string
*/
protected $externalIdFieldName = '';
/**
* @var string
*/
protected $type = '';
/**
* @var array
*/
private $info = [];

/**
* Data constructor.
*
* @param string $type
* @param string $externalIdFieldName
*/
public function __construct($type = '', $externalIdFieldName = 'Id')
{
$this->type = $type;
$this->externalIdFieldName = $externalIdFieldName;
}

/**
* External Id Field Name
*
* @return string
*/
public function externalIdFieldName()
{
return $this->externalIdFieldName;
}

/**
* Type
*
* @return string
*/
public function type()
{
return $this->type;
}

/**
* Offset Get
*
* @param object $object
* @return array
*/
public function &offsetGet($object)
{
if (!$this->contains($object)) {
$this->offsetSet($object, []);
}

return $this->info[parent::offsetGet($object)];
}

/**
* Offset Set
*
* @param object $object
* @param array $data
*/
public function offsetSet($object, $data = null)
{
$index = spl_object_hash($object);
parent::offsetSet($object, $index);
$this->info[$index] = $data;
}

/**
* Get Info
*
* @return array
*/
public function getInfo()
{
return $this->info[parent::getInfo()];
}

/**
* Set Info
*
* @param array $data
*/
public function setInfo($data)
{
$index = spl_object_hash($this->current());
parent::setInfo($index);
$this->info[$index] = $data;
}

/**
* Offset Unset
*
* @param object $object
*/
public function offsetUnset($object)
{
unset($this->info[parent::offsetGet($object)]);
parent::offsetUnset($object);
}
}
122 changes: 122 additions & 0 deletions Synchronize/Transport/Calls/Delete/Transport/Output.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

namespace TNW\Salesforce\Synchronize\Transport\Calls\Delete\Transport;

use SplObjectStorage;
use function spl_object_hash;

/**
* Upsert Transport Output
*/
class Output extends SplObjectStorage
{
/**
* @var string
*/
protected $type;
/**
* @var
*/
protected $unit;
/**
* @var array
*/
private $info = [];

/**
* Data constructor.
*
* @param string $type
*/
public function __construct($type = '')
{
$this->type = $type;
}

/**
* @return mixed
*/
public function getUnit()
{
return $this->unit;
}

/**
* @param mixed $unit
*/
public function setUnit($unit)
{
$this->unit = $unit;
}

/**
* Type
*
* @return string
*/
public function type()
{
return $this->type;
}

/**
* Offset Get
*
* @param object $object
* @return array
*/
public function &offsetGet($object)
{
if (!$this->contains($object)) {
$this->offsetSet($object, []);
}

return $this->info[parent::offsetGet($object)];
}

/**
* Offset Set
*
* @param object $object
* @param array $data
*/
public function offsetSet($object, $data = null)
{
$index = spl_object_hash($object);
parent::offsetSet($object, $index);
$this->info[$index] = $data;
}

/**
* Get Info
*
* @return array
*/
public function getInfo()
{
return $this->info[parent::getInfo()];
}

/**
* Set Info
*
* @param array $data
*/
public function setInfo($data)
{
$index = spl_object_hash($this->current());
parent::setInfo($index);
$this->info[$index] = $data;
}

/**
* Offset Unset
*
* @param object $object
*/
public function offsetUnset($object)
{
unset($this->info[parent::offsetGet($object)]);
parent::offsetUnset($object);
}
}
Loading

0 comments on commit b840163

Please sign in to comment.