From f509fb4c942c63962343d75b3db9e737e4521e5c Mon Sep 17 00:00:00 2001 From: TakeshiDaveau Date: Thu, 31 Aug 2023 09:58:40 +0200 Subject: [PATCH 1/2] revert: use tosLink and privacyLink instead of tosUrl and privacyUrl to handle retrocompatibility --- src/Presenter/BillingPresenter.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Presenter/BillingPresenter.php b/src/Presenter/BillingPresenter.php index e4d136f..d566c8e 100644 --- a/src/Presenter/BillingPresenter.php +++ b/src/Presenter/BillingPresenter.php @@ -107,8 +107,8 @@ public function present($params) 'id' => $this->getModule()->name, 'displayName' => $this->getModule()->displayName, 'logoSrc' => $this->encodeImage($this->getModuleLogo()), - 'privacyUrl' => !empty($params['privacyUrl']) ? $params['privacyUrl'] : '', - 'tosUrl' => !empty($params['tosUrl']) ? $params['tosUrl'] : '', + 'privacyUrl' => !empty($params['privacyUrl']) ? $params['privacyUrl'] : $params['privacyLink'], + 'tosUrl' => !empty($params['tosUrl']) ? $params['tosUrl'] : $params['tosLink'], ], ], ], @@ -126,17 +126,19 @@ public function present($params) */ private function validateContextArgs($params) { - if (empty($params['tosUrl'])) { - throw new BillingContextException('"tosUrl" must be provided (value=' . $params['tosUrl'] . ')'); + $tosUrl = !empty($params['tosUrl']) ? $params['tosUrl'] : $params['tosLink']; + $privacyUrl = !empty($params['privacyUrl']) ? $params['privacyUrl'] : $params['privacyLink']; + if (empty($tosUrl)) { + throw new BillingContextException('"tosUrl" must be provided (value=' . $tosUrl . ')'); } - if (!\Validate::isAbsoluteUrl($params['tosUrl'])) { - throw new BillingContextException('"tosUrl" must be a valid url (value=' . $params['tosUrl'] . ')'); + if (!\Validate::isAbsoluteUrl($tosUrl)) { + throw new BillingContextException('"tosUrl" must be a valid url (value=' . $tosUrl . ')'); } - if (empty($params['privacyUrl'])) { - throw new BillingContextException('"privacyUrl" must be provided (value=' . $params['privacyUrl'] . ')'); + if (empty($privacyUrl)) { + throw new BillingContextException('"privacyUrl" must be provided (value=' . $privacyUrl . ')'); } - if (!\Validate::isAbsoluteUrl($params['privacyUrl'])) { - throw new BillingContextException('"privacyUrl" must be a valid url (value=' . $params['privacyUrl'] . ')'); + if (!\Validate::isAbsoluteUrl($privacyUrl)) { + throw new BillingContextException('"privacyUrl" must be a valid url (value=' . $privacyUrl . ')'); } } From 5b5700c30c4c815aa18fe6fb3ec95c088bcb8e7f Mon Sep 17 00:00:00 2001 From: TakeshiDaveau Date: Thu, 31 Aug 2023 10:22:52 +0200 Subject: [PATCH 2/2] docs: add doc about introducing breaking change --- README.md | 16 ++++++++++++++++ src/Presenter/BillingPresenter.php | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b62459..f69b43d 100644 --- a/README.md +++ b/README.md @@ -113,3 +113,19 @@ chmod +x phpunit ``` ./phpunit tests ``` + +### Introduce a breaking change in module-lib-billing + +PrestaShop module system is not able to handle multiple version of the same library. + +**Here is an example:** +- Module A requires the v1 of a libA +- Module B requires the v2 of this same libA + +If someone install module A then module B, only the v1 of libA will be loaded for both Module A and Module B. + +#### Workaround + +When introducing a breaking change to a class or method signature, you should instead create a new class rather to changing the existing one. + +By creating a new class it will force the autoloader to use the last version of the lib. \ No newline at end of file diff --git a/src/Presenter/BillingPresenter.php b/src/Presenter/BillingPresenter.php index d566c8e..03b2363 100644 --- a/src/Presenter/BillingPresenter.php +++ b/src/Presenter/BillingPresenter.php @@ -81,6 +81,8 @@ public function present($params) $getEnv = $this->getBillingContextWrapper()->getBillingEnv() ?: ''; $billingEnv = $this->getEnvBuilder()->buildBillingEnv($getEnv); + $tosUrl = !empty($params['tosUrl']) ? $params['tosUrl'] : $params['tosLink']; + $privacyUrl = !empty($params['privacyUrl']) ? $params['privacyUrl'] : $params['privacyLink']; return [ 'psBillingContext' => [ @@ -107,8 +109,8 @@ public function present($params) 'id' => $this->getModule()->name, 'displayName' => $this->getModule()->displayName, 'logoSrc' => $this->encodeImage($this->getModuleLogo()), - 'privacyUrl' => !empty($params['privacyUrl']) ? $params['privacyUrl'] : $params['privacyLink'], - 'tosUrl' => !empty($params['tosUrl']) ? $params['tosUrl'] : $params['tosLink'], + 'privacyUrl' => !empty($privacyUrl) ? $privacyUrl : '', + 'tosUrl' => !empty($tosUrl) ? $tosUrl : '', ], ], ],