Skip to content

Commit

Permalink
Merge pull request #624 from PrestaShopCorp/4.5.x
Browse files Browse the repository at this point in the history
v4.5.2
  • Loading branch information
intraordinaire authored Aug 31, 2023
2 parents 8a4f03b + 7144df1 commit bedb606
Show file tree
Hide file tree
Showing 22 changed files with 163 additions and 137 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_mbo</name>
<displayName><![CDATA[PrestaShop Marketplace in your Back Office]]></displayName>
<version><![CDATA[4.5.0]]></version>
<version><![CDATA[4.5.2]]></version>
<description><![CDATA[Discover the best PrestaShop modules to optimize your online store.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down
8 changes: 4 additions & 4 deletions ps_mbo.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ps_mbo extends Module
/**
* @var string
*/
public const VERSION = '4.5.0';
public const VERSION = '4.5.2';

public const CONTROLLERS_WITH_CONNECTION_TOOLBAR = [
'AdminPsMboModule',
Expand Down Expand Up @@ -104,7 +104,7 @@ class ps_mbo extends Module
public function __construct()
{
$this->name = 'ps_mbo';
$this->version = '4.5.0';
$this->version = '4.5.2';
$this->author = 'PrestaShop';
$this->tab = 'administration';
$this->module_key = '6cad5414354fbef755c7df4ef1ab74eb';
Expand Down Expand Up @@ -366,7 +366,7 @@ public function getAdminAuthenticationProvider(): AdminAuthenticationProvider
$this->container = SymfonyContainer::getInstance();
}

return $this->container->has('mbo.security.admin_authentication.provider') ?
return null !== $this->container && $this->container->has('mbo.security.admin_authentication.provider') ?
$this->get('mbo.security.admin_authentication.provider') :
new AdminAuthenticationProvider(
$this->get('doctrine.dbal.default_connection'),
Expand Down Expand Up @@ -440,7 +440,7 @@ public function postponeTabsTranslations(): void
$lockFile = $this->moduleCacheDir . 'translate_tabs.lock';
if (!file_exists($lockFile)) {
if (!is_dir($this->moduleCacheDir)) {
mkdir($this->moduleCacheDir);
mkdir($this->moduleCacheDir, 0777, true);
}
$f = fopen($lockFile, 'w+');
fclose($f);
Expand Down
1 change: 1 addition & 0 deletions src/Addons/Provider/LinksProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public function getCategoryLink(string $categoryName): string
$routeParams = [];
if ($category && 'other' !== mb_strtolower($categoryName)) {
$routeParams['filterCategoryRef'] = $category->refMenu;
$routeParams['mbo_cdc_path'] = '/#/modules';
}

return $this->router->generate('admin_mbo_catalog_module', $routeParams);
Expand Down
2 changes: 2 additions & 0 deletions src/Distribution/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use GuzzleHttp\Exception\GuzzleException;
use PrestaShop\Module\Mbo\Helpers\Config;
use ps_mbo;
use Symfony\Component\Routing\Router;

class BaseClient
{
Expand Down Expand Up @@ -61,6 +62,7 @@ class BaseClient
'iso_code',
'addons_username',
'addons_pwd',
'catalogUrl',
];
/**
* @var array<string, string>
Expand Down
18 changes: 18 additions & 0 deletions src/Distribution/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@
use GuzzleHttp\Exception\GuzzleException;
use PrestaShop\Module\Mbo\Helpers\Config;
use stdClass;
use Symfony\Component\Routing\Router;

class Client extends BaseClient
{
/**
* @var Router
*/
private $router;

public function setRouter(Router $router): self
{
$this->router = $router;

return $this;
}

/**
* Get a new key from Distribution API.
*
Expand Down Expand Up @@ -107,9 +120,14 @@ public function getEmployeeMenu()
return $this->cacheProvider->fetch($cacheKey);
}

$catalogUrlParams = [
'utm_mbo_source' => 'menu-user-back-office',
];

$this->setQueryParams([
'isoLang' => $languageIsoCode,
'shopVersion' => _PS_VERSION_,
'catalogUrl' => $this->router ? $this->router->generate('admin_mbo_catalog_module', $catalogUrlParams, Router::ABSOLUTE_PATH) : '#',
]);
try {
$conf = $this->processRequestAndDecode('shops/employee-menu');
Expand Down
4 changes: 3 additions & 1 deletion src/Distribution/ConnectedClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use GuzzleHttp\Client as HttpClient;
use PrestaShop\Module\Mbo\Addons\User\UserInterface;
use PrestaShop\Module\Mbo\Helpers\Config;
use Symfony\Component\Routing\Router;

class ConnectedClient extends BaseClient
{
Expand All @@ -36,7 +37,8 @@ class ConnectedClient extends BaseClient

/**
* @param HttpClient $httpClient
* @param \Doctrine\Common\Cache\CacheProvider $cacheProvider
* @param CacheProvider $cacheProvider
* @param UserInterface $user
*/
public function __construct(HttpClient $httpClient, CacheProvider $cacheProvider, UserInterface $user)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/HaveShopOnExternalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private function callServiceWithLockFile(string $method, array $params = []): vo
// Create the lock file
if (!file_exists($lockFile)) {
if (!is_dir($this->moduleCacheDir)) {
mkdir($this->moduleCacheDir);
mkdir($this->moduleCacheDir, 0777, true);
}
$f = fopen($lockFile, 'w+');
fclose($f);
Expand Down
8 changes: 8 additions & 0 deletions src/Traits/Hooks/UseActionBeforeUninstallModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PrestaShop\PrestaShop\Adapter\Module\ModuleDataProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\KernelEvents;

trait UseActionBeforeUninstallModule
{
Expand All @@ -45,6 +46,13 @@ public function hookActionBeforeUninstallModule(array $params): void

if ('ps_mbo' === $moduleName) {
$this->storeAddonsCredentials($params, 'uninstall');

// If MBO is uninstalled with sources deletion, we disable the AddonsCredentialsEncryptionListener
$deleteFiles = (bool) (\Tools::getValue('actionParams', [])['deletion'] ?? false);
if ($deleteFiles) {
$addonsEncryptionListener = $this->get('service_container')->get('mbo.addons.event_listener.addons_credentials_encryption_listener');
$this->get('event_dispatcher')->removeListener(KernelEvents::RESPONSE, [$addonsEncryptionListener, 'onKernelResponse']);
}
}
}
}
38 changes: 20 additions & 18 deletions src/Traits/Hooks/UseActionGetAlternativeSearchPanels.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace PrestaShop\Module\Mbo\Traits\Hooks;

use PrestaShop\PrestaShop\Core\Search\SearchPanel;
use Symfony\Component\Routing\Router;

trait UseActionGetAlternativeSearchPanels
{
Expand All @@ -36,29 +37,30 @@ trait UseActionGetAlternativeSearchPanels
*/
public function hookActionGetAlternativeSearchPanels(array $params): array
{
$searchedExpression = $params['bo_query'];

$version = defined('_PS_VERSION_') ? _PS_VERSION_ : '';
if ($lastDotIndex = strrpos($version, '.')) {
$trailingVersion = str_replace('.', '_', substr($version, 0, $lastDotIndex));
} else {
$trailingVersion = '';
try {
/** @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
$router = $this->get('router');
} catch (\Exception $e) {
return '';
}

$queryParams = [
'search_query' => $searchedExpression,
'utm_source' => 'back-office',
'utm_medium' => 'search',
'utm_campaign' => 'back-office-' . $this->context->language->iso_code,
'utm_content' => 'download' . $trailingVersion,
];
$catalogUrl = $router->generate('admin_mbo_catalog_module', [], Router::ABSOLUTE_PATH);
$catalogUrlPath = parse_url($catalogUrl, PHP_URL_PATH);
parse_str(parse_url($catalogUrl, PHP_URL_QUERY), $catalogUrlParams);

$searchedExpression = $params['bo_query'];
if (!empty(trim($searchedExpression))) {
$catalogUrlParams['keyword'] = trim($searchedExpression);
}
$catalogUrlParams['utm_mbo_source'] = 'search-back-office';
$catalogUrlParams['mbo_cdc_path'] = '/#/modules';

$searchPanels = [];
$searchPanels[] = new SearchPanel(
$this->trans('Search addons.prestashop.com', [], 'Modules.Mbo.Search'),
$this->trans('Go to Addons', [], 'Modules.Mbo.Search'),
'https://addons.prestashop.com/search.php',
$queryParams
$this->trans('Find modules to grow your business', [], 'Modules.Mbo.Search'),
$this->trans('Explore PrestaShop Marketplace', [], 'Modules.Mbo.Search'),
$catalogUrlPath,
$catalogUrlParams
);

return $searchPanels;
Expand Down
17 changes: 16 additions & 1 deletion src/Traits/Hooks/UseActionObjectEmployeeUpdateBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace PrestaShop\Module\Mbo\Traits\Hooks;

use PrestaShop\Module\Mbo\Helpers\Config;

trait UseActionObjectEmployeeUpdateBefore
{
/**
Expand All @@ -31,7 +33,7 @@ public function hookActionObjectEmployeeUpdateBefore($params): void
if (empty($params) || empty($params['object']) || !$params['object'] instanceof \Employee) {
return;
}
$currentApiUser = $this->getAdminAuthenticationProvider()->getApiUser();
$currentApiUser = $this->getApiUser();
if (!$currentApiUser) {
return;
}
Expand All @@ -44,4 +46,17 @@ public function hookActionObjectEmployeeUpdateBefore($params): void
$params['object']->active = true;
}
}

private function getApiUser()
{
$apiUserId = \Db::getInstance()->getValue(
'SELECT `id_employee` FROM `' . _DB_PREFIX_ . 'employee` WHERE `email` = "' . pSQL(Config::getShopMboAdminMail()) . '" AND active = 1'
);

if (!$apiUserId) {
return null;
}

return new \Employee((int) $apiUserId);
}
}
10 changes: 9 additions & 1 deletion src/Traits/Hooks/UseDisplayBackOfficeEmployeeMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ public function hookDisplayBackOfficeEmployeeMenu(array $params): void
}

try {
$config = $apiClient->getEmployeeMenu();
/** @var \Symfony\Component\Routing\Router $router */
$router = $this->get('router');
} catch (\Exception $e) {
return;
}

try {
$config = $apiClient->setRouter($router)->getEmployeeMenu();
if (empty($config) || empty($config->userMenu) || !is_array($config->userMenu)) {
return;
}
Expand All @@ -67,6 +74,7 @@ public function hookDisplayBackOfficeEmployeeMenu(array $params): void
[
'link' => $link->link,
'icon' => $link->icon,
'samePage' => $link->same_page ?? false,
],
$link->name
)
Expand Down
16 changes: 8 additions & 8 deletions translations/de-DE/ModulesMboSearch.de-DE.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="src/Traits/Hooks/UseActionGetAlternativeSearchPanels.php" source-language="en" target-language="de" datatype="plaintext">
<body>
<trans-unit id="9d6f008f9c1e0446e23b253ecc7b311a" approved="yes">
<source>Search addons.prestashop.com</source>
<target state="final">Durchsuche addons.prestashop.com</target>
<note>Line: 58</note>
<trans-unit id="c15784789b60bab84ad3108dacfb3f18">
<source>Find modules to grow your business</source>
<target state="translated">Finden Sie Module, mit denen Sie Ihr Geschäft ausbauen können</target>
<note>Line: 60</note>
</trans-unit>
<trans-unit id="a68b46728e83ba2fd535a25e8216bdb7" approved="yes">
<source>Go to Addons</source>
<target state="final">Zu Addons wechseln</target>
<note>Line: 59</note>
<trans-unit id="66f434c53b61009046c615cea9273d61">
<source>Explore PrestaShop Marketplace</source>
<target state="translated">Entdecken Sie PrestaShop Marketplace</target>
<note>Line: 61</note>
</trans-unit>
</body>
</file>
Expand Down
16 changes: 8 additions & 8 deletions translations/en-US/ModulesMboSearch.en-US.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="src/Traits/Hooks/UseActionGetAlternativeSearchPanels.php" source-language="en-US" target-language="en-US" datatype="plaintext">
<body>
<trans-unit id="9d6f008f9c1e0446e23b253ecc7b311a">
<source>Search addons.prestashop.com</source>
<target>Search addons.prestashop.com</target>
<note>Line: 58</note>
<trans-unit id="c15784789b60bab84ad3108dacfb3f18">
<source>Find modules to grow your business</source>
<target>Find modules to grow your business</target>
<note>Line: 60</note>
</trans-unit>
<trans-unit id="a68b46728e83ba2fd535a25e8216bdb7">
<source>Go to Addons</source>
<target>Go to Addons</target>
<note>Line: 59</note>
<trans-unit id="66f434c53b61009046c615cea9273d61">
<source>Explore PrestaShop Marketplace</source>
<target>Explore PrestaShop Marketplace</target>
<note>Line: 61</note>
</trans-unit>
</body>
</file>
Expand Down
30 changes: 0 additions & 30 deletions translations/en-US/index.php

This file was deleted.

16 changes: 8 additions & 8 deletions translations/es-ES/ModulesMboSearch.es-ES.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="src/Traits/Hooks/UseActionGetAlternativeSearchPanels.php" source-language="en" target-language="es-ES" datatype="plaintext">
<body>
<trans-unit id="9d6f008f9c1e0446e23b253ecc7b311a" approved="yes">
<source>Search addons.prestashop.com</source>
<target state="final">Buscar addons.prestashop.com</target>
<note>Line: 58</note>
<trans-unit id="c15784789b60bab84ad3108dacfb3f18">
<source>Find modules to grow your business</source>
<target state="translated">Encuentre módulos para hacer crecer su negocio</target>
<note>Line: 60</note>
</trans-unit>
<trans-unit id="a68b46728e83ba2fd535a25e8216bdb7" approved="yes">
<source>Go to Addons</source>
<target state="final">Ir a Addons</target>
<note>Line: 59</note>
<trans-unit id="66f434c53b61009046c615cea9273d61">
<source>Explore PrestaShop Marketplace</source>
<target state="translated">Explorar PrestaShop Marketplace</target>
<note>Line: 61</note>
</trans-unit>
</body>
</file>
Expand Down
16 changes: 8 additions & 8 deletions translations/fr-FR/ModulesMboSearch.fr-FR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file original="src/Traits/Hooks/UseActionGetAlternativeSearchPanels.php" source-language="en" target-language="fr" datatype="plaintext">
<body>
<trans-unit id="9d6f008f9c1e0446e23b253ecc7b311a" approved="yes">
<source>Search addons.prestashop.com</source>
<target state="final">Rechercher sur addons.prestashop.com</target>
<note>Line: 58</note>
<trans-unit id="c15784789b60bab84ad3108dacfb3f18">
<source>Find modules to grow your business</source>
<target state="translated">Trouvez des modules pour développer votre entreprise</target>
<note>Line: 60</note>
</trans-unit>
<trans-unit id="a68b46728e83ba2fd535a25e8216bdb7" approved="yes">
<source>Go to Addons</source>
<target state="final">Rendez-vous sur Addons</target>
<note>Line: 59</note>
<trans-unit id="66f434c53b61009046c615cea9273d61">
<source>Explore PrestaShop Marketplace</source>
<target state="translated">Explorer la PrestaShop Marketplace</target>
<note>Line: 61</note>
</trans-unit>
</body>
</file>
Expand Down
Loading

0 comments on commit bedb606

Please sign in to comment.