From f57e95632cddf18530b1aefcc30ff8132d5a3d47 Mon Sep 17 00:00:00 2001
From: Alex Barth <alex_b@53995.no-reply.drupal.org>
Date: Mon, 29 Mar 2010 02:21:37 +0000
Subject: [PATCH] #736684 Souvent22, Mixologic: FeedsDateTime & Batch DateTime
 causes core dumps.

---
 CHANGELOG.txt           |  2 ++
 plugins/FeedsParser.inc | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index a9001bf3..b1b28d77 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -4,6 +4,8 @@
 Feeds 6.x 1.0 xxxxx xx, 2010-xx-xx
 ----------------------------------
 
+- #736684 Souvent22, Mixologic: FeedsDateTime & Batch DateTime causes core
+  dumps.
 - #750168 jtr: _parser_common_syndication_title does not strip html tags before
   constructing a title.
 - #648080 pvhee: FeedsNodeProcessor - static caching of mapping targets makes
diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc
index 49d04f22..17227542 100644
--- a/plugins/FeedsParser.inc
+++ b/plugins/FeedsParser.inc
@@ -346,6 +346,28 @@ class FeedsDateTimeElement extends FeedsElement {
 class FeedsDateTime extends DateTime {
   public $granularity = array();
   protected static $allgranularity = array('year', 'month', 'day', 'hour', 'minute', 'second', 'zone');
+  private $_serialized_time;
+  private $_serialized_timezone;
+
+  /**
+   * Helper function to prepare the object during serialization.
+   *
+   * We are extending a core class and core classes cannot be serialized.
+   *
+   * Ref: http://bugs.php.net/41334, http://bugs.php.net/39821
+   */
+  public function __sleep(){
+    $this->_serialized_time = $this->format('c');
+    $this->_serialized_timezone = $this->getTimezone()->getName();
+    return array('_serialized_time', '_serialized_timezone');
+  }
+
+  /**
+   * Upon unserializing, we must re-build ourselves using local variables.
+   */
+  public function __wakeup() {
+    $this->__construct($this->_serialized_time, new DateTimeZone($this->_serialized_timezone));
+  }
 
   /**
    * Overridden constructor.
-- 
GitLab