Skip to content

Commit

Permalink
Merge branch 'b-6.2.x' into b-6.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	.travis.yml
#	CHANGELOG.md
  • Loading branch information
godefroy-le-hardi committed Jan 24, 2020
2 parents 0173c3c + 7a55c00 commit ab65411
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 158 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ php:

matrix:
fast_finish: true
allow_failures:
- php: "7.3"
- php: "7.4"

# Numeric values of error reporting levels:
# 32767: E_ALL
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `OxidEsales\Eshop\Core\Config::$sConfigKey`
- `OxidEsales\Eshop\Core\Config::DEFAULT_CONFIG_KEY`
- `Conf`
- `OxidEsales\Eshop\Core\Registry\UserPayment::_insert()`
- `OxidEsales\EshopCommunity\Core\InputValidator::validatePaymentInputData()`
- `OxidEsales\EshopCommunity\Application\Controller\PaymentController::validatePayment()`
- `OxidEsales\Eshop\Core\Session::$_blStarted`

### Fixed
- Warnings in order discounts recalculation [PR-742](https://github.com/OXID-eSales/oxideshop_ce/pull/742)
- Require at least 3.4.26 DI component [PR-746](https://github.com/OXID-eSales/oxideshop_ce/pull/746)
- Fix return type annoation for `OxidEsales\EshopCommunity\Application\Model::load()` to `bool`
- Handle translated error message from validator in password change correctly [PR-731](https://github.com/OXID-eSales/oxideshop_ce/pull/731)

### Added
- Support PHP 7.3 and 7.4

## [6.5.0] - 2019-11-07

### Added
Expand Down
8 changes: 2 additions & 6 deletions source/Application/Component/UserComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,13 @@ public function login()
protected function _afterLogin($oUser)
{
$oSession = $this->getSession();

// generating new session id after login
if ($this->getLoginStatus() === USER_LOGIN_SUCCESS) {
if ($this->getLoginStatus() === USER_LOGIN_SUCCESS && $oSession->isSessionStarted()) {
$oSession->regenerateSessionId();
}

$myConfig = $this->getConfig();

// this user is blocked, deny him
if ($oUser->inGroup('oxidblocked')) {
$sUrl = $myConfig->getShopHomeUrl() . 'cl=content&tpl=user_blocked.tpl';
$sUrl = $this->getConfig()->getShopHomeUrl() . 'cl=content&tpl=user_blocked.tpl';
Registry::getUtils()->redirect($sUrl, true, 302);
}

Expand Down
6 changes: 3 additions & 3 deletions source/Core/Form/FormFieldsTrimmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ class FormFieldsTrimmer implements EshopFormFieldsTrimmerInterface
*
* @param EshopFormFields $fields to trim.
*
* @return array
* @return ArrayIterator
*/
public function trim(EshopFormFields $fields)
{
$updatableFields = $fields->getUpdatableFields();
$updatableFields = $fields->getUpdatableFields()->getArrayCopy();

array_walk_recursive($updatableFields, function (&$value) {
$value = $this->isTrimmableField($value) ? $this->trimField($value) : $value;
});

return $updatableFields;
return new \ArrayIterator($updatableFields);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions source/Core/Module/ModuleChainsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,9 @@ protected function createClassExtension($parentClass, $moduleClass)
return false;
}

if (!class_exists($moduleClass, false)) {
$moduleClassParentAlias = $moduleClass . "_parent";
if (!class_exists($moduleClassParentAlias, false)) {
class_alias($parentClass, $moduleClassParentAlias);
}
$moduleClassParentAlias = $moduleClass . "_parent";
if (!class_exists($moduleClassParentAlias, false)) {
class_alias($parentClass, $moduleClassParentAlias);
}

return true;
Expand Down
77 changes: 35 additions & 42 deletions source/Core/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class Session extends \OxidEsales\Eshop\Core\Base
/**
* Started session marker
*
* @deprecated since v6.5.1 (2020-01-24); Use Session::isSessionStarted() instead.
*
* @var bool
*/
protected $_blStarted = false;
Expand Down Expand Up @@ -215,23 +217,14 @@ protected function getSidFromRequest()
*/
public function start()
{
if ($this->isSessionStarted()) {
return;
}

$myConfig = $this->getConfig();

if ($this->isAdmin()) {
$this->setName("admin_sid");
} else {
$this->setName("sid");
}
$this->setName($this->isAdmin() ? 'admin_sid' : 'sid');

$sid = $this->getSidFromRequest();
if ($sid) {
$this->setId($sid);
}

//starting session if only we can
if ($this->_allowSessionStart()) {
//creating new sid
if ($this->isSessionStarted() === false && $this->_allowSessionStart()) {
if (!$sid) {
self::$_blIsNewSession = true;
$this->initNewSession();
Expand All @@ -242,16 +235,16 @@ public function start()
}

//special handling for new ZP cluster session, as in that case session_start() regenerates id
if ($this->_sId != session_id()) {
$this->_setSessionId(session_id());
if ($this->getId() !== session_id()) {
$this->setId(session_id());
}

//checking for swapped client
$blSwapped = $this->_isSwappedClient();
if (!self::$_blIsNewSession && $blSwapped) {
$this->initNewSession();

// passing notification about session problems
$myConfig = $this->getConfig();
if ($this->_sErrorMsg && $myConfig->getConfigParam('iDebug')) {
\OxidEsales\Eshop\Core\Registry::getUtilsView()->addErrorToDisplay(oxNew(\OxidEsales\Eshop\Core\Exception\StandardException::class, $this->_sErrorMsg));
}
Expand Down Expand Up @@ -316,7 +309,7 @@ protected function _initNewSessionChallenge()
*/
protected function _sessionStart()
{
if (!headers_sent() && (PHP_SESSION_NONE == session_status())) {
if (!headers_sent() && (PHP_SESSION_NONE === session_status())) {
if ($this->needToSetHeaders()) {
//enforcing no caching when session is started
session_cache_limiter('nocache');
Expand All @@ -336,7 +329,7 @@ protected function _sessionStart()
}

$config = \OxidEsales\Eshop\Core\Registry::getConfig();
$this->_blStarted = @session_start([
$this->_blStarted = session_start([
'use_cookies' => $config->getConfigParam('blSessionUseCookies')
]);
if (!$this->getSessionChallengeToken()) {
Expand All @@ -351,8 +344,7 @@ protected function _sessionStart()
*/
public function initNewSession()
{
// starting session only if it was not started yet
if (self::$_blIsNewSession) {
if (!$this->isSessionStarted()) {
$this->_sessionStart();
}

Expand All @@ -364,7 +356,9 @@ public function initNewSession()
}
}

$this->_setSessionId($this->_getNewSessionId());
$sessionId = $this->_getNewSessionId(false);
$this->setId($sessionId);
$this->setSessionCookie($sessionId);

//restoring persistent params to session
foreach ($aPersistent as $sKey => $sParam) {
Expand All @@ -382,15 +376,17 @@ public function initNewSession()
*/
public function regenerateSessionId()
{
// starting session only if it was not started yet
if (self::$_blIsNewSession) {
if (!$this->isSessionStarted()) {
$this->_sessionStart();

// (re)setting actual user agent when initiating new session
$this->setVariable("sessionagent", \OxidEsales\Eshop\Core\Registry::getUtilsServer()->getServerVar('HTTP_USER_AGENT'));
}

$this->_setSessionId($this->_getNewSessionId(false));
$sessionId = $this->_getNewSessionId(false);
$this->setId($sessionId);
$this->setSessionCookie($sessionId);

$this->_initNewSessionChallenge();
}

Expand All @@ -404,7 +400,7 @@ public function regenerateSessionId()
*/
protected function _getNewSessionId($blUnset = true)
{
@session_regenerate_id(true);
session_regenerate_id(true);

if ($blUnset) {
session_unset();
Expand Down Expand Up @@ -978,21 +974,7 @@ protected function _setSessionId($sSessId)
session_id($sSessId);

$this->setId($sSessId);

$blUseCookies = $this->_getSessionUseCookies();

if (!$this->_allowSessionStart()) {
if ($blUseCookies) {
\OxidEsales\Eshop\Core\Registry::getUtilsServer()->setOxCookie($this->getName(), null);
}

return;
}

if ($blUseCookies) {
//setting session cookie
\OxidEsales\Eshop\Core\Registry::getUtilsServer()->setOxCookie($this->getName(), $sSessId);
}
$this->setSessionCookie($sSessId);
}

/**
Expand Down Expand Up @@ -1120,7 +1102,7 @@ public function isHeaderSent()
*/
public function isSessionStarted()
{
return $this->_blStarted;
return session_status() === PHP_SESSION_ACTIVE;
}

/**
Expand Down Expand Up @@ -1149,4 +1131,15 @@ protected function needToSetHeaders()
protected function sidToUrlEvent()
{
}

private function setSessionCookie($sessionId): void
{
if($this->_getSessionUseCookies()) {
if (!$this->_allowSessionStart()) {
Registry::getUtilsServer()->setOxCookie($this->getName(), null);
} else {
Registry::getUtilsServer()->setOxCookie($this->getName(), $sessionId);
}
}
}
}
34 changes: 15 additions & 19 deletions source/Core/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,37 +494,33 @@ public function toFileCache($sKey, $mContents, $iTtl = 0)
public function fromFileCache($sKey)
{
if (!array_key_exists($sKey, $this->_aFileCacheContents)) {
$sRes = null;

$aMeta = $this->getCacheMeta($sKey);
$blInclude = isset($aMeta["include"]) ? $aMeta["include"] : false;
$sCachePath = isset($aMeta["cachepath"]) ? $aMeta["cachepath"] : $this->getCacheFilePath($sKey);

// trying to lock
$this->_lockFile($sCachePath, $sKey, LOCK_SH);

clearstatcache();
if (is_readable($sCachePath)) {
$this->_lockFile($sCachePath, $sKey, LOCK_SH);

$blInclude = isset($aMeta["include"]) ? $aMeta["include"] : false;
$sRes = $blInclude ? $this->_includeFile($sCachePath) : $this->_readFile($sCachePath);
}

if (isset($sRes['ttl']) && $sRes['ttl'] != 0) {
$iTimestamp = $sRes['timestamp'];
$iTtl = $sRes['ttl'];
if (isset($sRes['ttl']) && $sRes['ttl'] != 0) {
$iTimestamp = $sRes['timestamp'];
$iTtl = $sRes['ttl'];

$iTime = \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime();
if ($iTime > $iTimestamp + $iTtl) {
return null;
$iTime = \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime();
if ($iTime > $iTimestamp + $iTtl) {
return null;
}
}
}
// release lock
$this->_releaseFile($sKey, LOCK_SH);

// caching
$this->_aFileCacheContents[$sKey] = $sRes;
$this->_aFileCacheContents[$sKey] = $sRes;

$this->_releaseFile($sKey, LOCK_SH);
}
}

return $this->_aFileCacheContents[$sKey]['content'];
return isset($this->_aFileCacheContents[$sKey]) ? $this->_aFileCacheContents[$sKey]['content'] : null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion source/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function () {
$sessionResetErrorTypes = [E_ERROR];

$error = error_get_last();
if (in_array($error['type'], $handledErrorTypes)) {
if ($error !== null && in_array($error['type'], $handledErrorTypes)) {
$errorType = array_flip(array_slice(get_defined_constants(true)['Core'], 0, 16, true))[$error['type']];

$errorMessage = $error['message'];
Expand Down
2 changes: 0 additions & 2 deletions tests/Integration/Application/Component/UserComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,13 @@ public function testAfterLogin()

$oSession = $this->getMock(\OxidEsales\Eshop\Core\Session::class, array('getBasket', "regenerateSessionId"));
$oSession->expects($this->atLeastOnce())->method('getBasket')->will($this->returnValue($oBasket));
$oSession->expects($this->once())->method('regenerateSessionId');

$oUser = $this->getMock(\OxidEsales\Eshop\Application\Component\UserComponent::class, array('inGroup'));
$oUser->expects($this->once())->method('inGroup')->will($this->returnValue(false));

$aMockFnc = array('getSession', "getLoginStatus");
$oUserView = $this->getMock(\OxidEsales\Eshop\Application\Component\UserComponent::class, $aMockFnc);
$oUserView->expects($this->atLeastOnce())->method('getSession')->will($this->returnValue($oSession));
$oUserView->expects($this->atLeastOnce())->method('getLoginStatus')->will($this->returnValue(1));
$this->assertEquals('payment', $oUserView->UNITafterLogin($oUser));
}

Expand Down
Loading

0 comments on commit ab65411

Please sign in to comment.