Skip to content

Commit

Permalink
Merge pull request #9174 from michaelKaefer/core-foundation-version
Browse files Browse the repository at this point in the history
Added a service to manage PrestaShop versions (may deprecate _PS_VERSION_)
  • Loading branch information
mickaelandrieu committed Jun 18, 2018
2 parents e53d97f + aa4fe1a commit 79384e7
Show file tree
Hide file tree
Showing 20 changed files with 375 additions and 86 deletions.
6 changes: 6 additions & 0 deletions app/AppKernel.php
Expand Up @@ -32,6 +32,12 @@

class AppKernel extends Kernel
{
const VERSION = '1.7.4.0';
const MAJOR_VERSION_STRING = '1.7';
const MAJOR_VERSION = 17;
const MINOR_VERSION = 4;
const RELEASE_VERSION = 0;

/**
* @{inheritdoc}
*/
Expand Down
9 changes: 4 additions & 5 deletions config/autoload.php
Expand Up @@ -23,11 +23,10 @@
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
require_once __DIR__.'/../vendor/autoload.php';

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

require_once(_PS_CONFIG_DIR_.'alias.php');
require_once(_PS_CLASS_DIR_.'PrestaShopAutoload.php');
require_once _PS_CONFIG_DIR_.'alias.php';
require_once _PS_CLASS_DIR_.'PrestaShopAutoload.php';
spl_autoload_register(array(PrestaShopAutoload::getInstance(), 'load'));

require_once(__DIR__.'/../vendor/autoload.php');
3 changes: 2 additions & 1 deletion src/Adapter/Admin/PagePreference.php
Expand Up @@ -28,6 +28,7 @@
use PrestaShopBundle\Service\TransitionalBehavior\AdminPagePreferenceInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;
use AppKernel;
use Db;

/**
Expand Down Expand Up @@ -96,7 +97,7 @@ public function getTemporaryShouldAllowUseLegacyPage($page = null)
return false;
}
$installVersion = explode('.', $version);
$currentVersion = explode('.', _PS_VERSION_);
$currentVersion = explode('.', AppKernel::VERSION);

// Prod mode, depends on the page
switch ($page) {
Expand Down
7 changes: 4 additions & 3 deletions src/Adapter/Product/AdminProductDataProvider.php
Expand Up @@ -32,6 +32,7 @@
use PrestaShop\PrestaShop\Adapter\Validate;
use PrestaShopBundle\Entity\AdminFilter;
use PrestaShopBundle\Service\DataProvider\Admin\ProductInterface;
use AppKernel;
use Db;
use Context;
use Hook;
Expand Down Expand Up @@ -297,7 +298,7 @@ public function getCatalogProductList(

// exec legacy hook but with different parameters (retro-compat < 1.7 is broken here)
Hook::exec('actionAdminProductsListingFieldsModifier', array(
'_ps_version' => _PS_VERSION_,
'_ps_version' => AppKernel::VERSION,
'sql_select' => &$sqlSelect,
'sql_table' => &$sqlTable,
'sql_where' => &$sqlWhere,
Expand Down Expand Up @@ -328,7 +329,7 @@ public function getCatalogProductList(

// exec legacy hook but with different parameters (retro-compat < 1.7 is broken here)
Hook::exec('actionAdminProductsListingFieldsModifier', array(
'_ps_version' => _PS_VERSION_,
'_ps_version' => AppKernel::VERSION,
'sql_select' => &$sqlSelect,
'sql_table' => &$sqlTable,
'sql_where' => &$sqlWhere,
Expand Down Expand Up @@ -360,7 +361,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', array(
'_ps_version' => _PS_VERSION_,
'_ps_version' => AppKernel::VERSION,
'products' => &$products,
'total' => $total,
));
Expand Down
4 changes: 3 additions & 1 deletion src/Adapter/Requirement/CheckMissingOrUpdatedFiles.php
Expand Up @@ -26,6 +26,8 @@

namespace PrestaShop\PrestaShop\Adapter\Requirement;

use AppKernel;

/**
* Part of requirements for a PrestaShop website
* Check if all required files exists.
Expand All @@ -43,7 +45,7 @@ public function getListOfUpdatedFiles($dir = null, $path = '')
);

if (is_null($dir)) {
$xml = @simplexml_load_file(_PS_API_URL_.'/xml/md5/'._PS_VERSION_.'.xml');
$xml = @simplexml_load_file(_PS_API_URL_.'/xml/md5/'.AppKernel::VERSION.'.xml');
if (!$xml) {
return $fileList;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Shop/ShopInformation.php
Expand Up @@ -55,7 +55,7 @@ public function __construct(LegacyContext $legacyContext)
public function getShopInformation()
{
return array(
'version' => _PS_VERSION_,
'version' => AppKernel::VERSION,
'url' => $this->context->shop->getBaseURL(),
'theme' => $this->context->shop->theme->getName(),
);
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Addon/Module/ModuleManagerBuilder.php
Expand Up @@ -160,7 +160,8 @@ private function __construct()
self::$translator->getLocale(),
$this->getCountryIso(),
new Tools(),
(new Configuration())->get('_PS_BASE_URL_')
(new Configuration())->get('_PS_BASE_URL_'),
\AppKernel::VERSION
);

$marketPlaceClient->setSslVerification(_PS_CACHE_CA_CERT_FILE_);
Expand Down
60 changes: 60 additions & 0 deletions src/Core/Foundation/Version/Exception/InvalidVersionException.php
@@ -0,0 +1,60 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\PrestaShop\Core\Foundation\Version\Exception;

use Exception;

/**
* This exception will be thrown if an invalid Shop version name is used
* in the application.
*/
class InvalidVersionException extends Exception
{
/**
* Creates an exception for the invalid type.
*
* @return static The created exception.
*/
public static function mustBeAString()
{
return new static('A valid version must be a string.');
}

/**
* Creates an exception for the invalid version name.
*
* @param string $versionName The version name.
*
* @return static The created exception.
*/
public static function mustBeValidName($versionName)
{
return new static(sprintf(
'You provided an invalid version string ("%s"). A valid version string must contain four numeric characters divided by three "." characters, for example "1.7.4.0".',
$versionName
));
}
}

0 comments on commit 79384e7

Please sign in to comment.