Skip to content

Commit

Permalink
refactor: pseventbus v4 (#341)
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Désiles <[email protected]>
Co-authored-by: Benoit Houdayer <[email protected]>
Co-authored-by: Guillaume Lepoetre <[email protected]>
  • Loading branch information
4 people authored Jan 8, 2025
1 parent 2b977d6 commit c9fd35a
Show file tree
Hide file tree
Showing 480 changed files with 22,963 additions and 21,021 deletions.
27 changes: 27 additions & 0 deletions .config.inte.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

return [
'ps_eventbus.proxy_api_url' => 'https://eventbus-proxy.psessentials-integration.net',
'ps_eventbus.sync_api_url' => 'https://eventbus-sync.psessentials-integration.net',
'ps_eventbus.live_sync_api_url' => 'https://api.cloudsync-integration.prestashop.com/live-sync/v1',
'ps_eventbus.sentry_dsn' => 'https://[email protected]/6066714',
'ps_eventbus.sentry_env' => 'integration',
];
6 changes: 0 additions & 6 deletions .config.inte.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .config.prod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

return [
'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://[email protected]/6066714',
'ps_eventbus.sentry_env' => 'production',
];
6 changes: 0 additions & 6 deletions .config.prod.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/build-release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
run: |
cp .env.dist .env
docker compose build
docker compose up --detach --wait
docker compose --profile cicd up --detach --wait
env:
DOCKER_IMAGE_PRESTASHOP: prestashop/prestashop-flashlight:${{matrix.ps_version}}
working-directory: e2e-env
Expand All @@ -74,7 +74,7 @@ jobs:
if: failure()
run: |
docker compose logs cloudsync-mock
docker compose down -v
docker compose --profile cicd down -v
working-directory: e2e-env

upload_release_assets:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
strategy:
fail-fast: false
matrix:
# @TODO: "1.6.1.24" is temporarily disabled here
ps_version: ["1.6.1.11", "1.7.8.10", "8.1.6"]
steps:
- name: Checkout
Expand Down Expand Up @@ -115,6 +114,9 @@ jobs:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

- name: install php dependencies
run: composer install

- name: Install dependencies and setup e2e
run: pnpm install --no-optional --force
working-directory: e2e
Expand All @@ -123,7 +125,7 @@ jobs:
run: |
cp .env.dist .env
docker compose build
docker compose up --detach --wait
docker compose --profile cicd up --detach --wait
env:
DOCKER_IMAGE_PRESTASHOP: prestashop/prestashop-flashlight:${{matrix.ps_version}}
working-directory: e2e-env
Expand All @@ -136,7 +138,7 @@ jobs:
if: failure()
run: |
docker compose logs cloudsync-mock prestashop
docker compose down -v
docker compose --profile cicd down -v
working-directory: e2e-env

e2e-lint:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ e2e/dumps
sonar-project.properties

*.cache

### Mytuns
credentials.json
14 changes: 14 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Apache 2.2
<IfModule !mod_authz_core.c>
<Files *.php>
order allow,deny
deny from all
</Files>
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
<Files *.php>
Require all denied
</Files>
</IfModule>
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
->exclude('vendor');

$config = (new PrestaShop\CodingStandards\CsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setUsingCache(false)
->setFinder($finder);

Expand Down
2 changes: 2 additions & 0 deletions .zip-contents
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ src
upgrade
vendor
ps_eventbus.php
config.php
logo.png
config.xml
LICENSE
README.md
composer.json
composer.lock
.htaccess
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ zip: zip-prod zip-inte zip-e2e
# target: zip-e2e - Bundle a local E2E integrable zip
.PHONY: zip-e2e
zip-e2e: vendor tools/vendor dist
@$(call zip_it,./config/parameters.yml,${PACKAGE}_e2e.zip)
@$(call zip_it,./config.php,${PACKAGE}_e2e.zip)

# target: zip-inte - Bundle an integration zip
.PHONY: zip-inte
zip-inte: vendor tools/vendor dist
@$(call zip_it,.config.inte.yml,${PACKAGE}_integration.zip)
@$(call zip_it,.config.inte.php,${PACKAGE}_integration.zip)

# target: zip-prod - Bundle a production zip
.PHONY: zip-prod
zip-prod: vendor tools/vendor dist
@$(call zip_it,.config.prod.yml,${PACKAGE}.zip)
@$(call zip_it,.config.prod.php,${PACKAGE}.zip)

# target: zip-unzipped - Bundle a production module, but without zip step (only to check sources)
.PHONY: zip-unzipped
zip-unzipped: vendor tools/vendor dist
@$(call no_zip_it,.config.prod.yml)
@$(call no_zip_it,.config.prod.php)

dist:
@mkdir -p ./dist
Expand Down Expand Up @@ -151,9 +151,14 @@ docker-phpunit-cov: tools/vendor
.PHONY: phpstan docker-phpstan
phpstan: tools/vendor prestashop/prestashop-${PS_VERSION}
phpstan analyse --memory-limit=-1 --configuration=./tests/phpstan/phpstan-local.neon;
docker-phpstan:
docker-phpstan: tools/vendor
@$(call in_docker,/usr/bin/phpstan,analyse --memory-limit=-1 --configuration=./tests/phpstan/phpstan-docker.neon)

# target: header-stamp - check Headers of PHP files
.PHONY:header-stamp
header-stamp:
tools/vendor/bin/header-stamp --license=tools/vendor/prestashop/header-stamp/assets/osl3.txt --exclude=vendor,tools,e2e,e2e-env,tests,composer.json,scoper.inc.php

define COMMENT
Fixme: add "allure-framework/allure-phpunit" in composer.json to solve this.
Currently failing to resolve devDeps:
Expand All @@ -178,7 +183,8 @@ define create_module
cp -r $(shell cat .zip-contents) ${TMP_DIR}/${MODULE_NAME};
$(call replace_version,${TMP_DIR}/${MODULE_NAME},${SEM_VERSION})
./tools/vendor/bin/autoindex prestashop:add:index ${TMP_DIR}
cp $1 ${TMP_DIR}/${MODULE_NAME}/config/parameters.yml
tools/vendor/bin/header-stamp --target=${TMP_DIR}/${MODULE_NAME} --license=tools/vendor/prestashop/header-stamp/assets/osl3.txt --exclude=vendor,e2e,e2e-env,tests,composer.json,scoper.inc.php
cp $1 ${TMP_DIR}/${MODULE_NAME}/config.php
cd ${TMP_DIR}/${MODULE_NAME} && composer dump-autoload
endef

Expand Down
99 changes: 80 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
## Compatibility matrix

| PrestaShop platform | PHP | PS EventBus |
| ------------------- | ---- | ----------- |
| 8.0 | 7.1+ | From 2.x |
| 1.7.3-1.7.8 | 7.1+ | From 2.x |
| 1.6.1.11 - 1.7.2.5 | 7.1 | From 3.1 |
| ------------------- | ---- | ----------------------- |
| 8.0 | 7.1+ | From 2.x - to latest |
| 1.7.3-1.7.8 | 7.1+ | From 2.x - to latest |
| 1.6.1.11 - 1.7.2.5 | 5.6+ | From 3.1 - to latest |

PS Accounts compatibility matrix [can be viewed here](https://github.com/PrestaShopCorp/ps_accounts#compatibility-matrix).

### Product Images Issue in PHP 8.1
#### Product Images Issue in PHP 8.1

Please note that starting from PHP 8.1, product images may be missing due to a known issue.
This is a recognized problem and is being tracked in the PrestaShop repository.
You can follow the progress and find more details about the resolution [here](https://github.com/PrestaShop/PrestaShop/issues/36836).

### BREAKING CHANGES

Since version 4.0, all API endpoints are grouped under a single controller "apiShopContent.php" (except for the healthcheck). The route to call is now unique, and the shopContent is no longer a specific endpoint but a query parameter of the request:
```http://localhost:8000/index.php?fc=module&module=ps_eventbus&controller=apiShopContent&shop_content=products```

## Use

```sh
Expand Down Expand Up @@ -99,22 +104,78 @@ Dev requirements:

Or an up-to-date [Docker engine](https://docs.docker.com/engine/install).

## List of missing data in a database and why is missing

| Object content | Reason | Added in PS version | Link with more info |
|:----------------------------------:|:--------------------:|:-------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| currency.precision | row missing in table | 1.7.6.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/37807f66b40b0cebb365ef952e919be15e9d6b2f#diff-3f41d3529ffdbfd1b994927eb91826a32a0560697025a734cf128a2c8e092a45R124) |
| employee.has_enabled_gravatar | row missing in table | 1.7.8.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/20f1d9fe8a03559dfa9d1f7109de1f70c99f1874#diff-cde6a9d4a58afb13ff068801ee09c0e712c5e90b0cbf5632a0cc965f15cb6802R107) |
| product.additional_delivery_time | row missing in table | 1.7.3.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/10268af8db4163dc2a02edb8da93d02f37f814d8#diff-e94a594ba740485c7a4882b333984d3932a2f99c0d6d0005620745087cce7a10R260) |
| product.delivery_in_stock | row missing in table | 1.7.3.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/10268af8db4163dc2a02edb8da93d02f37f814d8#diff-e94a594ba740485c7a4882b333984d3932a2f99c0d6d0005620745087cce7a10R260) |
| product.delivery_out_stock | row missing in table | 1.7.3.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/10268af8db4163dc2a02edb8da93d02f37f814d8#diff-e94a594ba740485c7a4882b333984d3932a2f99c0d6d0005620745087cce7a10R260) |
| stock.location | row missing in table | 1.7.5.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/4c7d58a905dfb61c7fb2ef4a1f9b4fab2a8d8ecb#diff-e57fb1deeaab9e9079505333394d58f0bf7bb40280b4382aad1278c08c73e2e8R58) |
| store_lang | table missing | 1.7.3.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/7dda2be62d8bd606edc269fa051c36ea68f81682#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R2004) |
| wishlist¹ | table missing | n/a | [Prestashop Addons](https://addons.prestashop.com/en/undownloadable/9131-wishlist-block.html) |
| taxonomy² | table missing | n/a | [Prestashop Addons](https://addons.prestashop.com/fr/produits-sur-facebook-reseaux-sociaux/50291-prestashop-social-with-facebook-instagram.htmll) |
### How to add new shop content
Let's take the example of adding a shopContent named "plane".

Add the shop content in the [Config.php](src/Config/Config.php) file (create a constant, and add it to the SHOP_CONTENTS array).
```PHP
const COLLECTION_PLANES = 'planes';

const SHOP_CONTENTS = [
...
self::COLLECTION_PLANES
...
];
```

Create a service "planesService.php" (in plural) in the [shop content services folder](src/Service/ShopContent/) that extends the [ShopContentAbstractService](src/Service/ShopContent/ShopContentAbstractService.php) and implements the [ShopContentServiceInterface.php](src/Service/ShopContent/ShopContentServiceInterface.php) interface. For the method structure, use the existing base on all other shop content services to maintain consistency.
```PHP
class PlanesService extends ShopContentAbstractService implements ShopContentServiceInterface
{
...
}
```
_Don't missing to declare this new service to [service.yml](config/front/services.yml) file._

Then create a repository PlaneRepository.php (in singular) in the [Repository](src/Repository/) folder that extends the [AbstractRepository.php](src/Repository/AbstractRepository.php) class and implements the [RepositoryInterface.php](src/Repository/RepositoryInterface.php) interface. Similarly, maintain consistency with other shop content repositories.
```PHP
class PlaneRepository extends AbstractRepository implements RepositoryInterface
{
...
}
```
_Don't missing to declare this new repository to [repository.yml](config/common/repository.yml) file._

Add your shop content in the [e2e config file](e2e/src/helpers/shop-contents.ts).
```javascript
export const shopContentMapping = {
...
planes: 'planes'
...
}
```

Run the tests once to generate the necessary dumps (they will be present in the [dump](e2e/dumps/) folder). Once the test is performed (and failed), copy the planes.json file, and paste it into the fixture folder for your given version. Do the same for each version (if the versions return different results).

You can run the tests again and ensure everything is green.

In case your shopContent cannot return results (missing data in the tables), please add a planes.json file in the folders of each version containing an empty array.

### List of missing data in a database and why is missing

| Object content | Reason | Added in PS version | Link with more info |
|:----------------------------------:|:--------------------:|:-------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| currency.precision | row missing in table | 1.7.6.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/37807f66b40b0cebb365ef952e919be15e9d6b2f#diff-3f41d3529ffdbfd1b994927eb91826a32a0560697025a734cf128a2c8e092a45R124) |
| employee.has_enabled_gravatar | row missing in table | 1.7.8.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/20f1d9fe8a03559dfa9d1f7109de1f70c99f1874#diff-cde6a9d4a58afb13ff068801ee09c0e712c5e90b0cbf5632a0cc965f15cb6802R107) |
| product.additional_delivery_time | row missing in table | 1.7.3.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/10268af8db4163dc2a02edb8da93d02f37f814d8#diff-e94a594ba740485c7a4882b333984d3932a2f99c0d6d0005620745087cce7a10R260) |
| product.delivery_in_stock | row missing in table | 1.7.3.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/10268af8db4163dc2a02edb8da93d02f37f814d8#diff-e94a594ba740485c7a4882b333984d3932a2f99c0d6d0005620745087cce7a10R260) |
| product.delivery_out_stock | row missing in table | 1.7.3.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/10268af8db4163dc2a02edb8da93d02f37f814d8#diff-e94a594ba740485c7a4882b333984d3932a2f99c0d6d0005620745087cce7a10R260) |
| stock.location | row missing in table | 1.7.5.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/4c7d58a905dfb61c7fb2ef4a1f9b4fab2a8d8ecb#diff-e57fb1deeaab9e9079505333394d58f0bf7bb40280b4382aad1278c08c73e2e8R58) |
| store_lang | table missing | 1.7.3.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/7dda2be62d8bd606edc269fa051c36ea68f81682#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R2004) |
| wishlist¹ | table missing | n/a | [Prestashop Addons](https://addons.prestashop.com/en/undownloadable/9131-wishlist-block.html) |
| taxonomy² | table missing | n/a | [Prestashop Addons](https://addons.prestashop.com/fr/produits-sur-facebook-reseaux-sociaux/50291-prestashop-social-with-facebook-instagram.htmll) |
| stock_available. physical_quantity | row missing in table | 1.7.2.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/2a3269ad93b1985f2615d6604458061d4989f0ea#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R2186) |
| stock_available. reserved_quantity | row missing in table | 1.7.2.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/2a3269ad93b1985f2615d6604458061d4989f0ea#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R2186) |
| languages.locale | row missing in table | 1.7.0.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/481111b8274ed005e1c4a8ce2cf2b3ebbeb9a270#diff-c123d3d30d9c9e012a826a21887fccce6600a2f2a848a58d5910e55f0f8f5093R41) |
| languages.locale | row missing in table | 1.7.0.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/481111b8274ed005e1c4a8ce2cf2b3ebbeb9a270#diff-c123d3d30d9c9e012a826a21887fccce6600a2f2a848a58d5910e55f0f8f5093R41) |
| products.mpn | row missing in table | 1.7.7.0 | [github](https://github.com/PrestaShop/PrestaShop/commit/75fcc335a85c4e3acb2444ef9584590a59fc2d62#diff-e98d435095567c145b49744715fd575eaab7050328c211b33aa9a37158421ff4R1615) |

¹ Feature enabled only with PsWishlist module</br>
² Feature enabled only with PsFacebook module

### Debugging
There are 3 variables that are passed globally from the apiShopContent file to the end of the chain (repositories and errorHandler):
- PS_EVENTBUS_EXPLAIN_SQL_ENABLED
- PS_EVENTBUS_VERBOSE_ENABLED
- PS_EVENTBUS_LOGS_ENABLED

These variables are defined via the PHP function define() and reused in the files mentioned above. The reason for this usage is to avoid having to pass these variables through the entire execution chain to retrieve them at the end of the chain (e.g., apiShopContent => frontService => shopContentService => shopContentRepository).
Loading

0 comments on commit c9fd35a

Please sign in to comment.