Skip to content

Commit

Permalink
Merge branch '2017.12' into 2018.09
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Mar 11, 2019
2 parents 75a854b + 177bbb8 commit b14a7da
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 41 deletions.
1 change: 1 addition & 0 deletions autoload/ezp_kernel.php
Expand Up @@ -486,6 +486,7 @@
'eZTextTool' => 'lib/ezutils/classes/eztexttool.php', 'eZTextTool' => 'lib/ezutils/classes/eztexttool.php',
'eZTextType' => 'kernel/classes/datatypes/eztext/eztexttype.php', 'eZTextType' => 'kernel/classes/datatypes/eztext/eztexttype.php',
'eZTime' => 'lib/ezlocale/classes/eztime.php', 'eZTime' => 'lib/ezlocale/classes/eztime.php',
'eZTimestamp' => 'lib/ezutils/classes/eztimestamp.php',
'eZTimeType' => 'kernel/classes/datatypes/eztime/eztimetype.php', 'eZTimeType' => 'kernel/classes/datatypes/eztime/eztimetype.php',
'eZTipafriendCounter' => 'kernel/classes/eztipafriendcounter.php', 'eZTipafriendCounter' => 'kernel/classes/eztipafriendcounter.php',
'eZTipafriendRequest' => 'kernel/classes/eztipafriendrequest.php', 'eZTipafriendRequest' => 'kernel/classes/eztipafriendrequest.php',
Expand Down
20 changes: 15 additions & 5 deletions kernel/classes/datatypes/ezdate/ezdatetype.php
Expand Up @@ -110,7 +110,7 @@ function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{ {
$date = new eZDate(); $date = new eZDate();
$date->setMDY( $month, $day, $year ); $date->setMDY( $month, $day, $year );
$stamp = $date->timeStamp(); $stamp = eZTimestamp::getUtcTimestampFromLocalTimestamp( $date->timeStamp() );
} }


$contentObjectAttribute->setAttribute( 'data_int', $stamp ); $contentObjectAttribute->setAttribute( 'data_int', $stamp );
Expand Down Expand Up @@ -175,7 +175,7 @@ function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $
{ {
$date = new eZDate(); $date = new eZDate();
$date->setMDY( $month, $day, $year ); $date->setMDY( $month, $day, $year );
$stamp = $date->timeStamp(); $stamp = eZTimestamp::getUtcTimestampFromLocalTimestamp( $date->timeStamp() );
} }


$collectionAttribute->setAttribute( 'data_int', $stamp ); $collectionAttribute->setAttribute( 'data_int', $stamp );
Expand All @@ -191,7 +191,9 @@ function objectAttributeContent( $contentObjectAttribute )
{ {
$date = new eZDate( ); $date = new eZDate( );
$stamp = $contentObjectAttribute->attribute( 'data_int' ); $stamp = $contentObjectAttribute->attribute( 'data_int' );
$date->setTimeStamp( $stamp ); $date->setTimeStamp(
eZTimestamp::getLocalTimestampFromUtcTimestamp( $stamp )
);
return $date; return $date;
} }


Expand Down Expand Up @@ -344,7 +346,13 @@ function serializeContentObjectAttribute( $package, $objectAttribute )
{ {
$dom = $node->ownerDocument; $dom = $node->ownerDocument;
$dateNode = $dom->createElement( 'date' ); $dateNode = $dom->createElement( 'date' );
$dateNode->appendChild( $dom->createTextNode( eZDateUtils::rfc1123Date( $stamp ) ) ); $dateNode->appendChild(
$dom->createTextNode(
eZDateUtils::rfc1123Date(
eZTimestamp::getLocalTimestampFromUtcTimestamp( $stamp )
)
)
);
$node->appendChild( $dateNode ); $node->appendChild( $dateNode );
} }
return $node; return $node;
Expand All @@ -355,7 +363,9 @@ function unserializeContentObjectAttribute( $package, $objectAttribute, $attribu
$dateNode = $attributeNode->getElementsByTagName( 'date' )->item( 0 ); $dateNode = $attributeNode->getElementsByTagName( 'date' )->item( 0 );
if ( is_object( $dateNode ) ) if ( is_object( $dateNode ) )
{ {
$timestamp = eZDateUtils::textToDate( $dateNode->textContent ); $timestamp = eZTimestamp::getUtcTimestampFromLocalTimestamp(
eZDateUtils::textToDate( $dateNode->textContent )
);
$objectAttribute->setAttribute( 'data_int', $timestamp ); $objectAttribute->setAttribute( 'data_int', $timestamp );
} }
} }
Expand Down
18 changes: 16 additions & 2 deletions kernel/classes/datatypes/ezuser/ezuser.php
Expand Up @@ -225,15 +225,24 @@ static function create( $contentObjectID )
return new eZUser( $row ); return new eZUser( $row );
} }


function store( $fieldFilters = null ) /**
* Only stores the entry if it has a Login value
*
* @param mixed|null $fieldFilters
*/
public function store( $fieldFilters = null )
{ {
$this->Email = trim( $this->Email ); $this->Email = trim( $this->Email );
$userID = $this->attribute( 'contentobject_id' ); $userID = $this->attribute( 'contentobject_id' );
// Clear memory cache // Clear memory cache
unset( $GLOBALS['eZUserObject_' . $userID] ); unset( $GLOBALS['eZUserObject_' . $userID] );
$GLOBALS['eZUserObject_' . $userID] = $this; $GLOBALS['eZUserObject_' . $userID] = $this;
self::purgeUserCacheByUserId( $userID ); self::purgeUserCacheByUserId( $userID );
parent::store( $fieldFilters );
if ( $this->Login )
{
parent::store( $fieldFilters );
}
} }


function originalPassword() function originalPassword()
Expand Down Expand Up @@ -307,6 +316,11 @@ function setInformation( $id, $login, $email, $password, $passwordConfirm = fals
} }
} }


/**
* @param integer $id
* @param bool $asObject
* @return eZUser|null
*/
static function fetch( $id, $asObject = true ) static function fetch( $id, $asObject = true )
{ {
if ( !$id ) if ( !$id )
Expand Down
37 changes: 27 additions & 10 deletions kernel/classes/datatypes/ezuser/ezusertype.php
Expand Up @@ -258,10 +258,22 @@ function storeObjectAttribute( $contentObjectAttribute )
} }


// saving information in the object attribute data_text field to simulate a draft // saving information in the object attribute data_text field to simulate a draft
$contentObjectAttribute->setAttribute( 'data_text', $this->serializeDraft( $user ) ); // only if the object version is a draft
if (
$user->Login &&
$contentObjectAttribute->attribute( 'object_version' )->attribute( 'status' ) == eZContentObjectVersion::STATUS_DRAFT
)
{
$contentObjectAttribute->setAttribute( 'data_text', $this->serializeDraft( $user ) );
}
} }
} }


/**
* @param $contentObjectAttribute
* @param eZContentObject $contentObject
* @param $publishedNodes
*/
function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes ) function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes )
{ {
/** @var eZContentObjectAttribute $contentObjectAttribute */ /** @var eZContentObjectAttribute $contentObjectAttribute */
Expand All @@ -274,10 +286,13 @@ function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes )
if ( !empty( $serializedDraft ) ) if ( !empty( $serializedDraft ) )
{ {
$user = $this->updateUserDraft( $user, $serializedDraft ); $user = $this->updateUserDraft( $user, $serializedDraft );
} $user->store();
$contentObjectAttribute->setContent( $user );


$user->store(); // Clear draft info
$contentObjectAttribute->setContent( $user ); $contentObjectAttribute->setAttribute( 'data_text', '' );
$contentObjectAttribute->store();
}
} }


/** /**
Expand Down Expand Up @@ -320,10 +335,13 @@ private function updateUserDraft( eZUser $user, $serializedDraft )
{ {
$draft = $this->unserializeDraft( $serializedDraft ); $draft = $this->unserializeDraft( $serializedDraft );


$user->setAttribute( 'login', $draft->login ); if ( $draft )
$user->setAttribute( 'password_hash', $draft->password_hash ); {
$user->setAttribute( 'email', $draft->email ); $user->setAttribute( 'login', $draft->login );
$user->setAttribute( 'password_hash_type', $draft->password_hash_type ); $user->setAttribute( 'password_hash', $draft->password_hash );
$user->setAttribute( 'email', $draft->email );
$user->setAttribute( 'password_hash_type', $draft->password_hash_type );
}


return $user; return $user;
} }
Expand Down Expand Up @@ -360,11 +378,10 @@ function objectAttributeContent( $contentObjectAttribute )
$GLOBALS['eZUserObject_' . $userID] = eZUser::fetch( $userID ); $GLOBALS['eZUserObject_' . $userID] = eZUser::fetch( $userID );
} }


/** @var eZUser $user */
$user = eZUser::fetch( $userID ); $user = eZUser::fetch( $userID );
eZDebugSetting::writeDebug( 'kernel-user', $user, 'user' ); eZDebugSetting::writeDebug( 'kernel-user', $user, 'user' );


// Looking for a "draft" and loading it's content //Looking for a "draft" and loading its content
$serializedDraft = $contentObjectAttribute->attribute( 'data_text' ); $serializedDraft = $contentObjectAttribute->attribute( 'data_text' );


if ( !empty( $serializedDraft ) ) if ( !empty( $serializedDraft ) )
Expand Down
41 changes: 41 additions & 0 deletions lib/ezutils/classes/eztimestamp.php
@@ -0,0 +1,41 @@
<?php
/**
* File containing the eZTimestamp class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
* @package lib
*/

