Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable live sync #180

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 52 additions & 52 deletions ps_eventbus.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function hookActionObjectImageDeleteAfter($parameters)
{
$image = $parameters['object'];
if (isset($image->id_product)) {
$this->sendLiveSync(['products'], $image->id_product, 'delete');
// $this->sendLiveSync(['products'], $image->id_product, 'delete');
$this->insertIncrementalSyncObject(
$image->id_product,
Config::COLLECTION_PRODUCTS,
Expand All @@ -248,7 +248,7 @@ public function hookActionObjectImageAddAfter($parameters)
{
$image = $parameters['object'];
if (isset($image->id_product)) {
$this->sendLiveSync(['products'], $image->id_product, 'upsert');
// $this->sendLiveSync(['products'], $image->id_product, 'upsert');
$this->insertIncrementalSyncObject(
$image->id_product,
Config::COLLECTION_PRODUCTS,
Expand All @@ -268,7 +268,7 @@ public function hookActionObjectImageUpdateAfter($parameters)
{
$image = $parameters['object'];
if (isset($image->id_product)) {
$this->sendLiveSync(['products'], $image->id_product, 'upsert');
// $this->sendLiveSync(['products'], $image->id_product, 'upsert');
$this->insertIncrementalSyncObject(
$image->id_product,
Config::COLLECTION_PRODUCTS,
Expand All @@ -289,7 +289,7 @@ public function hookActionObjectProductDeleteAfter($parameters)
$product = $parameters['object'];

if (isset($product->id)) {
$this->sendLiveSync(['products'], $product->id, 'delete');
// $this->sendLiveSync(['products'], $product->id, 'delete');
$this->insertDeletedObject(
$product->id,
Config::COLLECTION_PRODUCTS,
Expand All @@ -308,7 +308,7 @@ public function hookActionObjectProductAddAfter($parameters)
{
$product = $parameters['object'];
if (isset($product->id)) {
$this->sendLiveSync(['products', 'custom-product-carriers', 'stocks'], $product->id, 'upsert');
// $this->sendLiveSync(['products', 'custom-product-carriers', 'stocks'], $product->id, 'upsert');

$this->insertIncrementalSyncObject(
$product->id,
Expand Down Expand Up @@ -347,7 +347,7 @@ public function hookActionObjectProductUpdateAfter($parameters)
$product = $parameters['object'];

if (isset($product->id)) {
$this->sendLiveSync(['products', 'custom-product-carriers', 'stocks'], $product->id, 'upsert');
// $this->sendLiveSync(['products', 'custom-product-carriers', 'stocks'], $product->id, 'upsert');

$this->insertIncrementalSyncObject(
$product->id,
Expand Down Expand Up @@ -384,7 +384,7 @@ public function hookActionObjectWishlistDeleteAfter($parameters)
{
$wishlist = $parameters['object'];
if (isset($wishlist->id)) {
$this->sendLiveSync(['wishlists'], $wishlist->id, 'delete');
// $this->sendLiveSync(['wishlists'], $wishlist->id, 'delete');

$this->insertDeletedObject(
$wishlist->id,
Expand All @@ -404,7 +404,7 @@ public function hookActionObjectWishlistAddAfter($parameters)
{
$wishlist = $parameters['object'];
if (isset($wishlist->id)) {
$this->sendLiveSync(['wishlists'], $wishlist->id, 'upsert');
// $this->sendLiveSync(['wishlists'], $wishlist->id, 'upsert');

$this->insertIncrementalSyncObject(
$wishlist->id,
Expand All @@ -425,7 +425,7 @@ public function hookActionObjectWishlistUpdateAfter($parameters)
{
$wishlist = $parameters['object'];
if (isset($wishlist->id)) {
$this->sendLiveSync(['wishlists'], $wishlist->id, 'upsert');
// $this->sendLiveSync(['wishlists'], $wishlist->id, 'upsert');

$this->insertIncrementalSyncObject(
$wishlist->id,
Expand All @@ -446,7 +446,7 @@ public function hookActionObjectStockAddAfter($parameters)
{
$stock = $parameters['object'];
if (isset($stock->id)) {
$this->sendLiveSync(['stocks'], $stock->id, 'upsert');
// $this->sendLiveSync(['stocks'], $stock->id, 'upsert');

$this->insertIncrementalSyncObject(
$stock->id,
Expand All @@ -467,7 +467,7 @@ public function hookActionObjectStockUpdateAfter($parameters)
{
$stock = $parameters['object'];
if (isset($stock->id)) {
$this->sendLiveSync(['stocks'], $stock->id, 'upsert');
// $this->sendLiveSync(['stocks'], $stock->id, 'upsert');

$this->insertIncrementalSyncObject(
$stock->id,
Expand All @@ -488,7 +488,7 @@ public function hookActionObjectStoreDeleteAfter($parameters)
{
$product = $parameters['object'];
if (isset($product->id)) {
$this->sendLiveSync(['stores'], $product->id, 'delete');
// $this->sendLiveSync(['stores'], $product->id, 'delete');

$this->insertDeletedObject(
$product->id,
Expand All @@ -508,7 +508,7 @@ public function hookActionObjectStoreAddAfter($parameters)
{
$product = $parameters['object'];
if (isset($product->id)) {
$this->sendLiveSync(['stores'], $product->id, 'upsert');
// $this->sendLiveSync(['stores'], $product->id, 'upsert');

$this->insertIncrementalSyncObject(
$product->id,
Expand All @@ -529,7 +529,7 @@ public function hookActionObjectStoreUpdateAfter($parameters)
{
$store = $parameters['object'];
if (isset($store->id)) {
$this->sendLiveSync(['stores'], $store->id, 'upsert');
// $this->sendLiveSync(['stores'], $store->id, 'upsert');

$this->insertIncrementalSyncObject(
$store->id,
Expand All @@ -552,7 +552,7 @@ public function hookActionObjectCombinationDeleteAfter($parameters)
$combination = $parameters['object'];

if (isset($combination->id)) {
$this->sendLiveSync(['products'], $combination->id, 'delete');
// $this->sendLiveSync(['products'], $combination->id, 'delete');

$this->insertDeletedObject(
$combination->id,
Expand All @@ -573,7 +573,7 @@ public function hookActionObjectCategoryAddAfter($parameters)
$category = $parameters['object'];

if (isset($category->id)) {
$this->sendLiveSync(['categories'], $category->id, 'upsert');
// $this->sendLiveSync(['categories'], $category->id, 'upsert');

$this->insertIncrementalSyncObject(
$category->id,
Expand All @@ -595,7 +595,7 @@ public function hookActionObjectCategoryUpdateAfter($parameters)
$category = $parameters['object'];

if (isset($category->id)) {
$this->sendLiveSync(['categories'], $category->id, 'upsert');
// $this->sendLiveSync(['categories'], $category->id, 'upsert');

$this->insertIncrementalSyncObject(
$category->id,
Expand All @@ -617,7 +617,7 @@ public function hookActionObjectCategoryDeleteAfter($parameters)
$category = $parameters['object'];

if (isset($category->id)) {
$this->sendLiveSync(['categories'], $category->id, 'delete');
// $this->sendLiveSync(['categories'], $category->id, 'delete');

$this->insertDeletedObject(
$category->id,
Expand All @@ -638,7 +638,7 @@ public function hookActionObjectCustomerAddAfter($parameters)
$customer = $parameters['object'];

if (isset($customer->id)) {
$this->sendLiveSync(['customers'], $customer->id, 'upsert');
// $this->sendLiveSync(['customers'], $customer->id, 'upsert');

$this->insertIncrementalSyncObject(
$customer->id,
Expand All @@ -660,7 +660,7 @@ public function hookActionObjectCustomerUpdateAfter($parameters)
$customer = $parameters['object'];

if (isset($customer->id)) {
$this->sendLiveSync(['customers'], $customer->id, 'upsert');
// $this->sendLiveSync(['customers'], $customer->id, 'upsert');

$this->insertIncrementalSyncObject(
$customer->id,
Expand All @@ -682,7 +682,7 @@ public function hookActionObjectCustomerDeleteAfter($parameters)
$customer = $parameters['object'];

if (isset($customer->id)) {
$this->sendLiveSync(['customers'], $customer->id, 'delete');
// $this->sendLiveSync(['customers'], $customer->id, 'delete');

$this->insertDeletedObject(
$customer->id,
Expand All @@ -703,7 +703,7 @@ public function hookActionObjectCurrencyAddAfter($parameters)
$currency = $parameters['object'];

if (isset($currency->id)) {
$this->sendLiveSync(['currencies'], $currency->id, 'upsert');
// $this->sendLiveSync(['currencies'], $currency->id, 'upsert');

$this->insertIncrementalSyncObject(
$currency->id,
Expand All @@ -725,7 +725,7 @@ public function hookActionObjectCurrencyUpdateAfter($parameters)
$currency = $parameters['object'];

if (isset($currency->id)) {
$this->sendLiveSync(['currencies'], $currency->id, 'upsert');
// $this->sendLiveSync(['currencies'], $currency->id, 'upsert');

$this->insertIncrementalSyncObject(
$currency->id,
Expand All @@ -747,7 +747,7 @@ public function hookActionObjectCartAddAfter($parameters)
$cart = $parameters['object'];

if (isset($cart->id)) {
$this->sendLiveSync(['carts'], $cart->id, 'upsert');
// $this->sendLiveSync(['carts'], $cart->id, 'upsert');

$this->insertIncrementalSyncObject(
$cart->id,
Expand All @@ -768,7 +768,7 @@ public function hookActionObjectCartUpdateAfter($parameters)
$cart = $parameters['object'];

if (isset($cart->id)) {
$this->sendLiveSync(['carts'], $cart->id, 'upsert');
// $this->sendLiveSync(['carts'], $cart->id, 'upsert');

$this->insertIncrementalSyncObject(
$cart->id,
Expand All @@ -789,7 +789,7 @@ public function hookActionObjectOrderAddAfter($parameters)
$order = $parameters['object'];

if (isset($order->id)) {
$this->sendLiveSync(['orders'], $order->id, 'upsert');
// $this->sendLiveSync(['orders'], $order->id, 'upsert');

$this->insertIncrementalSyncObject(
$order->id,
Expand All @@ -810,7 +810,7 @@ public function hookActionObjectOrderUpdateAfter($parameters)
$order = $parameters['object'];

if (isset($order->id)) {
$this->sendLiveSync(['orders'], $order->id, 'upsert');
// $this->sendLiveSync(['orders'], $order->id, 'upsert');

$this->insertIncrementalSyncObject(
$order->id,
Expand All @@ -832,7 +832,7 @@ public function hookActionObjectCarrierAddAfter($parameters)
$carrier = $parameters['object'];

if (isset($carrier->id)) {
$this->sendLiveSync(['carriers'], $carrier->id, 'upsert');
// $this->sendLiveSync(['carriers'], $carrier->id, 'upsert');

$this->insertIncrementalSyncObject(
$carrier->id,
Expand All @@ -854,7 +854,7 @@ public function hookActionObjectCarrierUpdateAfter($parameters)
$carrier = $parameters['object'];

if (isset($carrier->id)) {
$this->sendLiveSync(['carriers'], $carrier->id, 'upsert');
// $this->sendLiveSync(['carriers'], $carrier->id, 'upsert');

$this->insertIncrementalSyncObject(
$carrier->id,
Expand All @@ -876,7 +876,7 @@ public function hookActionObjectCarrierDeleteAfter($parameters)
$carrier = $parameters['object'];

if (isset($carrier->id)) {
$this->sendLiveSync(['carriers'], $carrier->id, 'delete');
// $this->sendLiveSync(['carriers'], $carrier->id, 'delete');

$this->insertIncrementalSyncObject(
$carrier->id,
Expand Down Expand Up @@ -1107,7 +1107,7 @@ public function hookActionObjectSpecificPriceAddAfter($parameters)

if ($specificPrice instanceof SpecificPrice) {
if (isset($specificPrice->id)) {
$this->sendLiveSync(['specific-prices'], $specificPrice->id, 'upsert');
// $this->sendLiveSync(['specific-prices'], $specificPrice->id, 'upsert');
$this->insertIncrementalSyncObject(
$specificPrice->id,
Config::COLLECTION_SPECIFIC_PRICES,
Expand All @@ -1130,7 +1130,7 @@ public function hookActionObjectSpecificPriceUpdateAfter($parameters)

if ($specificPrice instanceof SpecificPrice) {
if (isset($specificPrice->id)) {
$this->sendLiveSync(['specific-prices'], $specificPrice->id, 'upsert');
// $this->sendLiveSync(['specific-prices'], $specificPrice->id, 'upsert');
$this->insertIncrementalSyncObject(
$specificPrice->id,
Config::COLLECTION_SPECIFIC_PRICES,
Expand All @@ -1153,7 +1153,7 @@ public function hookActionObjectSpecificPriceDeleteAfter($parameters)

if ($specificPrice instanceof SpecificPrice) {
if (isset($specificPrice->id)) {
$this->sendLiveSync(['specific-prices'], $specificPrice->id, 'delete');
// $this->sendLiveSync(['specific-prices'], $specificPrice->id, 'delete');
$this->insertDeletedObject(
$specificPrice->id,
Config::COLLECTION_SPECIFIC_PRICES,
Expand All @@ -1164,25 +1164,25 @@ public function hookActionObjectSpecificPriceDeleteAfter($parameters)
}
}

/**
* @param array $shopContents
* @param int $shopContentId
* @param string $action
*
* @return void
*/
private function sendLiveSync($shopContents, $shopContentId, $action)
{
if ((int) $shopContentId === 0) {
return;
}
try {
/** @var \PrestaShop\Module\PsEventbus\Api\SyncApiClient $syncApiClient */
$syncApiClient = $this->getService(\PrestaShop\Module\PsEventbus\Api\SyncApiClient::class);
$res = $syncApiClient->liveSync($shopContents, (int) $shopContentId, $action);
} catch (\Exception $e) {
}
}
// /**
// * @param array $shopContents
// * @param int $shopContentId
// * @param string $action
// *
// * @return void
// */
// private function sendLiveSync($shopContents, $shopContentId, $action)
// {
// if ((int) $shopContentId === 0) {
// return;
// }
// try {
// /** @var \PrestaShop\Module\PsEventbus\Api\SyncApiClient $syncApiClient */
// $syncApiClient = $this->getService(\PrestaShop\Module\PsEventbus\Api\SyncApiClient::class);
// $res = $syncApiClient->liveSync($shopContents, (int) $shopContentId, $action);
// } catch (\Exception $e) {
// }
// }

/**
* @param int $objectId
Expand Down
Loading