From 45a42adf22570c84b2ff019f740c58089d5a5e97 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 20 Sep 2024 17:17:17 +0200 Subject: [PATCH 1/2] feat: add images and image_types --- config/common/new-repository.yml | 8 + config/common/repository.yml | 8 - config/front/services.yml | 12 ++ e2e/src/full-sync.spec.ts | 4 +- e2e/src/helpers/data-helper.ts | 2 +- e2e/src/helpers/mock-probe.ts | 2 +- e2e/src/helpers/shop-contents.ts | 2 + e2e/src/job-id-validation.spec.ts | 2 +- src/Repository/ImageRepository.php | 177 ------------------ src/Repository/ImageTypeRepository.php | 122 ------------ .../NewRepository/CategoryRepository.php | 2 +- .../NewRepository/EmployeeRepository.php | 2 +- .../NewRepository/ImageRepository.php | 101 ++++++++++ .../NewRepository/ImageTypeRepository.php | 99 ++++++++++ .../NewRepository/ProductBundleRepository.php | 2 +- src/Service/ShopContent/ImageTypesService.php | 103 ++++++++++ src/Service/ShopContent/ImagesService.php | 101 ++++++++++ 17 files changed, 434 insertions(+), 315 deletions(-) delete mode 100644 src/Repository/ImageRepository.php delete mode 100644 src/Repository/ImageTypeRepository.php create mode 100644 src/Repository/NewRepository/ImageRepository.php create mode 100644 src/Repository/NewRepository/ImageTypeRepository.php create mode 100644 src/Service/ShopContent/ImageTypesService.php create mode 100644 src/Service/ShopContent/ImagesService.php diff --git a/config/common/new-repository.yml b/config/common/new-repository.yml index e809572f..a20793be 100644 --- a/config/common/new-repository.yml +++ b/config/common/new-repository.yml @@ -62,3 +62,11 @@ services: PrestaShop\Module\PsEventbus\Repository\NewRepository\EmployeeRepository: class: PrestaShop\Module\PsEventbus\Repository\NewRepository\EmployeeRepository public: true + + PrestaShop\Module\PsEventbus\Repository\NewRepository\ImageRepository: + class: PrestaShop\Module\PsEventbus\Repository\NewRepository\ImageRepository + public: true + + PrestaShop\Module\PsEventbus\Repository\NewRepository\ImageTypeRepository: + class: PrestaShop\Module\PsEventbus\Repository\NewRepository\ImageTypeRepository + public: true diff --git a/config/common/repository.yml b/config/common/repository.yml index 3f3a6195..f599a512 100644 --- a/config/common/repository.yml +++ b/config/common/repository.yml @@ -119,14 +119,6 @@ services: arguments: - '@=service("prestashop.adapter.legacy.context").getContext()' - PrestaShop\Module\PsEventbus\Repository\ImageRepository: - class: PrestaShop\Module\PsEventbus\Repository\ImageRepository - public: true - - PrestaShop\Module\PsEventbus\Repository\ImageTypeRepository: - class: PrestaShop\Module\PsEventbus\Repository\ImageTypeRepository - public: true - PrestaShop\Module\PsEventbus\Repository\TranslationRepository: class: PrestaShop\Module\PsEventbus\Repository\TranslationRepository public: true diff --git a/config/front/services.yml b/config/front/services.yml index 3a187e09..4ee036ff 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -165,3 +165,15 @@ services: public: true arguments: - '@PrestaShop\Module\PsEventbus\Repository\NewRepository\EmployeeRepository' + + PrestaShop\Module\PsEventbus\Service\ShopContent\ImagesService: + class: PrestaShop\Module\PsEventbus\Service\ShopContent\ImagesService + public: true + arguments: + - '@PrestaShop\Module\PsEventbus\Repository\NewRepository\ImageRepository' + + PrestaShop\Module\PsEventbus\Service\ShopContent\ImageTypesService: + class: PrestaShop\Module\PsEventbus\Service\ShopContent\ImageTypesService + public: true + arguments: + - '@PrestaShop\Module\PsEventbus\Repository\NewRepository\ImageTypeRepository' diff --git a/e2e/src/full-sync.spec.ts b/e2e/src/full-sync.spec.ts index 1d127378..655718db 100644 --- a/e2e/src/full-sync.spec.ts +++ b/e2e/src/full-sync.spec.ts @@ -65,7 +65,7 @@ describe("Full Sync", () => { it(`${shoContent} should reject full sync when ps_facebook is not installed`, async () => { // arrange - const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shoContent}&limit=5&full=1&job_id=${jobId}`; + const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=0&shop_content=${shoContent}&limit=5&full=1&job_id=${jobId}`; const callId = { call_id: Math.random().toString(36).substring(2, 11) }; @@ -92,7 +92,7 @@ describe("Full Sync", () => { describe.each(shopContents)("%s", (shopContent) => { it(`${shopContent} should accept full sync`, async () => { // arrange - const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5&full=1&job_id=${jobId}`; + const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=0&shop_content=${shopContent}&limit=5&full=1&job_id=${jobId}`; const callId = { call_id: Math.random().toString(36).substring(2, 11) }; diff --git a/e2e/src/helpers/data-helper.ts b/e2e/src/helpers/data-helper.ts index bd072533..9cf915b5 100644 --- a/e2e/src/helpers/data-helper.ts +++ b/e2e/src/helpers/data-helper.ts @@ -59,7 +59,7 @@ export async function getShopHealthCheck(options?: { healthCheck = cachedHealthCheck; } else { const res = await axios.get( - `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=healthcheck&job_id=valid-job-healthcheck`, + `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=0&shop_content=healthcheck&job_id=valid-job-healthcheck`, ); healthCheck = res.data; cachedHealthCheck = healthCheck; diff --git a/e2e/src/helpers/mock-probe.ts b/e2e/src/helpers/mock-probe.ts index 77c5c825..75e66dd6 100644 --- a/e2e/src/helpers/mock-probe.ts +++ b/e2e/src/helpers/mock-probe.ts @@ -96,7 +96,7 @@ export function doFullSync( const requestNext = (full: number) => { return axios.post( - `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5&full=${full}&job_id=${jobId}`, + `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=0&shop_content=${shopContent}&limit=5&full=${full}&job_id=${jobId}`, callId, { headers: { diff --git a/e2e/src/helpers/shop-contents.ts b/e2e/src/helpers/shop-contents.ts index 5c2afc84..f6e0b6cc 100644 --- a/e2e/src/helpers/shop-contents.ts +++ b/e2e/src/helpers/shop-contents.ts @@ -52,6 +52,8 @@ export const shopContentMapping = { customers: "customers", currencies: "currencies", employees: "employees", + images: "images", + image_types: "image-types", } as const; type ShopContentMapping = typeof shopContentMapping; diff --git a/e2e/src/job-id-validation.spec.ts b/e2e/src/job-id-validation.spec.ts index 1ff5d819..50bea911 100644 --- a/e2e/src/job-id-validation.spec.ts +++ b/e2e/src/job-id-validation.spec.ts @@ -22,7 +22,7 @@ describe("Reject invalid job-id", () => { async (shopContent) => { expect.assertions(6); // arrange - const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=1&shop_content=${shopContent}&limit=5&job_id=${jobId}`; + const url = `${testConfig.prestashopUrl}/index.php?fc=module&module=ps_eventbus&controller=apiFront&is_e2e=0&shop_content=${shopContent}&limit=5&job_id=${jobId}`; const message$ = probe({ params: { id: jobId } }); //act diff --git a/src/Repository/ImageRepository.php b/src/Repository/ImageRepository.php deleted file mode 100644 index f93f8a3a..00000000 --- a/src/Repository/ImageRepository.php +++ /dev/null @@ -1,177 +0,0 @@ -db = \Db::getInstance(); - } - - /** - * @return \DbQuery - */ - private function getBaseQuery() - { - $query = new \DbQuery(); - - $query->from('image', 'i') - ->leftJoin('image_lang', 'il', 'il.id_image = i.id_image') - ->leftJoin('image_shop', 'is', 'is.id_image = i.id_image'); - - return $query; - } - - /** - * @param int $offset - * @param int $limit - * - * @return array|bool|\mysqli_result|\PDOStatement|resource|null - * - * @throws \PrestaShopDatabaseException - */ - public function getImages($offset, $limit) - { - $query = $this->getBaseQuery(); - - $this->addSelectParameters($query); - - $query->limit($limit, $offset); - - return $this->db->executeS($query); - } - - /** - * @param int $offset - * - * @return int - */ - public function getRemainingImagesCount($offset) - { - $query = $this->getBaseQuery() - ->select('(COUNT(i.id_image) - ' . (int) $offset . ') as count'); - - return (int) $this->db->getValue($query); - } - - /** - * @param int $limit - * @param array $imageIds - * - * @return array|bool|\mysqli_result|\PDOStatement|resource|null - * - * @throws \PrestaShopDatabaseException - */ - public function getImagesIncremental($limit, $imageIds) - { - $query = $this->getBaseQuery(); - - $this->addSelectParameters($query); - - $query->where('i.id_image IN(' . implode(',', array_map('intval', $imageIds)) . ')') - ->limit($limit); - - return $this->db->executeS($query); - } - - /** - * @param int $productId - * @param int $shopId - * - * @return false|string|null - */ - public function getProductCoverImage($productId, $shopId) - { - $query = new \DbQuery(); - - $query->select('imgs.id_image') - ->from('image_shop', 'imgs') - ->where('imgs.cover = 1') - ->where('imgs.id_shop = ' . (int) $shopId) - ->where('imgs.id_product = ' . (int) $productId); - - return $this->db->getValue($query); - } - - /** - * @param int $productId - * @param int $attributeId - * @param int $shopId - * @param bool $includeCover - * - * @return array|bool|\mysqli_result|\PDOStatement|resource|null - * - * @throws \PrestaShopDatabaseException - */ - public function getProductImages($productId, $attributeId, $shopId, $includeCover = null) - { - $query = new \DbQuery(); - - $query->select('imgs.id_image') - ->from('image_shop', 'imgs') - ->leftJoin('image', 'img', 'imgs.id_image = img.id_image') - ->where('imgs.id_shop = ' . (int) $shopId) - ->where('imgs.id_product = ' . (int) $productId) - ->orderBy('img.position ASC'); - - if ((int) $attributeId !== 0) { - $query->innerJoin( - 'product_attribute_image', - 'pai', - 'imgs.id_image = pai.id_image AND pai.id_product_attribute = ' . (int) $attributeId - ); - } - - if (!$includeCover) { - $query->where('(imgs.cover IS NULL OR imgs.cover = 0)'); - } - - return $this->db->executeS($query); - } - - /** - * @param int $offset - * @param int $limit - * - * @return array - * - * @throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit) - { - $query = $this->getBaseQuery(); - - $this->addSelectParameters($query); - - $query->limit($limit, $offset); - - $queryStringified = preg_replace('/\s+/', ' ', $query->build()); - - return array_merge( - (array) $query, - ['queryStringified' => $queryStringified] - ); - } - - /** - * @param \DbQuery $query - * - * @return void - */ - private function addSelectParameters(\DbQuery $query) - { - $query->select('i.id_image'); - $query->select('i.id_product'); - $query->select('i.position'); - $query->select('i.cover'); - $query->select('il.id_lang'); - $query->select('il.legend'); - $query->select('is.id_shop'); - } -} diff --git a/src/Repository/ImageTypeRepository.php b/src/Repository/ImageTypeRepository.php deleted file mode 100644 index 745a6314..00000000 --- a/src/Repository/ImageTypeRepository.php +++ /dev/null @@ -1,122 +0,0 @@ -db = \Db::getInstance(); - } - - /** - * @return \DbQuery - */ - private function getBaseQuery() - { - $query = new \DbQuery(); - - $query->from('image_type', 'it'); - - return $query; - } - - /** - * @param int $offset - * @param int $limit - * - * @return array|bool|\mysqli_result|\PDOStatement|resource|null - * - * @throws \PrestaShopDatabaseException - */ - public function getImageTypes($offset, $limit) - { - $query = $this->getBaseQuery(); - - $this->addSelectParameters($query); - - $query->limit($limit, $offset); - - return $this->db->executeS($query); - } - - /** - * @param int $offset - * - * @return int - */ - public function getRemainingImageTypesCount($offset) - { - $query = $this->getBaseQuery() - ->select('(COUNT(it.id_image_type) - ' . (int) $offset . ') as count'); - - return (int) $this->db->getValue($query); - } - - /** - * @param int $limit - * @param array $imageTypeIds - * - * @return array|bool|\mysqli_result|\PDOStatement|resource|null - * - * @throws \PrestaShopDatabaseException - */ - public function getImageTypesIncremental($limit, $imageTypeIds) - { - $query = $this->getBaseQuery(); - - $this->addSelectParameters($query); - - $query->where('it.id_image_type IN(' . implode(',', array_map('intval', $imageTypeIds)) . ')') - ->limit($limit); - - return $this->db->executeS($query); - } - - /** - * @param int $offset - * @param int $limit - * - * @return array - * - * @throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit) - { - $query = $this->getBaseQuery(); - - $this->addSelectParameters($query); - - $query->limit($limit, $offset); - - $queryStringified = preg_replace('/\s+/', ' ', $query->build()); - - return array_merge( - (array) $query, - ['queryStringified' => $queryStringified] - ); - } - - /** - * @param \DbQuery $query - * - * @return void - */ - private function addSelectParameters(\DbQuery $query) - { - $query->select('it.id_image_type'); - $query->select('it.name'); - $query->select('it.width'); - $query->select('it.height'); - $query->select('it.products'); - $query->select('it.categories'); - $query->select('it.manufacturers'); - $query->select('it.suppliers'); - $query->select('it.stores'); - } -} diff --git a/src/Repository/NewRepository/CategoryRepository.php b/src/Repository/NewRepository/CategoryRepository.php index 45b6f241..7cfe2d16 100644 --- a/src/Repository/NewRepository/CategoryRepository.php +++ b/src/Repository/NewRepository/CategoryRepository.php @@ -81,7 +81,7 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso, $d $this->generateFullQuery($langIso, true); $this->query - ->where('p.id_category IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->where('cs.id_category IN(' . implode(',', array_map('intval', $contentIds)) . ')') ->limit($limit) ; diff --git a/src/Repository/NewRepository/EmployeeRepository.php b/src/Repository/NewRepository/EmployeeRepository.php index e6dfc4de..1bb9616d 100644 --- a/src/Repository/NewRepository/EmployeeRepository.php +++ b/src/Repository/NewRepository/EmployeeRepository.php @@ -87,7 +87,7 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso, $d $this->generateFullQuery($langIso, true); $this->query - ->where('c.id_employee IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->where('e.id_employee IN(' . implode(',', array_map('intval', $contentIds)) . ')') ->limit($limit) ; diff --git a/src/Repository/NewRepository/ImageRepository.php b/src/Repository/NewRepository/ImageRepository.php new file mode 100644 index 00000000..863688ef --- /dev/null +++ b/src/Repository/NewRepository/ImageRepository.php @@ -0,0 +1,101 @@ +generateMinimalQuery(self::TABLE_NAME, 'i'); + + $this->query + ->leftJoin('image_lang', 'il', 'il.id_image = i.id_image') + ->leftJoin('image_shop', 'is', 'is.id_image = i.id_image'); + + if ($withSelecParameters) { + $this->query + ->select('i.id_image') + ->select('i.id_product') + ->select('i.position') + ->select('i.cover') + ->select('il.id_lang') + ->select('il.legend') + ->select('is.id_shop') + ; + } + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * @param bool $debug + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function retrieveContentsForFull($offset, $limit, $langIso, $debug) + { + $this->generateFullQuery($langIso, true); + + $this->query->limit((int) $limit, (int) $offset); + + return $this->runQuery($debug); + } + + /** + * @param int $limit + * @param array $contentIds + * @param string $langIso + * @param bool $debug + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function retrieveContentsForIncremental($limit, $contentIds, $langIso, $debug) + { + $this->generateFullQuery($langIso, true); + + $this->query + ->where('i.id_image IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->limit($limit) + ; + + return $this->runQuery($debug); + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return int + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function countFullSyncContentLeft($offset, $limit, $langIso) + { + $this->generateFullQuery($langIso, false); + + $this->query->select('(COUNT(*) - ' . (int) $offset . ') as count'); + + $result = $this->runQuery(false); + + return $result[0]['count']; + } +} diff --git a/src/Repository/NewRepository/ImageTypeRepository.php b/src/Repository/NewRepository/ImageTypeRepository.php new file mode 100644 index 00000000..1ebfc258 --- /dev/null +++ b/src/Repository/NewRepository/ImageTypeRepository.php @@ -0,0 +1,99 @@ +generateMinimalQuery(self::TABLE_NAME, 'it'); + + if ($withSelecParameters) { + $this->query + ->select('it.id_image_type') + ->select('it.name') + ->select('it.width') + ->select('it.height') + ->select('it.products') + ->select('it.categories') + ->select('it.manufacturers') + ->select('it.suppliers') + ->select('it.stores') + ; + } + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * @param bool $debug + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function retrieveContentsForFull($offset, $limit, $langIso, $debug) + { + $this->generateFullQuery($langIso, true); + + $this->query->limit((int) $limit, (int) $offset); + + return $this->runQuery($debug); + } + + /** + * @param int $limit + * @param array $contentIds + * @param string $langIso + * @param bool $debug + * + * @return array + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function retrieveContentsForIncremental($limit, $contentIds, $langIso, $debug) + { + $this->generateFullQuery($langIso, true); + + $this->query + ->where('it.id_image_type IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->limit($limit) + ; + + return $this->runQuery($debug); + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return int + * + * @throws \PrestaShopException + * @throws \PrestaShopDatabaseException + */ + public function countFullSyncContentLeft($offset, $limit, $langIso) + { + $this->generateFullQuery($langIso, false); + + $this->query->select('(COUNT(*) - ' . (int) $offset . ') as count'); + + $result = $this->runQuery(false); + + return $result[0]['count']; + } +} diff --git a/src/Repository/NewRepository/ProductBundleRepository.php b/src/Repository/NewRepository/ProductBundleRepository.php index 69037b61..413ffbbf 100644 --- a/src/Repository/NewRepository/ProductBundleRepository.php +++ b/src/Repository/NewRepository/ProductBundleRepository.php @@ -75,7 +75,7 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso, $d $this->generateFullQuery($langIso, true); $this->query - ->where('p.id_bundle IN(' . implode(',', array_map('intval', $contentIds)) . ')') + ->where('pac.id_bundle IN(' . implode(',', array_map('intval', $contentIds)) . ')') ->limit($limit) ; diff --git a/src/Service/ShopContent/ImageTypesService.php b/src/Service/ShopContent/ImageTypesService.php new file mode 100644 index 00000000..ddfb1224 --- /dev/null +++ b/src/Service/ShopContent/ImageTypesService.php @@ -0,0 +1,103 @@ +imageTypeRepository = $imageTypeRepository; + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * @param bool $debug + * + * @return array + */ + public function getContentsForFull($offset, $limit, $langIso, $debug) + { + $result = $this->imageTypeRepository->retrieveContentsForFull($offset, $limit, $langIso, $debug); + + if (empty($result)) { + return []; + } + + $this->castImageTypes($result); + + return array_map(function ($item) { + return [ + 'id' => (string) $item['id_image_type'], + 'collection' => Config::COLLECTION_IMAGE_TYPES, + 'properties' => $item, + ]; + }, $result); + } + + /** + * @param int $limit + * @param array $contentIds + * @param string $langIso + * @param bool $debug + * + * @return array + */ + public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) + { + $result = $this->imageTypeRepository->retrieveContentsForIncremental($limit, $contentIds, $langIso, $debug); + + if (empty($result)) { + return []; + } + + $this->castImageTypes($result); + + return array_map(function ($item) { + return [ + 'id' => (string) $item['id_image_type'], + 'collection' => Config::COLLECTION_IMAGE_TYPES, + 'properties' => $item, + ]; + }, $result); + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return int + */ + public function getFullSyncContentLeft($offset, $limit, $langIso) + { + return $this->imageTypeRepository->countFullSyncContentLeft($offset, $limit, $langIso); + } + + /** + * @param array $imageTypes + * + * @return void + */ + private function castImageTypes(&$imageTypes) + { + foreach ($imageTypes as &$imageType) { + $imageType['id_image_type'] = (int) $imageType['id_image_type']; + $imageType['name'] = (string) $imageType['name']; + $imageType['width'] = (int) $imageType['width']; + $imageType['height'] = (int) $imageType['height']; + $imageType['products'] = (bool) $imageType['products']; + $imageType['categories'] = (bool) $imageType['categories']; + $imageType['manufacturers'] = (bool) $imageType['manufacturers']; + $imageType['suppliers'] = (bool) $imageType['suppliers']; + $imageType['stores'] = (bool) $imageType['stores']; + } + } +} diff --git a/src/Service/ShopContent/ImagesService.php b/src/Service/ShopContent/ImagesService.php new file mode 100644 index 00000000..619a80a0 --- /dev/null +++ b/src/Service/ShopContent/ImagesService.php @@ -0,0 +1,101 @@ +imageRepository = $imageRepository; + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * @param bool $debug + * + * @return array + */ + public function getContentsForFull($offset, $limit, $langIso, $debug) + { + $result = $this->imageRepository->retrieveContentsForFull($offset, $limit, $langIso, $debug); + + if (empty($result)) { + return []; + } + + $this->castImages($result); + + return array_map(function ($item) { + return [ + 'id' => (string) $item['id_image'], + 'collection' => Config::COLLECTION_IMAGES, + 'properties' => $item, + ]; + }, $result); + } + + /** + * @param int $limit + * @param array $contentIds + * @param string $langIso + * @param bool $debug + * + * @return array + */ + public function getContentsForIncremental($limit, $contentIds, $langIso, $debug) + { + $result = $this->imageRepository->retrieveContentsForIncremental($limit, $contentIds, $langIso, $debug); + + if (empty($result)) { + return []; + } + + $this->castImages($result); + + return array_map(function ($item) { + return [ + 'id' => (string) $item['id_image'], + 'collection' => Config::COLLECTION_IMAGES, + 'properties' => $item, + ]; + }, $result); + } + + /** + * @param int $offset + * @param int $limit + * @param string $langIso + * + * @return int + */ + public function getFullSyncContentLeft($offset, $limit, $langIso) + { + return $this->imageRepository->countFullSyncContentLeft($offset, $limit, $langIso); + } + + /** + * @param array $images + * + * @return void + */ + private function castImages(&$images) + { + foreach ($images as &$image) { + $image['id_image'] = (int) $image['id_image']; + $image['id_product'] = (int) $image['id_product']; + $image['id_lang'] = (int) $image['id_lang']; + $image['id_shop'] = (int) $image['id_shop']; + $image['position'] = (int) $image['position']; + $image['cover'] = (bool) $image['cover']; + $image['legend'] = (string) $image['legend']; + } + } +} From efc89d7c25d2ed4442b4651da561f7928eeb2ca8 Mon Sep 17 00:00:00 2001 From: "John.R" Date: Fri, 20 Sep 2024 17:22:25 +0200 Subject: [PATCH 2/2] fix: remove all extra useless files --- OLD/Provider/CartDataProvider.php | 173 ------------------ OLD/Provider/CartRuleDataProvider.php | 137 -------------- OLD/Provider/CategoryDataProvider.php | 106 ----------- OLD/Provider/CurrencyDataProvider.php | 105 ----------- .../CustomProductCarrierDataProvider.php | 85 --------- OLD/Provider/CustomerDataProvider.php | 106 ----------- OLD/Provider/EmployeeDataProvider.php | 106 ----------- OLD/Provider/ImageDataProvider.php | 106 ----------- OLD/Provider/ImageTypeDataProvider.php | 106 ----------- config/common/decorator.yml | 28 --- e2e/src/helpers/shop-contents.ts | 14 -- src/Decorator/CurrencyDecorator.php | 36 ---- src/Decorator/CustomerDecorator.php | 47 ----- src/Decorator/EmployeeDecorator.php | 67 ------- src/Decorator/ImageDecorator.php | 34 ---- src/Decorator/ImageTypeDecorator.php | 36 ---- 16 files changed, 1292 deletions(-) delete mode 100644 OLD/Provider/CartDataProvider.php delete mode 100644 OLD/Provider/CartRuleDataProvider.php delete mode 100644 OLD/Provider/CategoryDataProvider.php delete mode 100644 OLD/Provider/CurrencyDataProvider.php delete mode 100644 OLD/Provider/CustomProductCarrierDataProvider.php delete mode 100644 OLD/Provider/CustomerDataProvider.php delete mode 100644 OLD/Provider/EmployeeDataProvider.php delete mode 100644 OLD/Provider/ImageDataProvider.php delete mode 100644 OLD/Provider/ImageTypeDataProvider.php delete mode 100644 src/Decorator/CurrencyDecorator.php delete mode 100644 src/Decorator/CustomerDecorator.php delete mode 100644 src/Decorator/EmployeeDecorator.php delete mode 100644 src/Decorator/ImageDecorator.php delete mode 100644 src/Decorator/ImageTypeDecorator.php diff --git a/OLD/Provider/CartDataProvider.php b/OLD/Provider/CartDataProvider.php deleted file mode 100644 index d31ab62e..00000000 --- a/OLD/Provider/CartDataProvider.php +++ /dev/null @@ -1,173 +0,0 @@ -cartRepository = $cartRepository; - $this->cartProductRepository = $cartProductRepository; - } - - public function getFormattedData($offset, $limit, $langIso) - { - $carts = $this->cartRepository->getCarts($offset, $limit); - - if (!is_array($carts)) { - return []; - } - - $cartProducts = $this->getCartProducts($carts); - - $this->castCartValues($carts); - - $carts = array_map(function ($cart) { - return [ - 'id' => $cart['id_cart'], - 'collection' => Config::COLLECTION_CARTS, - 'properties' => $cart, - ]; - }, $carts); - - return array_merge($carts, $cartProducts); - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - */ - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->cartRepository->getRemainingCartsCount($offset); - } - - /** - * @param array $carts - * - * @return void - */ - private function castCartValues(&$carts) - { - foreach ($carts as &$cart) { - $cart['id_cart'] = (string) $cart['id_cart']; - } - } - - /** - * @param array $cartProducts - * - * @return void - */ - private function castCartProductValues(&$cartProducts) - { - foreach ($cartProducts as &$cartProduct) { - $cartProduct['id_cart_product'] = (string) "{$cartProduct['id_cart']}-{$cartProduct['id_product']}-{$cartProduct['id_product_attribute']}"; - $cartProduct['id_cart'] = (string) $cartProduct['id_cart']; - $cartProduct['id_product'] = (string) $cartProduct['id_product']; - $cartProduct['id_product_attribute'] = (string) $cartProduct['id_product_attribute']; - $cartProduct['quantity'] = (int) $cartProduct['quantity']; - } - } - - /** - * @param int $limit - * @param string $langIso - * @param array $objectIds - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - $carts = $this->cartRepository->getCartsIncremental($limit, $objectIds); - - if (!is_array($carts) || empty($carts)) { - return []; - } - - $cartProducts = $this->getCartProducts($carts); - - $this->castCartValues($carts); - - $carts = array_map(function ($cart) { - return [ - 'id' => $cart['id_cart'], - 'collection' => Config::COLLECTION_CARTS, - 'properties' => $cart, - ]; - }, $carts); - - return array_merge($carts, $cartProducts); - } - - /** - * @param array $carts - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - private function getCartProducts($carts) - { - $cartIds = array_map(function ($cart) { - return (string) $cart['id_cart']; - }, $carts); - - $cartProducts = $this->cartProductRepository->getCartProducts($cartIds); - - if (!is_array($cartProducts) || empty($cartProducts)) { - return []; - } - - $this->castCartProductValues($cartProducts); - - if (is_array($cartProducts)) { - return array_map(function ($cartProduct) { - return [ - 'id' => "{$cartProduct['id_cart']}-{$cartProduct['id_product']}-{$cartProduct['id_product_attribute']}", - 'collection' => Config::COLLECTION_CART_PRODUCTS, - 'properties' => $cartProduct, - ]; - }, $cartProducts); - } - - return []; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->cartRepository->getQueryForDebug($offset, $limit); - } -} diff --git a/OLD/Provider/CartRuleDataProvider.php b/OLD/Provider/CartRuleDataProvider.php deleted file mode 100644 index fc1d9e85..00000000 --- a/OLD/Provider/CartRuleDataProvider.php +++ /dev/null @@ -1,137 +0,0 @@ -cartRuleRepository = $cartRuleRepository; - } - - public function getFormattedData($offset, $limit, $langIso) - { - $cartRules = $this->cartRuleRepository->getCartRules($limit, $offset); - - if (!is_array($cartRules) || empty($cartRules)) { - return []; - } - - $this->castCartRuleValues($cartRules); - - if (is_array($cartRules)) { - return array_map(function ($cartRule) { - return [ - 'id' => $cartRule['id_cart_rule'], - 'collection' => Config::COLLECTION_CART_RULES, - 'properties' => $cartRule, - ]; - }, $cartRules); - } - - return []; - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - */ - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->cartRuleRepository->getRemainingCartRulesCount($offset); - } - - /** - * @param int $limit - * @param string $langIso - * @param array $objectIds - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - $cartRules = $this->cartRuleRepository->getCartRulesIncremental($limit, $objectIds); - - if (!is_array($cartRules)) { - return []; - } - - $this->castCartRuleValues($cartRules); - - return array_map(function ($cartRule) { - return [ - 'id' => $cartRule['id_cart_rule'], - 'collection' => Config::COLLECTION_CART_RULES, - 'properties' => $cartRule, - ]; - }, $cartRules); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->cartRuleRepository->getQueryForDebug($limit, $offset); - } - - /** - * @param array $cartRules - * - * @return void - */ - private function castCartRuleValues(&$cartRules) - { - foreach ($cartRules as &$cartRule) { - $cartRule['id_cart_rule'] = (int) $cartRule['id_cart_rule']; - $cartRule['id_customer'] = (int) $cartRule['id_customer']; - $cartRule['quantity'] = (int) $cartRule['quantity']; - $cartRule['quantity_per_user'] = (int) $cartRule['quantity_per_user']; - $cartRule['priority'] = (int) $cartRule['priority']; - $cartRule['partial_use'] = (bool) $cartRule['partial_use']; - $cartRule['minimum_amount'] = (float) $cartRule['minimum_amount']; - $cartRule['minimum_amount_tax'] = (bool) $cartRule['minimum_amount_tax']; - $cartRule['minimum_amount_currency'] = (int) $cartRule['minimum_amount_currency']; - $cartRule['minimum_amount_shipping'] = (bool) $cartRule['minimum_amount_shipping']; - $cartRule['country_restriction'] = (bool) $cartRule['country_restriction']; - $cartRule['carrier_restriction'] = (bool) $cartRule['carrier_restriction']; - $cartRule['group_restriction'] = (bool) $cartRule['group_restriction']; - $cartRule['cart_rule_restriction'] = (bool) $cartRule['cart_rule_restriction']; - $cartRule['product_restriction'] = (bool) $cartRule['product_restriction']; - $cartRule['shop_restriction'] = (bool) $cartRule['shop_restriction']; - $cartRule['free_shipping'] = (bool) $cartRule['free_shipping']; - $cartRule['reduction_percent'] = (float) $cartRule['reduction_percent']; - $cartRule['reduction_amount'] = (float) $cartRule['reduction_amount']; - $cartRule['reduction_tax'] = (bool) $cartRule['reduction_tax']; - $cartRule['reduction_currency'] = (int) $cartRule['reduction_currency']; - $cartRule['reduction_product'] = (int) $cartRule['reduction_product']; - $cartRule['reduction_exclude_special'] = (bool) $cartRule['reduction_exclude_special']; - $cartRule['gift_product'] = (int) $cartRule['gift_product']; - $cartRule['gift_product_attribute'] = (int) $cartRule['gift_product_attribute']; - $cartRule['highlight'] = (bool) $cartRule['highlight']; - $cartRule['active'] = (bool) $cartRule['active']; - } - } -} diff --git a/OLD/Provider/CategoryDataProvider.php b/OLD/Provider/CategoryDataProvider.php deleted file mode 100644 index 80cf9876..00000000 --- a/OLD/Provider/CategoryDataProvider.php +++ /dev/null @@ -1,106 +0,0 @@ -categoryRepository = $categoryRepository; - $this->categoryDecorator = $categoryDecorator; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedData($offset, $limit, $langIso) - { - $categories = $this->categoryRepository->getCategories($offset, $limit, $langIso); - - if (!is_array($categories)) { - return []; - } - - $this->categoryDecorator->decorateCategories($categories); - - return array_map(function ($category) { - return [ - 'id' => "{$category['id_category']}-{$category['iso_code']}", - 'collection' => Config::COLLECTION_CATEGORIES, - 'properties' => $category, - ]; - }, $categories); - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - */ - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->categoryRepository->getRemainingCategoriesCount($offset, $langIso); - } - - /** - * @param int $limit - * @param string $langIso - * @param array $objectIds - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - $categories = $this->categoryRepository->getCategoriesIncremental($limit, $langIso, $objectIds); - - if (!is_array($categories)) { - return []; - } - - $this->categoryDecorator->decorateCategories($categories); - - return array_map(function ($category) { - return [ - 'id' => "{$category['id_category']}-{$category['iso_code']}", - 'collection' => Config::COLLECTION_CATEGORIES, - 'properties' => $category, - ]; - }, $categories); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->categoryRepository->getQueryForDebug($offset, $limit, $langIso); - } -} diff --git a/OLD/Provider/CurrencyDataProvider.php b/OLD/Provider/CurrencyDataProvider.php deleted file mode 100644 index 9ee19053..00000000 --- a/OLD/Provider/CurrencyDataProvider.php +++ /dev/null @@ -1,105 +0,0 @@ -currencyRepository = $currencyRepository; - $this->currencyDecorator = $currencyDecorator; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedData($offset, $limit, $langIso) - { - $currencies = $this->currencyRepository->getCurrencies($offset, $limit); - - if (!is_array($currencies)) { - return []; - } - $this->currencyDecorator->decorateCurrencies($currencies); - - return array_map(function ($currency) { - return [ - 'id' => $currency['id_currency'], - 'collection' => Config::COLLECTION_CURRENCIES, - 'properties' => $currency, - ]; - }, $currencies); - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - */ - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->currencyRepository->getRemainingCurrenciesCount($offset); - } - - /** - * @param int $limit - * @param string $langIso - * @param array $objectIds - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - $currencies = $this->currencyRepository->getCurrenciesIncremental($limit, $objectIds); - - if (!is_array($currencies)) { - return []; - } - $this->currencyDecorator->decorateCurrencies($currencies); - - return array_map(function ($currency) { - return [ - 'id' => $currency['id_currency'], - 'collection' => Config::COLLECTION_CURRENCIES, - 'properties' => $currency, - ]; - }, $currencies); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->currencyRepository->getQueryForDebug($offset, $limit); - } -} diff --git a/OLD/Provider/CustomProductCarrierDataProvider.php b/OLD/Provider/CustomProductCarrierDataProvider.php deleted file mode 100644 index c0ef680b..00000000 --- a/OLD/Provider/CustomProductCarrierDataProvider.php +++ /dev/null @@ -1,85 +0,0 @@ -productCarrierRepository = $productCarrierRepository; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedData($offset, $limit, $langIso) - { - $productCarriers = $this->productCarrierRepository->getProductCarriers($offset, $limit); - $productCarriers = array_map(function ($productCarrier) { - return [ - 'id' => $productCarrier['id_product'] . '-' . $productCarrier['id_carrier_reference'], - 'collection' => Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS, - 'properties' => $productCarrier, - ]; - }, $productCarriers); - - return $productCarriers; - } - - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - /** @var array $productCarrierIncremental */ - $productCarrierIncremental = $this->productCarrierRepository->getProductCarrierIncremental(Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS, $langIso); - - if (!$productCarrierIncremental) { - return []; - } - - $productIds = array_column($productCarrierIncremental, 'id_object'); - - /** @var array $productCarriers */ - $productCarriers = $this->productCarrierRepository->getProductCarriersProperties($productIds); - - return array_map(function ($productCarrier) { - return [ - 'id' => "{$productCarrier['id_product']}-{$productCarrier['id_carrier_reference']}", - 'collection' => Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS, - 'properties' => $productCarrier, - ]; - }, $productCarriers); - } - - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->productCarrierRepository->getRemainingProductCarriersCount($offset); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->productCarrierRepository->getQueryForDebug($offset, $limit); - } -} diff --git a/OLD/Provider/CustomerDataProvider.php b/OLD/Provider/CustomerDataProvider.php deleted file mode 100644 index 75a682c1..00000000 --- a/OLD/Provider/CustomerDataProvider.php +++ /dev/null @@ -1,106 +0,0 @@ -customerRepository = $customerRepository; - $this->customerDecorator = $customerDecorator; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedData($offset, $limit, $langIso) - { - $customers = $this->customerRepository->getCustomers($offset, $limit); - - if (!is_array($customers)) { - return []; - } - - $this->customerDecorator->decorateCustomers($customers); - - return array_map(function ($customer) { - return [ - 'id' => "{$customer['id_customer']}", - 'collection' => Config::COLLECTION_CUSTOMERS, - 'properties' => $customer, - ]; - }, $customers); - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - */ - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->customerRepository->getRemainingCustomersCount($offset); - } - - /** - * @param int $limit - * @param string $langIso - * @param array $objectIds - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - $customers = $this->customerRepository->getCustomersIncremental($limit, $objectIds); - - if (!is_array($customers)) { - return []; - } - - $this->customerDecorator->decorateCustomers($customers); - - return array_map(function ($customer) { - return [ - 'id' => "{$customer['id_customer']}", - 'collection' => Config::COLLECTION_CUSTOMERS, - 'properties' => $customer, - ]; - }, $customers); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->customerRepository->getQueryForDebug($offset, $limit); - } -} diff --git a/OLD/Provider/EmployeeDataProvider.php b/OLD/Provider/EmployeeDataProvider.php deleted file mode 100644 index df991457..00000000 --- a/OLD/Provider/EmployeeDataProvider.php +++ /dev/null @@ -1,106 +0,0 @@ -employeeRepository = $employeeRepository; - $this->employeeDecorator = $employeeDecorator; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedData($offset, $limit, $langIso) - { - $employees = $this->employeeRepository->getEmployees($offset, $limit); - - if (!is_array($employees)) { - return []; - } - - $this->employeeDecorator->decorateEmployees($employees); - - return array_map(function ($employee) { - return [ - 'id' => "{$employee['id_employee']}", - 'collection' => Config::COLLECTION_EMPLOYEES, - 'properties' => $employee, - ]; - }, $employees); - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - */ - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->employeeRepository->getRemainingEmployeesCount($offset); - } - - /** - * @param int $limit - * @param string $langIso - * @param array $objectIds - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - $employees = $this->employeeRepository->getEmployeesIncremental($limit, $objectIds); - - if (!is_array($employees)) { - return []; - } - - $this->employeeDecorator->decorateEmployees($employees); - - return array_map(function ($employee) { - return [ - 'id' => "{$employee['id_customer']}", - 'collection' => Config::COLLECTION_EMPLOYEES, - 'properties' => $employee, - ]; - }, $employees); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->employeeRepository->getQueryForDebug($offset, $limit); - } -} diff --git a/OLD/Provider/ImageDataProvider.php b/OLD/Provider/ImageDataProvider.php deleted file mode 100644 index 89201986..00000000 --- a/OLD/Provider/ImageDataProvider.php +++ /dev/null @@ -1,106 +0,0 @@ -imageRepository = $imageRepository; - $this->imageDecorator = $imageDecorator; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedData($offset, $limit, $langIso) - { - $images = $this->imageRepository->getImages($offset, $limit); - - if (!is_array($images)) { - return []; - } - - $this->imageDecorator->decorateImages($images); - - return array_map(function ($image) { - return [ - 'id' => "{$image['id_image']}", - 'collection' => Config::COLLECTION_IMAGES, - 'properties' => $image, - ]; - }, $images); - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - */ - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->imageRepository->getRemainingImagesCount($offset); - } - - /** - * @param int $limit - * @param string $langIso - * @param array $objectIds - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - $images = $this->imageRepository->getImagesIncremental($limit, $objectIds); - - if (!is_array($images)) { - return []; - } - - $this->imageDecorator->decorateImages($images); - - return array_map(function ($image) { - return [ - 'id' => "{$image['id_image']}", - 'collection' => Config::COLLECTION_IMAGES, - 'properties' => $image, - ]; - }, $images); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->imageRepository->getQueryForDebug($offset, $limit); - } -} diff --git a/OLD/Provider/ImageTypeDataProvider.php b/OLD/Provider/ImageTypeDataProvider.php deleted file mode 100644 index a15e8bac..00000000 --- a/OLD/Provider/ImageTypeDataProvider.php +++ /dev/null @@ -1,106 +0,0 @@ -imageTypeRepository = $imageTypeRepository; - $this->imageTypeDecorator = $imageTypeDecorator; - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedData($offset, $limit, $langIso) - { - $imageTypes = $this->imageTypeRepository->getImageTypes($offset, $limit); - - if (!is_array($imageTypes)) { - return []; - } - - $this->imageTypeDecorator->decorateImageTypes($imageTypes); - - return array_map(function ($imageType) { - return [ - 'id' => "{$imageType['id_image_type']}", - 'collection' => Config::COLLECTION_IMAGE_TYPES, - 'properties' => $imageType, - ]; - }, $imageTypes); - } - - /** - * @param int $offset - * @param string $langIso - * - * @return int - */ - public function getRemainingObjectsCount($offset, $langIso) - { - return (int) $this->imageTypeRepository->getRemainingImageTypesCount($offset); - } - - /** - * @param int $limit - * @param string $langIso - * @param array $objectIds - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getFormattedDataIncremental($limit, $langIso, $objectIds) - { - $imageTypes = $this->imageTypeRepository->getImageTypesIncremental($limit, $objectIds); - - if (!is_array($imageTypes)) { - return []; - } - - $this->imageTypeDecorator->decorateImageTypes($imageTypes); - - return array_map(function ($imageType) { - return [ - 'id' => "{$imageType['id_image_type']}", - 'collection' => Config::COLLECTION_IMAGE_TYPES, - 'properties' => $imageType, - ]; - }, $imageTypes); - } - - /** - * @param int $offset - * @param int $limit - * @param string $langIso - * - * @return array - * - * @@throws \PrestaShopDatabaseException - */ - public function getQueryForDebug($offset, $limit, $langIso) - { - return $this->imageTypeRepository->getQueryForDebug($offset, $limit); - } -} diff --git a/config/common/decorator.yml b/config/common/decorator.yml index 68ae3d0d..1879f558 100644 --- a/config/common/decorator.yml +++ b/config/common/decorator.yml @@ -1,16 +1,4 @@ services: - PrestaShop\Module\PsEventbus\Decorator\CategoryDecorator: - class: PrestaShop\Module\PsEventbus\Decorator\CategoryDecorator - public: true - - PrestaShop\Module\PsEventbus\Decorator\CurrencyDecorator: - class: PrestaShop\Module\PsEventbus\Decorator\CurrencyDecorator - public: true - - PrestaShop\Module\PsEventbus\Decorator\CustomerDecorator: - class: PrestaShop\Module\PsEventbus\Decorator\CustomerDecorator - public: true - PrestaShop\Module\PsEventbus\Decorator\PayloadDecorator: class: PrestaShop\Module\PsEventbus\Decorator\PayloadDecorator public: true @@ -44,26 +32,10 @@ services: class: PrestaShop\Module\PsEventbus\Decorator\SupplierDecorator public: true - PrestaShop\Module\PsEventbus\Decorator\ProductSupplierDecorator: - class: PrestaShop\Module\PsEventbus\Decorator\ProductSupplierDecorator - public: true - - PrestaShop\Module\PsEventbus\Decorator\EmployeeDecorator: - class: PrestaShop\Module\PsEventbus\Decorator\EmployeeDecorator - public: true - PrestaShop\Module\PsEventbus\Decorator\LanguageDecorator: class: PrestaShop\Module\PsEventbus\Decorator\LanguageDecorator public: true - PrestaShop\Module\PsEventbus\Decorator\ImageDecorator: - class: PrestaShop\Module\PsEventbus\Decorator\ImageDecorator - public: true - - PrestaShop\Module\PsEventbus\Decorator\ImageTypeDecorator: - class: PrestaShop\Module\PsEventbus\Decorator\ImageTypeDecorator - public: true - PrestaShop\Module\PsEventbus\Decorator\TranslationDecorator: class: PrestaShop\Module\PsEventbus\Decorator\TranslationDecorator public: true diff --git a/e2e/src/helpers/shop-contents.ts b/e2e/src/helpers/shop-contents.ts index f6e0b6cc..73676bc8 100644 --- a/e2e/src/helpers/shop-contents.ts +++ b/e2e/src/helpers/shop-contents.ts @@ -3,34 +3,20 @@ import R from "ramda"; // TEMPORARY DISABLED, WAIT ADD ALL SHOP CONTENT // AFTER UNCOMMENT THIS, CHANGE ALL "as ShopContent"CAST IN FULLSYNC TEST /* export const shopContentMapping = { - 'carrier_details': 'carrier-details', - 'carts' : 'carts', - 'cart_products': 'carts', - 'cart_rules' : 'cart-rules', - 'categories' : 'categories', - 'currencies' : 'currencies', 'specific_prices': 'specific-prices', - 'custom_product_carriers' : 'custom-product-carriers', - 'customers': 'customers', 'taxonomies': 'taxonomies', 'modules': 'modules', - 'products': 'products', 'shops': 'info', 'stores': 'stores', 'themes': 'themes', - 'product_bundles': 'product-bundles', 'wishlists': 'wishlists', 'wishlist_products': 'wishlist-products', 'stocks': 'stocks', 'stock_movements': 'stock-movements', 'manufacturers': 'manufacturers', 'suppliers': 'suppliers', - 'product_suppliers': 'product-suppliers', 'languages': 'languages', - 'employees': 'employees', 'translations': 'translations', - 'images': 'images', - 'image_types': 'image-types' } as const; */ export const shopContentMapping = { diff --git a/src/Decorator/CurrencyDecorator.php b/src/Decorator/CurrencyDecorator.php deleted file mode 100644 index 64060be8..00000000 --- a/src/Decorator/CurrencyDecorator.php +++ /dev/null @@ -1,36 +0,0 @@ - $currencies - * - * @return void - */ - public function decorateCurrencies(&$currencies) - { - foreach ($currencies as &$currency) { - $this->castPropertyValues($currency); - } - } - - /** - * @param array $currency - * - * @return void - */ - private function castPropertyValues(&$currency) - { - $currency['id_currency'] = (int) $currency['id_currency']; - $currency['conversion_rate'] = (float) $currency['conversion_rate']; - $currency['deleted'] = (bool) $currency['deleted']; - $currency['active'] = (bool) $currency['active']; - - // https://github.com/PrestaShop/PrestaShop/commit/37807f66b40b0cebb365ef952e919be15e9d6b2f#diff-3f41d3529ffdbfd1b994927eb91826a32a0560697025a734cf128a2c8e092a45R124 - if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.6.0', '>=')) { - $currency['precision'] = (int) $currency['precision']; - } - } -} diff --git a/src/Decorator/CustomerDecorator.php b/src/Decorator/CustomerDecorator.php deleted file mode 100644 index 97cc6eea..00000000 --- a/src/Decorator/CustomerDecorator.php +++ /dev/null @@ -1,47 +0,0 @@ - $customers - * - * @return void - */ - public function decorateCustomers(&$customers) - { - foreach ($customers as &$customer) { - $this->castPropertyValues($customer); - $this->hashEmail($customer); - } - } - - /** - * @param array $customer - * - * @return void - */ - private function castPropertyValues(&$customer) - { - $customer['id_customer'] = (int) $customer['id_customer']; - $customer['id_lang'] = (int) $customer['id_lang']; - $customer['newsletter'] = (bool) $customer['newsletter']; - $customer['newsletter_date_add'] = (string) $customer['newsletter_date_add']; - $customer['optin'] = (bool) $customer['optin']; - $customer['active'] = (bool) $customer['active']; - $customer['is_guest'] = (bool) $customer['is_guest']; - $customer['deleted'] = (bool) $customer['deleted']; - } - - /** - * @param array $customer - * - * @return void - */ - private function hashEmail(&$customer) - { - $customer['email_hash'] = hash('sha256', $customer['email'] . 'dUj4GMBD6689pL9pyr'); - unset($customer['email']); - } -} diff --git a/src/Decorator/EmployeeDecorator.php b/src/Decorator/EmployeeDecorator.php deleted file mode 100644 index 46d89006..00000000 --- a/src/Decorator/EmployeeDecorator.php +++ /dev/null @@ -1,67 +0,0 @@ - $employees - * - * @return void - */ - public function decorateEmployees(&$employees) - { - foreach ($employees as &$employee) { - $this->castPropertyValues($employee); - $this->hashEmail($employee); - } - } - - /** - * @param array $employee - * - * @return void - */ - private function castPropertyValues(&$employee) - { - $employee['id_employee'] = (int) $employee['id_employee']; - $employee['id_profile'] = (int) $employee['id_profile']; - $employee['id_lang'] = (int) $employee['id_lang']; - - $employee['default_tab'] = (int) $employee['default_tab']; - $employee['bo_width'] = (int) $employee['bo_width']; - $employee['bo_menu'] = (bool) $employee['bo_menu']; - - $employee['optin'] = (bool) $employee['optin']; - $employee['active'] = (bool) $employee['active']; - - $employee['id_last_order'] = (int) $employee['id_last_order']; - $employee['id_last_customer_message'] = (int) $employee['id_last_customer_message']; - $employee['id_last_customer'] = (int) $employee['id_last_customer']; - - if ($employee['last_connection_date'] == '0000-00-00') { - $employee['last_connection_date'] = null; - } else { - $employee['last_connection_date'] = (string) $employee['last_connection_date']; - } - - $employee['id_shop'] = (int) $employee['id_shop']; - - // https://github.com/PrestaShop/PrestaShop/commit/20f1d9fe8a03559dfa9d1f7109de1f70c99f1874#diff-cde6a9d4a58afb13ff068801ee09c0e712c5e90b0cbf5632a0cc965f15cb6802R107 - if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.8.0', '>=')) { - $employee['has_enabled_gravatar'] = (bool) $employee['has_enabled_gravatar']; - } - } - - /** - * @param array $employee - * - * @return void - */ - private function hashEmail(&$employee) - { - // FIXME : use a random salt generated during module install - $employee['email_hash'] = hash('sha256', $employee['email'] . 'dUj4GMBD6689pL9pyr'); - unset($employee['email']); - } -} diff --git a/src/Decorator/ImageDecorator.php b/src/Decorator/ImageDecorator.php deleted file mode 100644 index 5e3a4fda..00000000 --- a/src/Decorator/ImageDecorator.php +++ /dev/null @@ -1,34 +0,0 @@ - $images - * - * @return void - */ - public function decorateImages(&$images) - { - foreach ($images as &$image) { - $this->castPropertyValues($image); - } - } - - /** - * @param array $image - * - * @return void - */ - private function castPropertyValues(&$image) - { - $image['id_image'] = (int) $image['id_image']; - $image['id_product'] = (int) $image['id_product']; - $image['id_lang'] = (int) $image['id_lang']; - $image['id_shop'] = (int) $image['id_shop']; - $image['position'] = (int) $image['position']; - $image['cover'] = (bool) $image['cover']; - $image['legend'] = (string) $image['legend']; - } -} diff --git a/src/Decorator/ImageTypeDecorator.php b/src/Decorator/ImageTypeDecorator.php deleted file mode 100644 index 82b42cbd..00000000 --- a/src/Decorator/ImageTypeDecorator.php +++ /dev/null @@ -1,36 +0,0 @@ - $imageTypes - * - * @return void - */ - public function decorateImageTypes(&$imageTypes) - { - foreach ($imageTypes as &$imageType) { - $this->castPropertyValues($imageType); - } - } - - /** - * @param array $imageType - * - * @return void - */ - private function castPropertyValues(&$imageType) - { - $imageType['id_image_type'] = (int) $imageType['id_image_type']; - $imageType['name'] = (string) $imageType['name']; - $imageType['width'] = (int) $imageType['width']; - $imageType['height'] = (int) $imageType['height']; - $imageType['products'] = (bool) $imageType['products']; - $imageType['categories'] = (bool) $imageType['categories']; - $imageType['manufacturers'] = (bool) $imageType['manufacturers']; - $imageType['suppliers'] = (bool) $imageType['suppliers']; - $imageType['stores'] = (bool) $imageType['stores']; - } -}