Skip to content

Commit bd614e9

Browse files
committed
Merge upstream/5.x (v5.2.2) into our fork
Brings in: - fix: recreate deleted config files for upgrade issue (PrestaShopCorp#855) - fix: undefined key 'route' (PrestaShopCorp#857) - fix: upgrade purchased modules (PrestaShopCorp#850) - PHP Null Coalescing Operator fix - Be sure env var are loaded even if putenv disabled Keeps our PHP 8.4 compatibility fixes: - Sentry SDK upgrade to 4.x - Implicit nullable parameter fixes
2 parents 51e8dc2 + 759411c commit bd614e9

File tree

16 files changed

+227
-106
lines changed

16 files changed

+227
-106
lines changed

bootstrap.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
if (!defined('_PS_VERSION_')) {
2121
exit;
2222
}
23-
$rootDir = defined('_PS_ROOT_DIR_') ? _PS_ROOT_DIR_ : getenv('_PS_ROOT_DIR_');
23+
$rootDir = defined('_PS_ROOT_DIR_') ? _PS_ROOT_DIR_ : (function_exists('putenv') ? getenv('_PS_ROOT_DIR_') : $_ENV['_PS_ROOT_DIR_']);
2424
if (!$rootDir) {
2525
$rootDir = __DIR__ . '/../../';
2626
}
@@ -30,6 +30,4 @@
3030
require_once $rootAutoload;
3131
}
3232

33-
(new Symfony\Component\Dotenv\Dotenv())
34-
->usePutenv()
35-
->loadEnv(__DIR__ . '/.env');
33+
\PrestaShop\Module\Mbo\Helpers\EnvHelper::loadEnv(__DIR__ . '/.env');

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<module>
33
<name>ps_mbo</name>
44
<displayName><![CDATA[PrestaShop Marketplace in your Back Office]]></displayName>
5-
<version><![CDATA[5.2.0]]></version>
5+
<version><![CDATA[5.2.2]]></version>
66
<description><![CDATA[Browse the Addons marketplace directly from your back office to better meet your needs.]]></description>
77
<author><![CDATA[PrestaShop]]></author>
88
<tab><![CDATA[administration]]></tab>

config/services/api/modules.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ services:
44

55
PrestaShop\Module\Mbo\Module\SourceRetriever\AddonsUrlSourceRetriever:
66
autowire: true
7+
arguments:
8+
$addonsDataProvider: '@PrestaShop\Module\Mbo\Addons\Provider\AddonsDataProvider'
9+
$translator: '@translator'
10+
$httpClient: '@Psr\Http\Client\ClientInterface'
11+
$requestFactory: '@Psr\Http\Message\ServerRequestFactoryInterface'
12+
$configuration: '@PrestaShop\PrestaShop\Core\ConfigurationInterface'
713
properties:
814
cacheDir: "%kernel.cache_dir%"
915

config/services/overrides.yml

Whitespace-only changes.

config/services/tab.yml

Whitespace-only changes.

ps_mbo.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@
3131
use PrestaShop\Module\Mbo\Accounts\Provider\AccountsDataProvider;
3232
use PrestaShop\Module\Mbo\Addons\Subscriber\ModuleManagementEventSubscriber;
3333
use PrestaShop\Module\Mbo\Helpers\Config;
34+
use PrestaShop\Module\Mbo\Helpers\EnvHelper;
3435
use PrestaShop\Module\Mbo\Helpers\ErrorHelper;
3536
use PrestaShop\PrestaShop\Core\Module\ModuleRepository;
3637
use PrestaShopBundle\Event\ModuleManagementEvent;
37-
use Symfony\Component\Dotenv\Dotenv;
3838

