Skip to content
Snippets Groups Projects

Resolve #3187004 "Drupaldatetime serialization issue"

3 unresolved threads

Closes #3187004

Merge request reports

Closed by Artem DmitriievArtem Dmitriiev 3 years ago (Oct 26, 2021 7:14am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
163 163 return $value;
164 164 }
165 165
166 /**
167 * Magic __sleep() method to avoid serializing formatTranslationCache.
  • 239 239 $this->assertEquals('America/New_York', $drupaldatetime->getTimezone()->getName());
    240 240 }
    241 241
    242 /**
    243 * Test to avoid serialization of formatTranslationCache
    244 */
    245 public function testSleep() {
  • 163 163 return $value;
    164 164 }
    165 165
    166 /**
    167 * Magic __sleep() method to avoid serializing formatTranslationCache.
    168 */
    169 public function __sleep() {
    170 return ['langcode', 'dateTimeObject'];
    • There is an implementation of __sleep method, but I don't see the one for __wakeup. Please consider using DependencySerializationTrait to make sure serialization is done properly.

      Once we have DependencySerializationTrait in place, we can override __sleep method and exclude problematic properties. If this property is formatTranslationCache, then it might look like this:

      public function __sleep() {
        return array_diff(parent::__sleep(), ['formatTranslationCache']);
      {
      Edited by Ivan Doroshenko
    • changed this line in version 5 of the diff

    • @Matroskeen, I've updated as per you suggestions. Can you please review this.

    • @mohit_rocks, it looks good, thanks!

      I have just one question: is it necessary to add aliases for the trait methods or we could just use parent::__sleep() or parent::__wakeup()? I noticed we have both patterns in core so I'm just wondering if this is a personal preference or there is some use-case when one variation works better than other.

    • Please register or sign in to reply
  • Mohit Aghera added 1 commit

    added 1 commit

    • 48277bc3 - Update serialization approach.

    Compare with previous version

  • Artem Dmitriiev changed target branch from 8.9.x to 9.3.x

    changed target branch from 8.9.x to 9.3.x

  • Artem Dmitriiev changed target branch from 9.3.x to 8.9.x

    changed target branch from 9.3.x to 8.9.x

  • Please register or sign in to reply
    Loading