class eZTimestamp
{
/*!
\return a timestamp in UTC
*/
public static function getUtcTimestampFromLocalTimestamp( $localTimestamp ) {
$utcTimezone = new \DateTimeZone( 'UTC' );
$localTimezone = new \DateTimeZone( date_default_timezone_get() );

$localDate = new \DateTime( null, $localTimezone );
$localDate->setTimestamp( $localTimestamp );
$utcDate = new \DateTime( $localDate->format( 'Y-m-d H:i:s' ), $utcTimezone );

return $utcDate->getTimestamp();
}

/*!
\return a timestamp in timezone defined in php.ini
*/
public static function getLocalTimestampFromUtcTimestamp( $utcTimestamp ) {
$utcTimezone = new \DateTimeZone( 'UTC' );
$localTimezone = new \DateTimeZone( date_default_timezone_get() );

$utcDate = new \DateTime( null, $utcTimezone );
$utcDate->setTimestamp( $utcTimestamp );
$localDate = new \DateTime( $utcDate->format( 'Y-m-d H:i:s' ), $localTimezone );

return $localDate->getTimestamp();
}
}
?>
38 changes: 14 additions & 24 deletions tests/tests/kernel/datatypes/ezuser/ezusertype_regression.php
Expand Up @@ -38,11 +38,16 @@ public function setUp()
'parent_node_id' => $ini->variable( 'UserSettings', 'DefaultUserPlacement' ), 'parent_node_id' => $ini->variable( 'UserSettings', 'DefaultUserPlacement' ),
'attributes' => array( 'attributes' => array(
'first_name' => 'foo', 'first_name' => 'foo',
'last_name' => 'bar' ), 'last_name' => 'bar',
'user_account' => "{$this->userLogin}|{$this->userEmail}|1234|md5_password|0",
),
); );


$contentObject = eZContentFunctions::createAndPublishObject( $params ); $contentObject = eZContentFunctions::createAndPublishObject( $params );


// Re-fetch to get the object after it was published
$contentObject = eZContentObject::fetch( $contentObject->ID );

if( !$contentObject instanceof eZContentObject ) if( !$contentObject instanceof eZContentObject )
{ {
die( 'Impossible to create user object' ); die( 'Impossible to create user object' );
Expand Down Expand Up @@ -110,8 +115,9 @@ public function testFromStringHandlesDisabledAccount()
$userAccount = $dataMap['user_account']->fromString( $userAccount = $dataMap['user_account']->fromString(
join( '|', array( $tmpLogin, $tmpEmail, self::USER_PASSWORD_HASH, self::USER_PASSWORD_HASH_ID, 0 ) ) join( '|', array( $tmpLogin, $tmpEmail, self::USER_PASSWORD_HASH, self::USER_PASSWORD_HASH_ID, 0 ) )
); );
$userAccount->store();


$dataMap['user_account']->setContent( $userAccount );
$dataMap['user_account']->store();


$tempObject = eZContentObject::fetch( $this->userObject->attribute( 'id' ) ); $tempObject = eZContentObject::fetch( $this->userObject->attribute( 'id' ) );
$dataMap = $tempObject->dataMap(); $dataMap = $tempObject->dataMap();
Expand Down Expand Up @@ -151,8 +157,9 @@ public function testFromStringHandlesEnabledAccount()
$userAccount = $dataMap['user_account']->fromString( $userAccount = $dataMap['user_account']->fromString(
join( '|', array( $tmpLogin, $tmpEmail, self::USER_PASSWORD_HASH, self::USER_PASSWORD_HASH_ID, 1 ) ) join( '|', array( $tmpLogin, $tmpEmail, self::USER_PASSWORD_HASH, self::USER_PASSWORD_HASH_ID, 1 ) )
); );
$userAccount->store();


$dataMap['user_account']->setContent( $userAccount );
$dataMap['user_account']->store();


$tempObject = eZContentObject::fetch( $this->userObject->attribute( 'id' ) ); $tempObject = eZContentObject::fetch( $this->userObject->attribute( 'id' ) );
$dataMap = $tempObject->dataMap(); $dataMap = $tempObject->dataMap();
Expand Down Expand Up @@ -188,11 +195,13 @@ public function testUpdatePasswordUpdatesSerializedData()
{ {
$userId = $this->userObject->attribute('id'); $userId = $this->userObject->attribute('id');


$passwordHash = $this->getSerializedPasswordHash($this->userObject); $user = ezuser::fetch( $userId );
$passwordHash = $user->PasswordHash;


eZUserOperationCollection::password($userId, 'newpassword'); eZUserOperationCollection::password($userId, 'newpassword');


$updatedPasswordHash = $this->getSerializedPasswordHash( eZContentObject::fetch($userId) ); $user = ezuser::fetch( $userId );
$updatedPasswordHash = $user->PasswordHash;


self::assertNotEquals( self::assertNotEquals(
$passwordHash, $passwordHash,
Expand All @@ -201,25 +210,6 @@ public function testUpdatePasswordUpdatesSerializedData()
); );
} }


/**
* @param \eZContentObject $userObject
*
* @return string The serialized password hash, or null if none is set
*/
private function getSerializedPasswordHash(eZContentObject $userObject)
{
$dataMap = $userObject->dataMap();

$userAccountAttributeText = $dataMap['user_account']->attribute('data_text');

// empty on initial version
if (!empty($userAccountAttributeText)) {
return json_decode($userAccountAttributeText)->password_hash;
}

return null;
}

/** /**
* Enables the current user * Enables the current user
*/ */
Expand Down

0 comments on commit b14a7da

Please sign in to comment.