diff --git a/.github/workflows/build-release-publish.yml b/.github/workflows/build-release-publish.yml index 9a6f3ff8..d9ce3be5 100755 --- a/.github/workflows/build-release-publish.yml +++ b/.github/workflows/build-release-publish.yml @@ -10,7 +10,7 @@ jobs: if: github.event.release.draft == false steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install composer dependencies run: composer install --no-dev -o @@ -21,7 +21,7 @@ jobs: VERSION: ${{ github.event.release.tag_name }} - name: Create & upload artifact - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 with: name: ${{ github.event.repository.name }} path: ./ @@ -32,7 +32,7 @@ jobs: needs: [build] steps: - name: Download artifact - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v3 with: name: ${{ github.event.repository.name }} @@ -45,7 +45,7 @@ jobs: CONFIG_FILE: ${{ secrets.PS_EVENTBUS_PRODUCTION_CONFIG }} - name: Publish the production zip - uses: actions/upload-release-asset@v1.0.1 + uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GA_ACCESS_TOKEN }} with: @@ -60,7 +60,7 @@ jobs: needs: [build] steps: - name: Download artifact - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v3 with: name: ${{ github.event.repository.name }} @@ -73,7 +73,7 @@ jobs: CONFIG_FILE: ${{ secrets.PS_EVENTBUS_INTEGRATION_CONFIG }} - name: Publish the integration zip - uses: actions/upload-release-asset@v1.0.1 + uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GA_ACCESS_TOKEN }} with: @@ -88,7 +88,7 @@ jobs: needs: [build] steps: - name: Download artifact - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v3 with: name: ${{ github.event.repository.name }} @@ -101,7 +101,7 @@ jobs: CONFIG_FILE: ${{ secrets.PS_EVENTBUS_PREPRODUCTION_CONFIG }} - name: Publish the preprod zip - uses: actions/upload-release-asset@v1.0.1 + uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GA_ACCESS_TOKEN }} with: @@ -117,7 +117,7 @@ jobs: if: "!github.event.release.prerelease" steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download release asset uses: dsaltares/fetch-gh-release-asset@master diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index 3c5e702a..1b964f6b 100755 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -17,7 +17,7 @@ jobs: php_version: ["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: PHP syntax checker ${{ matrix.php_version }} run: PHP_VERSION=${{ matrix.php_version }} make docker-php-lint @@ -39,7 +39,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: Cache vendor folder - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: vendor key: php-${{ hashFiles('composer.lock') }} @@ -57,7 +57,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: Cache vendor folder - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: vendor key: php-${{ hashFiles('composer.lock') }} @@ -72,7 +72,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: Cache vendor folder - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: vendor key: php-${{ hashFiles('composer.lock') }} @@ -88,19 +88,19 @@ jobs: # - name: Checkout # uses: actions/checkout@v3 # - name: Cache vendor folder - # uses: actions/cache@v1 + # uses: actions/cache@v3 # with: # path: vendor # key: php-${{ hashFiles('composer.lock') }} # - name: PHP unit with coverage # run: make phpunit-coverage # - name: 🎁 Publishing Allure artifact to GitHub Actions - # uses: actions/upload-artifact@v2 + # uses: actions/upload-artifact@v3 # with: # name: allure-reports # path: allure-reports # - name: 🎁 Publishing Code coverage report to GitHub Actions - # uses: actions/upload-artifact@v2 + # uses: actions/upload-artifact@v3 # with: # name: coverage-reports # path: coverage-reports diff --git a/.gitignore b/.gitignore index b93386c5..7776da92 100755 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,12 @@ coverage-reports allure-reports tests/.phpunit.result.cache .phpunit.cache/ + +# Jetbrains +.idea + +# Sonar +.scannerwork +sonar-project.properties + +*.cache diff --git a/Makefile b/Makefile index 95d63c82..55ae2b69 100755 --- a/Makefile +++ b/Makefile @@ -107,7 +107,7 @@ composer-validate: vendor @./composer.phar validate --no-check-publish # target: translation-validate - Validates the translation files in translations/ directory -translation-validate: +translation-validate: php tests/translation.test.php # target: lint - Lint the code and expose errors diff --git a/README.md b/README.md index 63e6dbd8..78332fe5 100755 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # PS EventBus -[![Quality Control](https://github.com/PrestaShopCorp/ps_eventbus/actions/workflows/eventbus-qc-php.yml/badge.svg)](https://github.com/PrestaShopCorp/ps_eventbus/actions/workflows/eventbus-qc-php.yml) +[![Quality Check](https://github.com/PrestaShopCorp/ps_eventbus/actions/workflows/quality-check.yml/badge.svg)](https://github.com/PrestaShopCorp/ps_eventbus/actions/workflows/quality-check.yml) `ps_eventbus` is a module companion for CloudSync. ## Compatibility matrix | PrestaShop platform | PS EventBus | -| ------------------- | -------------- | +|---------------------|----------------| | 8.0 | 2.x - PHP 7.1+ | | 1.7.0-1.7.8 | 2.x - PHP 7.1+ | | 1.6.1.x | No | @@ -23,7 +23,7 @@ make version # update the package configuration to the current version make zip # make a zip ready to be tested in PrestaShop (see ./dist) ``` -> Pro tip: prefix all you make commands with the variables you want to override. Ie: `VERSION=v1.2.3-rc4 make version` to set the package do the desired version. +> Pro-tip: prefix all you make commands with the variables you want to override. Ie: `VERSION=v1.2.3-rc4 make version` to set the package do the desired version. ## Testing diff --git a/config/front/api.yml b/config/front/api.yml index 1699e7b0..234c83d1 100755 --- a/config/front/api.yml +++ b/config/front/api.yml @@ -7,6 +7,14 @@ services: - "%ps_eventbus.sync_api_url%" - "@ps_eventbus" + PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient: + class: PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient + public: true + arguments: + - '@PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts' + - "%ps_eventbus.live_sync_api_url%" + - "@ps_eventbus" + PrestaShop\Module\PsEventbus\Api\CollectorApiClient: class: PrestaShop\Module\PsEventbus\Api\CollectorApiClient public: true diff --git a/config/front/repository.yml b/config/front/repository.yml index 02e21e2d..cfaf23ed 100755 --- a/config/front/repository.yml +++ b/config/front/repository.yml @@ -76,7 +76,7 @@ services: - '@PrestaShop\Module\PsEventbus\Repository\ShopRepository' - '@PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts' - '@PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandlerInterface' - - { EVENT_BUS_SYNC_API_URL: '%ps_eventbus.sync_api_url%', EVENT_BUS_PROXY_API_URL: '%ps_eventbus.proxy_api_url%' } + - { EVENT_BUS_SYNC_API_URL: '%ps_eventbus.sync_api_url%', EVENT_BUS_LIVE_SYNC_API_URL: '%ps_eventbus.live_sync_api_url%', EVENT_BUS_PROXY_API_URL: '%ps_eventbus.proxy_api_url%' } PrestaShop\Module\PsEventbus\Repository\ThemeRepository: class: PrestaShop\Module\PsEventbus\Repository\ThemeRepository diff --git a/config/index.php b/config/index.php index 1dd39a59..df296714 100755 --- a/config/index.php +++ b/config/index.php @@ -1,28 +1,28 @@ -* @copyright 2007-2020 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ +/* + * Copyright (c) 2007-2023 PrestaShop and Contributors + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License (AFL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * https://opensource.org/licenses/afl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please email + * license@prestashop.com, so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + * versions in the future. If you wish to customize PrestaShop for your + * needs please refer to http://www.prestashop.com for more information. + * + * @author PrestaShop SA + * @copyright 2007-2023 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); diff --git a/config/parameters.yml b/config/parameters.yml index b028318a..db5fd449 100755 --- a/config/parameters.yml +++ b/config/parameters.yml @@ -1,7 +1,8 @@ # Note: this file is here for documentation purpose -# It will be overrided by the Makefile +# It will be overridden by the Makefile parameters: ps_eventbus.proxy_api_url: "https://eventbus-proxy.psessentials.net" ps_eventbus.sync_api_url: "https://eventbus-sync.psessentials.net" + ps_eventbus.live_sync_api_url: "https://api.cloudsync.prestashop.com/live-sync/v1" ps_eventbus.sentry_dsn: "https://sentry-id@stuff.ingest.sentry.io/stuff" ps_eventbus.sentry_env: "development" diff --git a/dev-tools.Dockerfile b/dev-tools.Dockerfile index 5ba86df0..018971cd 100644 --- a/dev-tools.Dockerfile +++ b/dev-tools.Dockerfile @@ -1,7 +1,7 @@ ARG BUILDPLATFORM=linux/amd64 ARG PHP_VERSION=8.2 -FROM --platform=${BUILDPLATFORM} php:${PHP_VERSION}-alpine as dev-tools +FROM --platform=${BUILDPLATFORM} php:${PHP_VERSION}-alpine AS dev-tools WORKDIR /src @@ -13,7 +13,7 @@ RUN apk add -U make $PCRE_DEV && \ 7*) export XDEBUG_VERSION="3.1.6";; \ *) export XDEBUG_VERSION="3.2.0";; \ esac; \ - pecl channel-update pecl.php.net && \ + pecl channel-update pecl.php.net && \ pecl install xdebug-${XDEBUG_VERSION} && \ docker-php-ext-enable xdebug && \ apk del $PCRE_DEV; diff --git a/docker-compose.yml b/docker-compose.yml index 43029e20..23f57942 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: "3.7" +version: "3" services: php: @@ -9,7 +9,7 @@ services: environment: _PS_ROOT_DIR_: /var/www/html node: - image: node:10.16 + image: node:lts-alpine volumes: - ./:/var/www/html working_dir: /var/www/html @@ -24,7 +24,7 @@ services: environment: MYSQL_ROOT_PASSWORD: prestashop MYSQL_DATABASE: prestashop - restart: always + restart: unless-stopped healthcheck: test: "mysqladmin ping -h127.0.0.1 -uroot -pprestashop --silent" interval: 10s diff --git a/ps_eventbus.php b/ps_eventbus.php index 1bd65762..49204617 100755 --- a/ps_eventbus.php +++ b/ps_eventbus.php @@ -1,7 +1,7 @@ - * @copyright 2007-2020 PrestaShop SA - * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) - * International Registered Trademark & Property of PrestaShop SA + * @author PrestaShop SA + * @copyright 2007-2023 PrestaShop SA and Contributors + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of PrestaShop SA */ use PrestaShop\Module\PsEventbus\Config\Config; @@ -237,7 +237,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, @@ -257,7 +257,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, @@ -277,7 +277,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, @@ -297,7 +297,7 @@ public function hookActionObjectLanguageDeleteAfter($parameters) { $language = $parameters['object']; if (isset($language->id)) { - // $this->sendLiveSync(['languages'], $language->id, 'delete'); + $this->sendLiveSync(['languages'], $language->id, 'delete'); $this->insertDeletedObject( $language->id, Config::COLLECTION_LANGUAGES, @@ -315,8 +315,8 @@ public function hookActionObjectLanguageDeleteAfter($parameters) public function hookActionObjectLanguageAddAfter($parameters) { $language = $parameters['object']; - if (isset($language->id)) { - // $this->sendLiveSync(['languages'], $language->id_product, 'upsert'); + if (isset($language->id) && isset($language->id_product)) { + $this->sendLiveSync(['languages'], $language->id_product, 'upsert'); $this->insertIncrementalSyncObject( $language->id, Config::COLLECTION_LANGUAGES, @@ -335,8 +335,8 @@ public function hookActionObjectLanguageAddAfter($parameters) public function hookActionObjectLanguageUpdateAfter($parameters) { $language = $parameters['object']; - if (isset($language->id)) { - // $this->sendLiveSync(['languages'], $language->id_product, 'upsert'); + if (isset($language->id) && isset($language->id_product)) { + $this->sendLiveSync(['languages'], $language->id_product, 'upsert'); $this->insertIncrementalSyncObject( $language->id, Config::COLLECTION_LANGUAGES, @@ -356,7 +356,7 @@ public function hookActionObjectManufacturerDeleteAfter($parameters) { $manufacturer = $parameters['object']; if (isset($manufacturer->id)) { - // $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'delete'); + $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'delete'); $this->insertDeletedObject( $manufacturer->id, Config::COLLECTION_MANUFACTURERS, @@ -375,7 +375,7 @@ public function hookActionObjectManufacturerAddAfter($parameters) { $manufacturer = $parameters['object']; if (isset($manufacturer->id)) { - // $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'upsert'); + $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'upsert'); $this->insertIncrementalSyncObject( $manufacturer->id, Config::COLLECTION_MANUFACTURERS, @@ -395,7 +395,7 @@ public function hookActionObjectManufacturerUpdateAfter($parameters) { $manufacturer = $parameters['object']; if (isset($manufacturer->id)) { - // $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'upsert'); + $this->sendLiveSync(['manufacturers'], $manufacturer->id, 'upsert'); $this->insertIncrementalSyncObject( $manufacturer->id, Config::COLLECTION_MANUFACTURERS, @@ -415,7 +415,7 @@ public function hookActionObjectSupplierDeleteAfter($parameters) { $supplier = $parameters['object']; if (isset($supplier->id)) { - // $this->sendLiveSync(['suppliers'], $supplier->id, 'delete'); + $this->sendLiveSync(['suppliers'], $supplier->id, 'delete'); $this->insertDeletedObject( $supplier->id, Config::COLLECTION_SUPPLIERS, @@ -434,7 +434,7 @@ public function hookActionObjectSupplierAddAfter($parameters) { $supplier = $parameters['object']; if (isset($supplier->id)) { - // $this->sendLiveSync(['suppliers'], $supplier->id, 'upsert'); + $this->sendLiveSync(['suppliers'], $supplier->id, 'upsert'); $this->insertIncrementalSyncObject( $supplier->id, Config::COLLECTION_SUPPLIERS, @@ -454,7 +454,7 @@ public function hookActionObjectSupplierUpdateAfter($parameters) { $supplier = $parameters['object']; if (isset($supplier->id)) { - // $this->sendLiveSync(['suppliers'], $supplier->id, 'upsert'); + $this->sendLiveSync(['suppliers'], $supplier->id, 'upsert'); $this->insertIncrementalSyncObject( $supplier->id, Config::COLLECTION_SUPPLIERS, @@ -475,7 +475,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, @@ -494,7 +494,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, @@ -533,8 +533,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, Config::COLLECTION_PRODUCTS, @@ -542,7 +541,6 @@ public function hookActionObjectProductUpdateAfter($parameters) $this->shopId, true ); - $this->insertIncrementalSyncObject( $product->id, Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS, @@ -550,7 +548,6 @@ public function hookActionObjectProductUpdateAfter($parameters) $this->shopId, false ); - $this->insertIncrementalSyncObject( $product->id, Config::COLLECTION_STOCKS, @@ -570,8 +567,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, Config::COLLECTION_WISHLISTS, @@ -590,8 +586,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, Config::COLLECTION_WISHLISTS, @@ -611,8 +606,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, Config::COLLECTION_WISHLISTS, @@ -632,8 +626,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, Config::COLLECTION_STOCKS, @@ -653,8 +646,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, Config::COLLECTION_STOCKS, @@ -674,8 +666,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, Config::COLLECTION_STORES, @@ -694,8 +685,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, Config::COLLECTION_STORES, @@ -715,8 +705,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, Config::COLLECTION_STORES, @@ -738,8 +727,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, Config::COLLECTION_PRODUCT_ATTRIBUTES, @@ -759,8 +747,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, Config::COLLECTION_CATEGORIES, @@ -781,8 +768,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, Config::COLLECTION_CATEGORIES, @@ -803,8 +789,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, Config::COLLECTION_CATEGORIES, @@ -824,8 +809,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, Config::COLLECTION_CUSTOMERS, @@ -846,8 +830,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, Config::COLLECTION_CUSTOMERS, @@ -868,8 +851,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, Config::COLLECTION_CUSTOMERS, @@ -889,8 +871,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, Config::COLLECTION_CURRENCIES, @@ -911,8 +892,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, Config::COLLECTION_CURRENCIES, @@ -933,8 +913,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, Config::COLLECTION_CARTS, @@ -954,8 +933,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, Config::COLLECTION_CARTS, @@ -975,8 +953,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, Config::COLLECTION_ORDERS, @@ -996,8 +973,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, Config::COLLECTION_ORDERS, @@ -1018,8 +994,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, Config::COLLECTION_CARRIERS, @@ -1040,8 +1015,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, Config::COLLECTION_CARRIERS, @@ -1062,8 +1036,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, Config::COLLECTION_CARRIERS, @@ -1293,7 +1266,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, @@ -1316,7 +1289,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, @@ -1339,7 +1312,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, @@ -1350,25 +1323,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\LiveSyncApiClient $liveSyncApiClient */ + $liveSyncApiClient = $this->getService(\PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient::class); + $liveSyncApiClient->liveSync($shopContents, (int) $shopContentId, $action); + } catch (\Exception $e) { + } + } /** * @param int $objectId @@ -1437,7 +1410,7 @@ private function insertDeletedObject($objectId, $type, $date, $shopId) } /** - * Set PHP compatibilty to 7.1 + * Set PHP compatibility to 7.1 * * @return bool */ diff --git a/sql/index.php b/sql/index.php index 4b8dc071..5c9a7c77 100755 --- a/sql/index.php +++ b/sql/index.php @@ -1,20 +1,26 @@ - * @copyright 2007-2020 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * @copyright 2007-2023 PrestaShop SA and Contributors + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); diff --git a/src/Api/LiveSyncApiClient.php b/src/Api/LiveSyncApiClient.php new file mode 100644 index 00000000..6103471b --- /dev/null +++ b/src/Api/LiveSyncApiClient.php @@ -0,0 +1,96 @@ +module = $module; + $this->jwt = $psAccounts->getPsAccountsService()->getOrRefreshToken(); + $this->shopId = $psAccounts->getPsAccountsService()->getShopUuid(); + $this->liveSyncApiUrl = $liveSyncApiUrl; + } + + /** + * @see https://docs.guzzlephp.org/en/stable/quickstart.html- + * + * @param int $timeout + * + * @return HttpClientInterface + */ + private function getClient($timeout = Config::SYNC_API_MAX_TIMEOUT) + { + return (new ClientFactory())->getClient([ + 'allow_redirects' => true, + 'connect_timeout' => 3, + 'http_errors' => false, + 'timeout' => $timeout, + ]); + } + + /** + * @param array $shopContents + * @param int $shopContentId + * @param string $action + * + * @return array + */ + public function liveSync($shopContents, $shopContentId, $action) + { + $rawResponse = $this->getClient(3)->sendRequest( + new Request( + 'POST', + $this->liveSyncApiUrl . '/notify/' . $this->shopId, + [ + 'Accept' => 'application/json', + 'Authorization' => 'Bearer ' . $this->jwt, + 'User-Agent' => 'ps-eventbus/' . $this->module->version, + 'Content-Type' => 'application/json', + ], + '{"shopContents":' . json_encode($shopContents) . ', "shopContentId": ' . $shopContentId . ', "action": "' . $action . '"}' + ) + ); + + return [ + 'status' => substr((string) $rawResponse->getStatusCode(), 0, 1) === '2', + 'httpCode' => $rawResponse->getStatusCode(), + 'body' => $rawResponse->getBody(), + ]; + } +} diff --git a/src/Api/index.php b/src/Api/index.php index 4b8dc071..df296714 100755 --- a/src/Api/index.php +++ b/src/Api/index.php @@ -1,20 +1,26 @@ - * @copyright 2007-2020 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * @copyright 2007-2023 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); diff --git a/src/Repository/ServerInformationRepository.php b/src/Repository/ServerInformationRepository.php index 5a242914..084db360 100755 --- a/src/Repository/ServerInformationRepository.php +++ b/src/Repository/ServerInformationRepository.php @@ -188,6 +188,7 @@ public function getHealthCheckData() 'env' => [ 'EVENT_BUS_PROXY_API_URL' => isset($this->configuration['EVENT_BUS_PROXY_API_URL']) ? $this->configuration['EVENT_BUS_PROXY_API_URL'] : null, 'EVENT_BUS_SYNC_API_URL' => isset($this->configuration['EVENT_BUS_SYNC_API_URL']) ? $this->configuration['EVENT_BUS_SYNC_API_URL'] : null, + 'EVENT_BUS_LIVE_SYNC_API_URL' => isset($this->configuration['EVENT_BUS_LIVE_SYNC_API_URL']) ? $this->configuration['EVENT_BUS_LIVE_SYNC_API_URL'] : null, ], ]; } diff --git a/src/index.php b/src/index.php index 1dd39a59..5c9a7c77 100755 --- a/src/index.php +++ b/src/index.php @@ -1,28 +1,28 @@ -* @copyright 2007-2020 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ +/* + * Copyright (c) 2007-2023 PrestaShop and Contributors + * + * NOTICE OF LICENSE + * + * This source file is subject to the Academic Free License (AFL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/afl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please email + * license@prestashop.com, so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + * versions in the future. If you wish to customize PrestaShop for your + * needs please refer to http://www.prestashop.com for more information. + * + * @author PrestaShop SA + * @copyright 2007-2023 PrestaShop SA and Contributors + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');