Bug #51236

Task #55953: Repair and streamline ValueObject support

ValueObject Identity generation broken in some cases

Added by Philipp Maier almost 2 years ago. Updated 6 months ago.

Status:Resolved Start date:2013-08-21
Priority:Must have Due date:
Assigned To:Philipp Maier % Done:

100%

Category:-
Target version:-
PHP Version: Complexity:
Has patch:No Affected Flow version:(any)

Description

Consider this example ValueObject with two attributes.

<?php
namespace Vendor\Package\Domain\Model;

use TYPO3\Flow\Annotations as Flow;

/**
 * @Flow\ValueObject
 */
class Test {

  /**
   * @var string
   */
  protected $prop1;

  /**
   * @var string
   */
  protected $prop2;

  /**
   * @param string $prop1
   * @param string $prop2
   */
  public function __construct($prop1, $prop2) {
    $this->prop1 = $prop1;
    $this->prop2 = $prop2;
  }

  // ...
}

$test1 = new Test('Name', '');
$test2 = new Test('', 'Name');

$test1 and $test2 will have the same Identity generated by the PersistenceMagicAspect::generateValueHash because the names of the attributes are not included in the hash.
Fixing this will probably break some stuff.

--
Please also regard https://review.typo3.org/#/c/11368/4 in that matter

Associated revisions

Revision 2d6a0dfd
Added by Philipp Maier 6 months ago

[!!!][BUGFIX] Generate Value Object hash from property values

This changes the Value Objects' hash generation algorithm to
use the actual properties of the Value Object, not only the
constructor arguments which lead to duplicate hashes in cases
where arguments were empty.

Furthermore the initial approach disregarded everything that
can be done within the constructor (such as trimming, calculations,
etc.).

This patch delays the generation of the value hash to just after
instantiation, where the Value Object is completely initialized.
The final object properties names and values are then hashed.

Additionally, the handling of DateTime objects has been improved.
The generated ValueHash now also includes information about the
timezone.

This might be breaking in the unlikely case where the initial
hash calculation leads to the same hash as the new calculation,
for different VOs. Besides, it might lead to duplicate VOs in the
database because the "same" VO can become a new hash due to the
changed hashing algorithm.

Change-Id: Iaf4d2a28bcd8fc5bf2c749f8021171456616e45c
Fixes: #51236
Fixes: #37357
Releases: master

History

#1 Updated by Gerrit Code Review almost 2 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23241

#2 Updated by Gerrit Code Review almost 2 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23241

#3 Updated by Gerrit Code Review almost 2 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23241

#4 Updated by Gerrit Code Review almost 2 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23241

#5 Updated by Gerrit Code Review almost 2 years ago

Patch set 5 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23241

#6 Updated by Gerrit Code Review almost 2 years ago

Patch set 6 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23241

#7 Updated by Adrian Föder over 1 year ago

  • Parent task set to #55953

#8 Updated by Gerrit Code Review over 1 year ago

Patch set 7 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/23241

#9 Updated by Gerrit Code Review 7 months ago

Patch set 8 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/23241

#10 Updated by Gerrit Code Review 7 months ago

Patch set 9 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/23241

#11 Updated by Gerrit Code Review 6 months ago

Patch set 10 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/23241

#12 Updated by Gerrit Code Review 6 months ago

Patch set 11 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/23241

#13 Updated by Gerrit Code Review 6 months ago

Patch set 12 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/23241

#14 Updated by Gerrit Code Review 6 months ago

Patch set 13 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at http://review.typo3.org/23241

#15 Updated by Philipp Maier 6 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF