Skip to content

Commit

Permalink
Merge pull request #690 from PowerSync/develop-2.4.4
Browse files Browse the repository at this point in the history
Develop 2.4.4
  • Loading branch information
yuriiperevuznyk authored Feb 14, 2023
2 parents 420420f + 23c6f95 commit dd2f2e3
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 76 deletions.
14 changes: 11 additions & 3 deletions Block/Adminhtml/Base/Edit/Renderer/SForceId.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
use Magento\Framework\Data\Form\Element\CollectionFactory;
use Magento\Framework\Data\Form\Element\Factory;
use Magento\Framework\Escaper;
use TNW\Salesforce\Service\Model\ResourceModel\Objects\MassLoadObjectIds;

abstract class SForceId extends \Magento\Framework\Data\Form\Element\Link
{
/**
* @var MassLoadObjectIds
*/
protected $massLoadObjectIds;

/** @var \TNW\Salesforce\Client\Salesforce */
private $client;

Expand All @@ -22,14 +28,14 @@ abstract class SForceId extends \Magento\Framework\Data\Form\Element\Link
protected $registry;

/**
* SForceId constructor.
* @param Factory $factoryElement
* @param CollectionFactory $factoryCollection
* @param Escaper $escaper
* @param array $data
* @param \TNW\Salesforce\Client\Salesforce $client
* @param \TNW\Salesforce\Model\ResourceModel\Objects $resourceObjects
* @param \Magento\Framework\Registry $registry
* @param MassLoadObjectIds $massLoadObjectIds
*/
public function __construct(
Factory $factoryElement,
Expand All @@ -38,12 +44,14 @@ public function __construct(
array $data,
\TNW\Salesforce\Client\Salesforce $client,
\TNW\Salesforce\Model\ResourceModel\Objects $resourceObjects,
\Magento\Framework\Registry $registry
\Magento\Framework\Registry $registry,
MassLoadObjectIds $massLoadObjectIds
) {
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
$this->client = $client;
$this->resourceObjects = $resourceObjects;
$this->registry = $registry;
$this->massLoadObjectIds = $massLoadObjectIds;
}

/**
Expand Down Expand Up @@ -104,7 +112,7 @@ protected function generateLinkToSalesforce($field)
$url = $this->client->getSalesForceUrl($websiteId);

$magentoId = $this->getEntityId();
$salesforceIds = $this->resourceObjects->loadObjectIds($magentoId, $this->getMagentoObjectType(), $websiteId);
$salesforceIds = $this->massLoadObjectIds->loadObjectIds($magentoId, $this->getMagentoObjectType(), $websiteId);

$salesforceObject = $this->getSalesforceObjectByAttribute();

Expand Down
10 changes: 9 additions & 1 deletion Block/Adminhtml/Customer/Edit/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
use Magento\Backend\Block\Widget\Form\Generic;
use TNW\Salesforce\Block\Adminhtml\Customer\Edit\Renderer\SForceId;
use TNW\Salesforce\Block\Adminhtml\Customer\Edit\Renderer\SyncStatus;
use TNW\Salesforce\Service\Model\ResourceModel\Objects\MassLoadObjectIds;

class Tabs extends Generic implements TabInterface
{
/**
* @var MassLoadObjectIds
*/
protected $massLoadObjectIds;

/**
* @var \Magento\Framework\Registry
*/
Expand All @@ -36,11 +42,13 @@ public function __construct(
\Magento\Framework\Data\FormFactory $formFactory,
CustomerRepositoryInterface $customerRepository,
\TNW\Salesforce\Model\ResourceModel\Objects $resourceObjects,
MassLoadObjectIds $massLoadObjectIds,
array $data = []
) {
$this->coreRegistry = $registry;
$this->customerRepository = $customerRepository;
$this->resourceObjects = $resourceObjects;
$this->massLoadObjectIds = $massLoadObjectIds;

parent::__construct($context, $registry, $formFactory, $data);
}
Expand Down Expand Up @@ -169,7 +177,7 @@ public function initForm()
'value' => $status,
]);

