From 9dda3101bb59da1d032b76eaf40989a535dde313 Mon Sep 17 00:00:00 2001
From: Andrew Berry <deviantintegral@gmail.com>
Date: Fri, 16 Sep 2011 15:53:40 -0400
Subject: [PATCH] Issue #1281556: Fix saving NULL video lengths for videos
 being processed.

---
 ooyala.module |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/ooyala.module b/ooyala.module
index ef7ef7e..b22bffc 100755
--- a/ooyala.module
+++ b/ooyala.module
@@ -353,7 +353,16 @@ function ooyala_field_sanitize($entity_type, $entity, $field, $instance, $langco
   module_load_include('inc', 'ooyala', 'includes/ooyala.api');
 
   foreach ($items as $delta => $item) {
-    $items[$delta]['length'] = empty($items[$delta]['length']) ? ooyala_api_video_property($item['value'], 'length') : $items[$delta]['length'];
+    // We might not have a length yet from Ooyala depending on the processing
+    // of the content. If Ooyala doesn't have a length, unset the value so
+    // Field API will save NULL to the database.
+    if (empty($items[$delta]['length'])) {
+      $length = ooyala_api_video_property($item['value'], 'length');
+      if ($length === FALSE) {
+        unset($items[$delta]['length']);
+      }
+    }
+
     $items[$delta]['status'] = empty($items[$delta]['status']) ? ooyala_api_video_property($item['value'], 'status') : $items[$delta]['status'];
 
     if (isset($item['thumbnail_list'])) {
-- 
1.7.6.1