3939
class ps_mbo extends Module
4040
{
4141
use PrestaShop\Module\Mbo\Traits\HaveTabs;
4242
use PrestaShop\Module\Mbo\Traits\UseHooks;
4343
use PrestaShop\Module\Mbo\Traits\HaveConfigurationPage;
4444

45-
public const VERSION = '5.2.0';
45+
public const VERSION = '5.2.2';
4646

4747
public array $configurationList = [
4848
'PS_MBO_SHOP_ADMIN_UUID' => '', // 'ADMIN' because there will be only one for all shops in a multishop context
@@ -71,7 +71,7 @@ public function __construct()
7171
{
7272
$this->name = 'ps_mbo';
7373
// This value must be hard-coded to respect Addons rules, so we must make sure that the const value is always synced with this one
74-
$this->version = '5.2.0';
74+
$this->version = '5.2.2';
7575
$this->author = 'PrestaShop';
7676
$this->tab = 'administration';
7777
$this->module_key = '6cad5414354fbef755c7df4ef1ab74eb';
@@ -381,16 +381,6 @@ private function uninstallTables(): bool
381381
*/
382382
private function loadEnv(): void
383383
{
384-
$dotenv = new Dotenv();
385-
$dotenv->usePutenv();
386-
$dotenv->loadEnv(__DIR__ . '/.env');
387-
}
388-
389-
private function isPsAccountEnabled(): bool
390-
{
391-
/** @var PrestaShop\PsAccountsInstaller\Installer\Installer|null $accountsInstaller */
392-
$accountsInstaller = $this->get(PrestaShop\PsAccountsInstaller\Installer\Installer::class);
393-
394-
return null !== $accountsInstaller && $accountsInstaller->isModuleEnabled();
384+
EnvHelper::loadEnv(__DIR__ . '/.env');
395385
}
396386
}

src/Addons/Provider/AddonsDataProvider.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,22 @@ public function getAuthenticationParams(): array
242242
return $authParams;
243243
}
244244

245+
/**
246+
* Returns authentication parameters for Addons API requests
247+
* @return string|null
248+
*/
249+
public function getAuthenticationToken(): ?string
250+
{
251+
if ($this->isUserAuthenticated()) {
252+
$credentials = $this->user->getCredentials();
253+
if (null !== $credentials && array_key_exists('accounts_token', $credentials)) {
254+
return $credentials['accounts_token'];
255+
}
256+
}
257+
258+
return null;
259+
}
260+
245261
public function getAccountsShopUuid(): ?string
246262
{
247263
if (!$this->isUserAuthenticatedOnAccounts()) {

src/Addons/User/AddonsUser.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace PrestaShop\Module\Mbo\Addons\User;
2323

2424
use PrestaShop\Module\Mbo\Accounts\Provider\AccountsDataProvider;
25+
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
2526
use Symfony\Component\HttpFoundation\RequestStack;
2627

2728
if (!defined('_PS_VERSION_')) {
@@ -116,11 +117,15 @@ public function getAccountsShopUuid(): ?string
116117
}
117118

118119
/**
119-
* @return mixed
120+
* @return string|null
120121
*/
121-
private function getAccountsTokenFromSession()
122+
private function getAccountsTokenFromSession(): ?string
122123
{
123-
return $this->requestStack->getSession()->get('accounts_token');
124+
try {
125+
return $this->requestStack->getSession()->get('accounts_token');
126+
} catch (SessionNotFoundException $e) {
127+
return null;
128+
}
124129
}
125130

126131
/**
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
declare(strict_types=1);
21+
22+
namespace PrestaShop\Module\Mbo\Exception;
23+
24+
use Exception;
25+
26+
class FileOperationException extends Exception
27+
{
28+
}

src/Handler/ErrorHandler/ErrorHandler.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace PrestaShop\Module\Mbo\Handler\ErrorHandler;
2323

24+
use PrestaShop\Module\Mbo\Helpers\EnvHelper;
2425
use Sentry\Client;
2526
use Sentry\State\Scope;
2627
use Sentry\UserDataBag;
@@ -48,7 +49,7 @@ class ErrorHandler implements ErrorHandlerInterface
4849

4950
public function __construct()
5051
{
51-
$this->dsn = getenv('SENTRY_CREDENTIALS');
52+
$this->dsn = EnvHelper::getEnv('SENTRY_CREDENTIALS');
5253

5354
if (empty($this->dsn)) {
5455
return;
@@ -58,17 +59,17 @@ public function __construct()
5859
\Sentry\init([
5960
'dsn' => $this->dsn,
6061
'release' => \ps_mbo::VERSION,
61-
'environment' => getenv('SENTRY_ENVIRONMENT'),
62+
'environment' => EnvHelper::getEnv('SENTRY_ENVIRONMENT'),
6263
'traces_sample_rate' => 0.5,
6364
'sample_rate' => 0.5,
6465
]);
6566

6667
\Sentry\configureScope(function (Scope $scope): void {
6768
$scope->setContext('shop info', [
6869
'prestashop_version' => _PS_VERSION_,
69-
'mbo_cdc_url' => getenv('MBO_CDC_URL'),
70-
'distribution_api_url' => getenv('DISTRIBUTION_API_URL'),
71-
'addons_api_url' => getenv('ADDONS_API_URL'),
70+
'mbo_cdc_url' => EnvHelper::getEnv('MBO_CDC_URL'),
71+
'distribution_api_url' => EnvHelper::getEnv('DISTRIBUTION_API_URL'),
72+
'addons_api_url' => EnvHelper::getEnv('ADDONS_API_URL'),
7273
]);
7374
});
7475
} catch (\Throwable $e) {

0 commit comments

Comments
 (0)