Skip to content

Commit

Permalink
Merge pull request PrestaShop#29750 from FabienPapet/add-prestashop-v…
Browse files Browse the repository at this point in the history
…ersion

Replace AppKernel version constants by prestashop versions
  • Loading branch information
jolelievre authored Oct 27, 2022
2 parents ae7dcc5 + 8632cf0 commit bf2bf60
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 30 deletions.
14 changes: 8 additions & 6 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@

use PrestaShop\PrestaShop\Adapter\Module\Repository\ModuleRepository;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Version;
use PrestaShop\TranslationToolsBundle\TranslationToolsBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
const VERSION = '8.0.0';
const MAJOR_VERSION_STRING = '8';
const MAJOR_VERSION = 8;
const MINOR_VERSION = 0;
const RELEASE_VERSION = 0;
const VERSION = Version::VERSION;
const MAJOR_VERSION_STRING = Version::MAJOR_VERSION_STRING;
const MAJOR_VERSION = Version::MAJOR_VERSION;
const MINOR_VERSION = Version::MINOR_VERSION;
const RELEASE_VERSION = Version::RELEASE_VERSION;

/**
* {@inheritdoc}
Expand All @@ -54,7 +56,7 @@ public function registerBundles()
// PrestaShop Core bundle
new PrestaShopBundle\PrestaShopBundle(),
// PrestaShop Translation parser
new PrestaShop\TranslationToolsBundle\TranslationToolsBundle(),
new TranslationToolsBundle(),
new League\Tactician\Bundle\TacticianBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
);
Expand Down
2 changes: 1 addition & 1 deletion app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:

framework:
assets:
version: !php/const \AppKernel::VERSION
version: !php/const PrestaShop\PrestaShop\Core\Version::VERSION

# esi: ~
secret: "%secret%"
Expand Down
5 changes: 4 additions & 1 deletion config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

use PrestaShop\PrestaShop\Core\Version;

require_once __DIR__.'/../vendor/autoload.php';

define('_PS_VERSION_', AppKernel::VERSION);
define('_PS_VERSION_', Version::VERSION);

require_once _PS_CONFIG_DIR_.'alias.php';
require_once _PS_CLASS_DIR_.'PrestaShopAutoload.php';
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Admin/PagePreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

namespace PrestaShop\PrestaShop\Adapter\Admin;

use AppKernel;
use Db;
use PrestaShop\PrestaShop\Core\Version;
use PrestaShopBundle\Service\TransitionalBehavior\AdminPagePreferenceInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
Expand Down Expand Up @@ -108,7 +108,7 @@ public function getTemporaryShouldAllowUseLegacyPage($page = null)
return false;
}
$installVersion = explode('.', $version);
$currentVersion = explode('.', AppKernel::VERSION);
$currentVersion = explode('.', Version::VERSION);

// Prod mode, depends on the page
switch ($page) {
Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/Hook/HookDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
use PrestaShop\PrestaShop\Core\Hook\HookInterface;
use PrestaShop\PrestaShop\Core\Hook\RenderedHook;
use PrestaShop\PrestaShop\Core\Version;
use PrestaShopBundle\Service\Hook\HookEvent;
use PrestaShopBundle\Service\Hook\RenderingHookEvent;
use Symfony\Component\EventDispatcher\Event;
Expand Down Expand Up @@ -224,7 +225,7 @@ public function dispatchRenderingWithParameters($hookName, array $hookParameters
*/
private function getHookEventContextParameters(): array
{
$globalParameters = ['_ps_version' => \AppKernel::VERSION];
$globalParameters = ['_ps_version' => Version::VERSION];

if (null === $this->requestStack) {
return $globalParameters;
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/Product/AdminProductDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace PrestaShop\PrestaShop\Adapter\Product;

use AppKernel;
use Configuration;
use Context;
use Currency;
Expand All @@ -37,6 +36,7 @@
use PrestaShop\PrestaShop\Adapter\Admin\AbstractAdminQueryBuilder;
use PrestaShop\PrestaShop\Adapter\ImageManager;
use PrestaShop\PrestaShop\Adapter\Validate;
use PrestaShop\PrestaShop\Core\Version;
use PrestaShopBundle\Entity\AdminFilter;
use PrestaShopBundle\Service\DataProvider\Admin\ProductInterface;
use Product;
Expand Down Expand Up @@ -339,7 +339,7 @@ public function getCatalogProductList(

// exec legacy hook but with different parameters (retro-compat < 1.7 is broken here)
Hook::exec('actionAdminProductsListingFieldsModifier', [
'_ps_version' => AppKernel::VERSION,
'_ps_version' => Version::VERSION,
'sql_select' => &$sqlSelect,
'sql_table' => &$sqlTable,
'sql_where' => &$sqlWhere,
Expand Down Expand Up @@ -394,7 +394,7 @@ public function getCatalogProductList(
// post treatment by hooks
// exec legacy hook but with different parameters (retro-compat < 1.7 is broken here)
Hook::exec('actionAdminProductsListingResultsModifier', [
'_ps_version' => AppKernel::VERSION,
'_ps_version' => Version::VERSION,
'products' => &$products,
'total' => $total,
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Requirement/CheckMissingOrUpdatedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace PrestaShop\PrestaShop\Adapter\Requirement;

use AppKernel;
use PrestaShop\PrestaShop\Core\Version;

/**
* Part of requirements for a PrestaShop website
Expand All @@ -48,7 +48,7 @@ public function getListOfUpdatedFiles($dir = null, $path = '')
];

if (null === $dir) {
$xml = @simplexml_load_file(_PS_API_URL_ . '/xml/md5-' . AppKernel::MAJOR_VERSION . '/' . AppKernel::VERSION . '.xml');
$xml = @simplexml_load_file(_PS_API_URL_ . '/xml/md5-' . Version::MAJOR_VERSION . '/' . Version::VERSION . '.xml');
if (!$xml) {
return $fileList;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Shop/ShopInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

namespace PrestaShop\PrestaShop\Adapter\Shop;

use AppKernel;
use PrestaShop\PrestaShop\Adapter\LegacyContext;
use PrestaShop\PrestaShop\Core\Version;
use Tools;

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ public function __construct(LegacyContext $legacyContext)
public function getShopInformation()
{
return [
'version' => AppKernel::VERSION,
'version' => Version::VERSION,
'url' => $this->context->shop->getBaseURL(),
'path' => _PS_ROOT_DIR_,
'theme' => $this->context->shop->theme->getName(),
Expand Down
21 changes: 21 additions & 0 deletions src/Core/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace PrestaShop\PrestaShop\Core;

/**
* This class contains the current prestashop version constants.
* This will be updated everytime we release a new version.
*/
final class Version
{
public const VERSION = '8.0.0';
public const MAJOR_VERSION_STRING = '8';
public const MAJOR_VERSION = 8;
public const MINOR_VERSION = 0;
public const RELEASE_VERSION = 0;

// This class should not be instanciated
private function __construct()
{
}
}
6 changes: 3 additions & 3 deletions src/PrestaShopBundle/Install/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace PrestaShopBundle\Install;

use AppKernel;
use Language as LanguageLegacy;
use PhpEncryption;
use PrestaShop\PrestaShop\Adapter\Entity\Cache;
Expand Down Expand Up @@ -58,6 +57,7 @@
use PrestaShop\PrestaShop\Core\Addon\Theme\ThemeManagerBuilder;
use PrestaShop\PrestaShop\Core\Module\ConfigReader as ModuleConfigReader;
use PrestaShop\PrestaShop\Core\Theme\ConfigReader as ThemeConfigReader;
use PrestaShop\PrestaShop\Core\Version;
use PrestaShopBundle\Cache\LocalizationWarmer;
use PrestaShopBundle\Service\Database\Upgrade as UpgradeDatabase;
use PrestaShopException;
Expand Down Expand Up @@ -432,7 +432,7 @@ public function installDefaultData($shop_name, $iso_country = false, $all_langua
if (!$all_languages) {
$iso_codes_to_install = [$this->language->getLanguageIso()];
if ($iso_country) {
$version = str_replace('.', '', AppKernel::VERSION);
$version = str_replace('.', '', Version::VERSION);
$version = substr($version, 0, 2);
$localization_file_content = $this->getLocalizationPackContent($version, $iso_country);

Expand Down Expand Up @@ -836,7 +836,7 @@ public function configureShop(array $data = [])
Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'country SET active = 0 WHERE id_country != ' . (int) $id_country);

// Set localization configuration
$version = str_replace('.', '', AppKernel::VERSION);
$version = str_replace('.', '', Version::VERSION);
$version = substr($version, 0, 2);
$localization_file_content = $this->getLocalizationPackContent($version, $data['shop_country']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
prestashop.core.foundation.version:
class: PrestaShop\PrestaShop\Core\Foundation\Version
arguments:
- !php/const AppKernel::VERSION
- !php/const AppKernel::MAJOR_VERSION_STRING
- !php/const AppKernel::MAJOR_VERSION
- !php/const AppKernel::MINOR_VERSION
- !php/const AppKernel::RELEASE_VERSION
- !php/const PrestaShop\PrestaShop\Core\Version::VERSION
- !php/const PrestaShop\PrestaShop\Core\Version::MAJOR_VERSION_STRING
- !php/const PrestaShop\PrestaShop\Core\Version::MAJOR_VERSION
- !php/const PrestaShop\PrestaShop\Core\Version::MINOR_VERSION
- !php/const PrestaShop\PrestaShop\Core\Version::RELEASE_VERSION
8 changes: 4 additions & 4 deletions tests/Resources/DatabaseDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

namespace Tests\Resources;

use AppKernel;
use Cache;
use Db;
use Exception;
use PrestaShop\PrestaShop\Core\Version;
use Tools;

class DatabaseDump
Expand Down Expand Up @@ -111,7 +111,7 @@ private function __construct($dumpFile = null)

$this->databaseName = _DB_NAME_;
if ($dumpFile === null) {
$this->dumpFile = sprintf('%s/ps_dump_%s_%s.sql', sys_get_temp_dir(), $this->databaseName, AppKernel::VERSION);
$this->dumpFile = sprintf('%s/ps_dump_%s_%s.sql', sys_get_temp_dir(), $this->databaseName, Version::VERSION);
} else {
$this->dumpFile = $dumpFile;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ private function getTableDumpPath(string $table): string
'%s/ps_dump_%s_%s_%s.sql',
sys_get_temp_dir(),
$this->databaseName,
AppKernel::VERSION,
Version::VERSION,
$table
);
}
Expand All @@ -259,7 +259,7 @@ private function getTableChecksumPath(string $table): string
'%s/ps_dump_%s_%s_%s.md5',
sys_get_temp_dir(),
$this->databaseName,
AppKernel::VERSION,
Version::VERSION,
$table
);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Unit/PrestaShopBundle/AppKernelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tests\Unit\PrestaShopBundle;

use PHPUnit\Framework\TestCase;
use PrestaShop\PrestaShop\Core\Version;

class AppKernelTest extends TestCase
{
public function testVersion(): void
{
self::assertSame(\AppKernel::VERSION, Version::VERSION);
}
}

0 comments on commit bf2bf60

Please sign in to comment.