$salesforceIds = $this->resourceObjects->loadObjectIds(
$salesforceIds = $this->massLoadObjectIds->loadObjectIds(
$this->getCustomerId(),
\TNW\Salesforce\Model\Entity\SalesforceIdStorage::MAGENTO_TYPE_CUSTOMER,
$this->websiteId()
Expand Down
17 changes: 12 additions & 5 deletions Model/Entity/SalesforceIdStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Store\Model\StoreManagerInterface;
use TNW\Salesforce\Model\Config;
use TNW\Salesforce\Model\ResourceModel\Objects;
use TNW\Salesforce\Service\Model\ResourceModel\Objects\MassLoadObjectIds;

class SalesforceIdStorage
{
Expand All @@ -32,6 +33,11 @@ class SalesforceIdStorage
const MAGENTO_TYPE_ORDER_SHIPMENT_ITEM = 'Order Shipment Item';
const MAGENTO_TYPE_ORDER_SHIPMENT_TRACK = 'Order Shipment Track';

/**
* @var MassLoadObjectIds
*/
protected $massLoadObjectIds;

/**
* @var string
*/
Expand Down Expand Up @@ -63,26 +69,27 @@ class SalesforceIdStorage
private $cacheForUpdateStatus = [];

/**
* ObjectAbstract constructor.
*
* @param string $magentoType
* @param array $mappingAttribute
* @param Objects $resourceObjects
* @param StoreManagerInterface $storeManager
* @param Config $config
* @param MassLoadObjectIds $massLoadObjectIds
*/
public function __construct(
string $magentoType,
array $mappingAttribute,
Objects $resourceObjects,
StoreManagerInterface $storeManager,
Config $config
Config $config,
MassLoadObjectIds $massLoadObjectIds
) {
$this->resourceObjects = $resourceObjects;
$this->magentoType = $magentoType;
$this->mappingAttribute = $mappingAttribute;
$this->storeManager = $storeManager;
$this->config = $config;
$this->massLoadObjectIds = $massLoadObjectIds;
}

/**
Expand Down Expand Up @@ -390,7 +397,7 @@ public function loadObjectIds($entity, $website = null)
throw new Exception('magentoType was not defined!');
}

return $this->resourceObjects->loadObjectIds(
return $this->massLoadObjectIds->loadObjectIds(
$entity->getId(),
$this->magentoType,
$this->prepareWebsiteId($website)
Expand All @@ -416,7 +423,7 @@ public function massLoadObjectIds(array $entities, $website = null)
$entityId !== null && $entityIds[] = $entityId;
}

return $this->resourceObjects->massLoadObjectIds(
return $this->massLoadObjectIds->massLoadObjectIds(
$entityIds,
$this->magentoType,
$this->prepareWebsiteId($website)
Expand Down
43 changes: 5 additions & 38 deletions Model/ResourceModel/Objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Magento\Framework\Model\ResourceModel\Db\Context;
use Psr\Log\LoggerInterface;
use TNW\Salesforce\Model\Config;
use TNW\Salesforce\Service\Model\ResourceModel\Objects\MassLoadObjectIds;

class Objects extends AbstractDb
{
Expand Down Expand Up @@ -66,34 +65,26 @@ class Objects extends AbstractDb
*/
private $config;

/** @var MassLoadObjectIds */
private $massLoadObjectIds;

/** @var LoggerInterface */
private $logger;

/**
* Objects constructor.
*
* @param Context $context
* @param Config $config
* @param MassLoadObjectIds $massLoadObjectIds
* @param LoggerInterface $logger
* @param null $connectionName
* @param ?Manager $eventManager
* @param Context $context
* @param Config $config
* @param LoggerInterface $logger
* @param null $connectionName
* @param Manager|null $eventManager
*/
public function __construct(
Context $context,
Config $config,
MassLoadObjectIds $massLoadObjectIds,
LoggerInterface $logger,
$connectionName = null,
Manager $eventManager = null
) {
parent::__construct($context, $connectionName);
$this->eventManager = $eventManager ?? ObjectManager::getInstance()->get(Manager::class);
$this->config = $config;
$this->massLoadObjectIds = $massLoadObjectIds;
$this->logger = $logger;
}

Expand Down Expand Up @@ -216,30 +207,6 @@ public function loadPriceBookId(int $productId, int $websiteId, int $storeId = n
]);
}

/**
* @param int $entityId
* @param string $magentoType
* @param int $websiteId
*
* @return array
*/
public function loadObjectIds($entityId, $magentoType, $websiteId)
{
return $this->massLoadObjectIds->execute([$entityId], (string)$magentoType, (int)$websiteId)[$entityId] ?? [];
}

/**
* @param array $entityIds
* @param string $magentoType
* @param int $websiteId
*
* @return array
*/
public function massLoadObjectIds(array $entityIds, string $magentoType, int $websiteId): array
{
return $this->massLoadObjectIds->execute($entityIds, $magentoType, $websiteId);
}

/**
* @param int $entityId
* @param string $magentoType
Expand Down
12 changes: 10 additions & 2 deletions Plugin/Synchronize/Queue/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\StoreManagerInterface;
use TNW\Salesforce\Model\ResourceModel\Objects;
use TNW\Salesforce\Service\Model\ResourceModel\Objects\MassLoadObjectIds;
use TNW\Salesforce\Synchronize\Queue\Add as Subject;

class Add
{
/**
* @var MassLoadObjectIds
*/
protected $massLoadObjectIds;

/**
* @var Objects
*/
Expand All @@ -36,11 +42,13 @@ class Add
public function __construct(
Objects $resourceObjects,
StoreManagerInterface $storeManager,
RequestInterface $request
RequestInterface $request,
MassLoadObjectIds $massLoadObjectIds
) {
$this->resourceObjects = $resourceObjects;
$this->storeManager = $storeManager;
$this->request = $request;
$this->massLoadObjectIds = $massLoadObjectIds;
}

/**
Expand All @@ -56,7 +64,7 @@ public function beforeAddToQueue(Subject $subject, $entityIds)
$websiteId = $store->getWebsiteId();
$entityType = reset($subject->resolves)->entityType();

$objectIds = $this->resourceObjects->massLoadObjectIds($entityIds, (string)$entityType, (int)$websiteId);
$objectIds = $this->massLoadObjectIds->massLoadObjectIds($entityIds, (string)$entityType, (int)$websiteId);
$entityIdsForUpdateStatus = [];
foreach ($entityIds as $entityId) {
$data = $objectIds[$entityId] ?? [];
Expand Down
13 changes: 11 additions & 2 deletions Plugin/Synchronize/Unit/ProcessingAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\StoreManagerInterface;
use TNW\Salesforce\Model\ResourceModel\Objects;
use TNW\Salesforce\Service\Model\ResourceModel\Objects\MassLoadObjectIds;
use TNW\Salesforce\Synchronize\Unit\ProcessingAbstract as Subject;

class ProcessingAbstract
{
/**
* @var MassLoadObjectIds
*/
protected $massLoadObjectIds;

/**
* @var Objects
*/
Expand All @@ -32,15 +38,18 @@ class ProcessingAbstract
* @param Objects $resourceObjects
* @param StoreManagerInterface $storeManager
* @param RequestInterface $request
* @param MassLoadObjectIds $massLoadObjectIds
*/
public function __construct(
Objects $resourceObjects,
StoreManagerInterface $storeManager,
RequestInterface $request
RequestInterface $request,
MassLoadObjectIds $massLoadObjectIds
) {
$this->resourceObjects = $resourceObjects;
$this->storeManager = $storeManager;
$this->request = $request;
$this->massLoadObjectIds = $massLoadObjectIds;
}

/**
Expand Down Expand Up @@ -70,7 +79,7 @@ public function beforeProcess(Subject $subject)
}

foreach ($entityIdsByType as $entityType => $entityIds) {
$objectIds = $this->resourceObjects->massLoadObjectIds($entityIds, $entityType, $websiteId);
$objectIds = $this->massLoadObjectIds->massLoadObjectIds($entityIds, $entityType, $websiteId);
$entityIdsToUpdateStatus = [];
foreach ($entityIds as $entityId) {
$data = $objectIds[$entityId] ?? [];
Expand Down
25 changes: 25 additions & 0 deletions Service/Model/ResourceModel/Objects/MassLoadObjectIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,29 @@ public function clearLocalCache(): void
$this->cache = [];
$this->processed = [];
}


/**
* @param int $entityId
* @param string $magentoType
* @param int $websiteId
*
* @return array
*/
public function loadObjectIds($entityId, $magentoType, $websiteId)
{
return $this->execute([$entityId], (string)$magentoType, (int)$websiteId)[$entityId] ?? [];
}

/**
* @param array $entityIds
* @param string $magentoType
* @param int $websiteId
*
* @return array
*/
public function massLoadObjectIds(array $entityIds, string $magentoType, int $websiteId): array
{
return $this->execute($entityIds, $magentoType, $websiteId);
}
}
Loading

0 comments on commit dd2f2e3

Please sign in to comment.