From ae9da6006d0d818543eef39f7bebd36752941a1c Mon Sep 17 00:00:00 2001 From: yossipapi Date: Sun, 5 Jan 2014 18:32:44 +0200 Subject: [PATCH 01/11] KalturaFrontController - save the serialized multirequest results PLAT-527 --- api_v3/lib/KalturaFrontController.php | 136 ++++++++++++++--------- api_v3/lib/KalturaJsonProcSerializer.php | 35 ++++++ api_v3/lib/KalturaJsonSerializer.php | 30 +++++ api_v3/lib/KalturaPhpSerializer.php | 30 +++++ api_v3/lib/KalturaSerializer.php | 10 +- api_v3/lib/KalturaXmlSerializer.php | 37 ++++++ 6 files changed, 222 insertions(+), 56 deletions(-) diff --git a/api_v3/lib/KalturaFrontController.php b/api_v3/lib/KalturaFrontController.php index f7e15d42304..9f00ea528de 100644 --- a/api_v3/lib/KalturaFrontController.php +++ b/api_v3/lib/KalturaFrontController.php @@ -13,6 +13,8 @@ class KalturaFrontController private $service = ""; private $action = ""; private $disptacher = null; + private $format; + private $serializer; private function KalturaFrontController() { @@ -88,6 +90,14 @@ public function run() set_error_handler(array(&$this, "errorHandler")); KalturaLog::debug("Params [" . print_r($this->params, true) . "]"); + + if (isset($_REQUEST["ignoreNull"])) + $ignoreNull = ($_REQUEST["ignoreNull"] === "1") ? true : false; + else + $ignoreNull = false; + + $this->setSerializerByFormat($ignoreNull); + if ($this->service == "multirequest") { set_exception_handler(null); @@ -110,11 +120,6 @@ public function run() } $this->onRequestEnd($success, $errorCode); } - - if (isset($_REQUEST["ignoreNull"])) - $ignoreNull = ($_REQUEST["ignoreNull"] === "1") ? true : false; - else - $ignoreNull = false; ob_end_clean(); @@ -128,6 +133,8 @@ public function handleMultiRequest() // arrange the parameters by request index $commonParams = array(); $listOfRequests = array(); + $dependencies = array(); + $pastResults = array(); foreach ($this->params as $paramName => $paramValue) { $explodedName = explode(':', $paramName, 2); @@ -144,6 +151,16 @@ public function handleMultiRequest() $listOfRequests[$requestIndex] = array(); } $listOfRequests[$requestIndex][$paramName] = $paramValue; + + $matches = array(); + if (preg_match('/\{([0-9]*)\:result\:?(.*)?\}/', $paramValue, $matches)) + { + $pastResultsIndex = $matches[0]; + $resultIndex = $matches[1]; + $resultKey = $matches[2]; + if(!isset($dependencies[$requestIndex][pastResultsIndex])) + $dependencies[$resultIndex][pastResultsIndex] = $resultKey; + } } // process the requests @@ -173,7 +190,7 @@ public function handleMultiRequest() { $currentParams['partnerId'] = $commonParams['partnerId']; } - + // check if we need to replace params with prev results foreach($currentParams as $key => &$val) { @@ -186,17 +203,12 @@ public function handleMultiRequest() // {1:result:playlistContent} if (preg_match('/\{([0-9]*)\:result\:?(.*)?\}/', $val, $matches)) { + $pastResultsIndex = $matches[0]; $resultIndex = $matches[1]; - $resultKey = $matches[2]; if (count($results) >= $resultIndex) // if the result index is valid { - if (strlen(trim($resultKey)) > 0) - $resultPathArray = explode(":",$resultKey); - else - $resultPathArray = array(); - - $val = $this->getValueFromObject($results[$resultIndex], $resultPathArray); + $val = $pastResults[$pastResultsIndex]; } } } @@ -238,8 +250,22 @@ public function handleMultiRequest() $cache->storeCache($currentResult, "", true); } $this->onRequestEnd($success, $errorCode, $i); + + if(isset($dependencies[$i])) + { + foreach($dependencies[$i] as $currentDependency => $dependencyName) + { + if (strlen(trim($dependencyName)) > 0) + $resultPathArray = explode(":",$dependencyName); + else + $resultPathArray = array(); + + $currValue = $this->getValueFromObject($currentResult, $resultPathArray); + $pastResults[$currentDependency] = $currValue; + } + } - $results[$i] = $currentResult; + $results[$i] = $this->serializer->serialize($currentResult); // in case a serve action is included in a multirequest, return only the result of the serve action // in order to avoid serializing the kRendererBase object and returning the internal server paths to the client @@ -411,21 +437,13 @@ public function adjustApiCacheForException($ex) } } - public function serializeResponse($object, $ignoreNull = false) + public function setSerializerByFormat($ignoreNull = false) { - if ($object instanceof kRendererBase) - { - return $object; - } - - $start = microtime(true); - KalturaLog::debug("Serialize start"); - // Determine the output format (or default to XML) - $format = isset($this->params["format"]) ? $this->params["format"] : KalturaResponseType::RESPONSE_TYPE_XML; + $this->format = isset($this->params["format"]) ? $this->params["format"] : KalturaResponseType::RESPONSE_TYPE_XML; // Create a serializer according to the given format - switch($format) + switch($this->format) { case KalturaResponseType::RESPONSE_TYPE_XML: $serializer = new KalturaXmlSerializer($ignoreNull); @@ -444,11 +462,24 @@ public function serializeResponse($object, $ignoreNull = false) break; default: - $serializer = KalturaPluginManager::loadObject('KalturaSerializer', $format); + $serializer = KalturaPluginManager::loadObject('KalturaSerializer', $this->format); break; } + + $this->serializer = $serializer; + } + + public function serializeResponse($object) + { + if ($object instanceof kRendererBase) + { + return $object; + } + + $start = microtime(true); + KalturaLog::debug("Serialize start"); - if ( ! empty( $serializer ) ) // Got a serializer for the given format? + if ( ! empty( $this->serializer ) ) // Got a serializer for the given format? { // Set HTTP headers if(isset($this->params['content-type'])) @@ -457,41 +488,36 @@ public function serializeResponse($object, $ignoreNull = false) } else { - $serializer->setHttpHeaders(); + $$this->serializer->setHttpHeaders(); } - // Serialize the object - $serializedObject = $serializer->serialize($object); + // Check if this is multi request if yes than object are already serialized so we will skip otherwise serialize the object + if ($this->service != "multirequest") + $serializedObject = $this->serializer->serialize($object); + else + $serializedObject = $this->handleSerializedObjectArray($object); // Post processing (handle special cases) - switch($format) - { - case KalturaResponseType::RESPONSE_TYPE_XML: - $result = - '' . - '' . - '' . - $serializedObject . - '' . - '' . ($this->end - $this->start) . '' . - ''; - break; - - case KalturaResponseType::RESPONSE_TYPE_JSONP: - $callback = isset($_GET["callback"]) ? $_GET["callback"] : null; - if (is_null($callback)) - die("Expecting \"callback\" parameter for jsonp format"); - $response = array(); - $result = $callback . "(" . $serializedObject . ");"; - break; - - default: - $result = $serializedObject; - break; - } + $result = $this->serializer->getHeader() . $serializedObject . $this->serializer->getFooter($this->end - $this->start); } KalturaLog::debug("Serialize took - " . (microtime(true) - $start)); return $result; } + + public function handleSerializedObjectArray($objects) + { + $objectsCount = count($objects); + $serializedObject = ''; + $serializedObject .= $this->serializer->getMulitRequestHeader($objectsCount); + for($i = 0 ; $i < $objectsCount; $i++) + { + $serializedObject .= $this->serializer->getItemHeader($i); + $serializedObject .= $objects[$i]; + $serializedObject .= $this->serializer->getItemFooter(); + } + $serializedObject .= $this->serializer->getMulitRequestFooter(); + + return $serializedObject; + } } diff --git a/api_v3/lib/KalturaJsonProcSerializer.php b/api_v3/lib/KalturaJsonProcSerializer.php index 5a83a9dba91..17fd44dd33b 100644 --- a/api_v3/lib/KalturaJsonProcSerializer.php +++ b/api_v3/lib/KalturaJsonProcSerializer.php @@ -9,4 +9,39 @@ public function setHttpHeaders() { header("Content-Type: application/javascript"); } + + public function getHeader() + { + $callback = isset($_GET["callback"]) ? $_GET["callback"] : null; + if (is_null($callback)) + die("Expecting \"callback\" parameter for jsonp format"); + $response = array(); + + return $callback . "("; + } + + public function getFooter($execTime = null) + { + return ");"; + } + + public function getItemHeader($itemIndex = null) + { + return ''; + } + + public function getItemFooter() + { + return ','; + } + + public function getMulitRequestHeader($itemsCount = null) + { + return '['; + } + + public function getMulitRequestFooter() + { + return ']'; + } } diff --git a/api_v3/lib/KalturaJsonSerializer.php b/api_v3/lib/KalturaJsonSerializer.php index 694cecbd591..abc841618ff 100644 --- a/api_v3/lib/KalturaJsonSerializer.php +++ b/api_v3/lib/KalturaJsonSerializer.php @@ -15,4 +15,34 @@ function serialize($object) $object = parent::prepareSerializedObject($object); return json_encode($object); } + + public function getHeader() + { + return ''; + } + + public function getFooter($execTime = null) + { + return ''; + } + + public function getItemHeader($itemIndex = null) + { + return ''; + } + + public function getItemFooter() + { + return ','; + } + + public function getMulitRequestHeader($itemsCount = null) + { + return '['; + } + + public function getMulitRequestFooter() + { + return ']'; + } } diff --git a/api_v3/lib/KalturaPhpSerializer.php b/api_v3/lib/KalturaPhpSerializer.php index acb2370633c..0d0ad2ae577 100644 --- a/api_v3/lib/KalturaPhpSerializer.php +++ b/api_v3/lib/KalturaPhpSerializer.php @@ -11,4 +11,34 @@ function serialize($object) $result = serialize($object); // Let PHP's built-in serialize() function do the work return $result; } + + public function getHeader() + { + return ''; + } + + public function getFooter($execTime = null) + { + return ''; + } + + public function getItemHeader($itemIndex = null) + { + return 'i:' .$itemIndex . ';'; + } + + public function getItemFooter() + { + return ''; + } + + public function getMulitRequestHeader($itemsCount = null) + { + return 'a:' . $itemsCount . ':{'; + } + + public function getMulitRequestFooter() + { + return '}'; + } } diff --git a/api_v3/lib/KalturaSerializer.php b/api_v3/lib/KalturaSerializer.php index fda2544455f..97ec92c7e00 100644 --- a/api_v3/lib/KalturaSerializer.php +++ b/api_v3/lib/KalturaSerializer.php @@ -15,7 +15,15 @@ protected function prepareSerializedObject($object) public function setHttpHeaders() {} - public function serialize($object) { return ''; } + abstract public function serialize($object); + + public function getHeader() { return '';} + public function getMulitRequestHeader($itemsCount = null) { return '';} + public function getItemHeader($itemIndex = null) { return '';} + + public function getFooter($execTime = null) { return '';} + public function getMulitRequestFooter() { return '';} + public function getItemFooter() { return '';} protected function convertExceptionsToPhpArrays($object) { diff --git a/api_v3/lib/KalturaXmlSerializer.php b/api_v3/lib/KalturaXmlSerializer.php index e2dc3a5ab83..d349cf44814 100644 --- a/api_v3/lib/KalturaXmlSerializer.php +++ b/api_v3/lib/KalturaXmlSerializer.php @@ -168,4 +168,41 @@ function writeTag($tag, $value) echo $value; echo ''; } + + public function getHeader() + { + return '' . + '' . + '' ; + } + + public function getFooter($execTime = null) + { + if(is_null($execTime)) + $execTime = 0; + + return '' . + '' . $execTime . '' . + ''; + } + + public function getItemHeader($itemIndex = null) + { + return ''; + } + + public function getItemFooter() + { + return ''; + } + + public function getMulitRequestHeader($itemsCount = null) + { + return ''; + } + + public function getMulitRequestFooter() + { + return ''; + } } From 0d254a1b187e95b99f1b75d815be90c112f57e2c Mon Sep 17 00:00:00 2001 From: yossipapi Date: Sun, 5 Jan 2014 20:50:05 +0200 Subject: [PATCH 02/11] Avoid putting item footers for last item if type is JSON or JSONP --- api_v3/lib/KalturaFrontController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api_v3/lib/KalturaFrontController.php b/api_v3/lib/KalturaFrontController.php index 9f00ea528de..8afe57eb007 100644 --- a/api_v3/lib/KalturaFrontController.php +++ b/api_v3/lib/KalturaFrontController.php @@ -514,7 +514,9 @@ public function handleSerializedObjectArray($objects) { $serializedObject .= $this->serializer->getItemHeader($i); $serializedObject .= $objects[$i]; - $serializedObject .= $this->serializer->getItemFooter(); + //check if item is the last one to avoid putting footer chars in json and jsonp serializers + if($i+1 != $objectsCount || ($this->format != KalturaResponseType::RESPONSE_TYPE_JSONP && $this->format != KalturaResponseType::RESPONSE_TYPE_JSON)) + $serializedObject .= $this->serializer->getItemFooter(); } $serializedObject .= $this->serializer->getMulitRequestFooter(); From d3f3952d7b09df581d9912ca0b65ad708efbe839 Mon Sep 17 00:00:00 2001 From: "eran.kornblau" Date: Wed, 15 Jan 2014 14:17:40 +0200 Subject: [PATCH 03/11] enable the client to choose the playManifest response format + support jsonp format --- .../kaltura/lib/cache/kPlayManifestCacher.php | 2 ++ alpha/apps/kaltura/lib/kManifestRenderers.php | 35 +++++++++++++++++++ .../actions/playManifestAction.class.php | 27 +++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/alpha/apps/kaltura/lib/cache/kPlayManifestCacher.php b/alpha/apps/kaltura/lib/cache/kPlayManifestCacher.php index 2620d0ca378..d1c89f73e6f 100644 --- a/alpha/apps/kaltura/lib/cache/kPlayManifestCacher.php +++ b/alpha/apps/kaltura/lib/cache/kPlayManifestCacher.php @@ -25,6 +25,8 @@ protected function init() if (!parent::init()) return false; + unset($this->_params['callback']); + $this->_playbackContext = isset($this->_params['playbackContext']) ? $this->_params['playbackContext'] : null; unset($this->_params['playbackContext']); diff --git a/alpha/apps/kaltura/lib/kManifestRenderers.php b/alpha/apps/kaltura/lib/kManifestRenderers.php index 3946ef664eb..0a37f070767 100644 --- a/alpha/apps/kaltura/lib/kManifestRenderers.php +++ b/alpha/apps/kaltura/lib/kManifestRenderers.php @@ -219,6 +219,7 @@ protected function tokenizeUrls() } $this->flavor['url'] = self::urlJoin($this->flavor['urlPrefix'], $url); + unset($this->flavor['urlPrefix']); // no longer need the prefix } } @@ -266,6 +267,7 @@ protected function tokenizeUrls() $url = $this->tokenizer->tokenizeSingleUrl($url); } $flavor['url'] = self::urlJoin($flavor['urlPrefix'], $url); + unset($flavor['urlPrefix']); // no longer need the prefix } } } @@ -612,3 +614,36 @@ protected function getHeaders() return array("location:{$url}"); } } + +class kJSONPManifestRenderer extends kMultiFlavorManifestRenderer +{ + /** + * @return array + */ + protected function getHeaders() + { + return array( + header("Content-Type: application/javascript"), + ); + } + + + /* (non-PHPdoc) + * @see kManifestRenderer::getManifestFlavors() + */ + protected function getManifestFlavors() + { + $callback = isset($_GET["callback"]) ? $_GET["callback"] : null; + if (is_null($callback)) + die("Expecting \"callback\" parameter for jsonp format"); + + $result = array( + 'entryId' => $this->entryId, + 'duration' => $this->duration, + 'baseUrl' => $this->baseUrl, + 'flavors' => $this->flavors, + ); + + return array($callback . '(' . json_encode($result) . ')'); + } +} diff --git a/alpha/apps/kaltura/modules/extwidget/actions/playManifestAction.class.php b/alpha/apps/kaltura/modules/extwidget/actions/playManifestAction.class.php index 5545108abd0..7af439ce1e8 100644 --- a/alpha/apps/kaltura/modules/extwidget/actions/playManifestAction.class.php +++ b/alpha/apps/kaltura/modules/extwidget/actions/playManifestAction.class.php @@ -58,6 +58,11 @@ class playManifestAction extends kalturaAction * @var string */ private $format; + + /** + * @var string + */ + private $responseFormat; /** * may contain several fallbacks options, each one with a set of tags @@ -1138,7 +1143,25 @@ private function buildRtmpLiveStreamFlavorsArray() private function getRenderer($defaultClass, $flavors) { - $class = $this->urlManager->getRendererClass(); + $class = null; + if ($this->responseFormat) + { + $formatMapping = array( + 'f4m' => 'kF4MManifestRenderer', + 'f4mv2' => 'kF4Mv2ManifestRenderer', + 'smil' => 'kSmilManifestRenderer', + 'm3u8' => 'kM3U8ManifestRenderer', + 'jsonp' => 'kJSONPManifestRenderer', + 'redirect' => 'kRedirectManifestRenderer', + ); + + if (isset($formatMapping[$this->responseFormat])) + $class = $formatMapping[$this->responseFormat]; + } + + if (!$class) + $class = $this->urlManager->getRendererClass(); + if (!$class) $class = $defaultClass; @@ -1515,6 +1538,8 @@ public function execute() $this->storageId = $this->getRequestParameter ( "storageId", null ); $this->cdnHost = $this->getRequestParameter ( "cdnHost", null ); + + $this->responseFormat = $this->getRequestParameter ( "responseFormat", null ); // Initialize $this->initEntry(); From 9526ab82ef53e99ed86bfb32b0d72016ce248db7 Mon Sep 17 00:00:00 2001 From: yossipapi Date: Wed, 15 Jan 2014 15:10:08 +0200 Subject: [PATCH 04/11] MultiRequest changes after testing --- api_v3/lib/KalturaFrontController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/api_v3/lib/KalturaFrontController.php b/api_v3/lib/KalturaFrontController.php index 8afe57eb007..7617c429c02 100644 --- a/api_v3/lib/KalturaFrontController.php +++ b/api_v3/lib/KalturaFrontController.php @@ -158,8 +158,8 @@ public function handleMultiRequest() $pastResultsIndex = $matches[0]; $resultIndex = $matches[1]; $resultKey = $matches[2]; - if(!isset($dependencies[$requestIndex][pastResultsIndex])) - $dependencies[$resultIndex][pastResultsIndex] = $resultKey; + if(!isset($dependencies[$requestIndex][$pastResultsIndex])) + $dependencies[$resultIndex][$pastResultsIndex] = $resultKey; } } @@ -488,7 +488,7 @@ public function serializeResponse($object) } else { - $$this->serializer->setHttpHeaders(); + $this->serializer->setHttpHeaders(); } // Check if this is multi request if yes than object are already serialized so we will skip otherwise serialize the object @@ -510,12 +510,12 @@ public function handleSerializedObjectArray($objects) $objectsCount = count($objects); $serializedObject = ''; $serializedObject .= $this->serializer->getMulitRequestHeader($objectsCount); - for($i = 0 ; $i < $objectsCount; $i++) + for($i = 1 ; $i <= $objectsCount; $i++) { - $serializedObject .= $this->serializer->getItemHeader($i); + $serializedObject .= $this->serializer->getItemHeader($i-1); $serializedObject .= $objects[$i]; //check if item is the last one to avoid putting footer chars in json and jsonp serializers - if($i+1 != $objectsCount || ($this->format != KalturaResponseType::RESPONSE_TYPE_JSONP && $this->format != KalturaResponseType::RESPONSE_TYPE_JSON)) + if($i != $objectsCount || ($this->format != KalturaResponseType::RESPONSE_TYPE_JSONP && $this->format != KalturaResponseType::RESPONSE_TYPE_JSON)) $serializedObject .= $this->serializer->getItemFooter(); } $serializedObject .= $this->serializer->getMulitRequestFooter(); From 0f16f9d687cf15ec938992e2b71895d967882398 Mon Sep 17 00:00:00 2001 From: "eran.kornblau" Date: Wed, 15 Jan 2014 19:30:53 +0200 Subject: [PATCH 05/11] use streamer type RTMP by default for live streams that have a stream name --- alpha/apps/kaltura/lib/kContextDataHelper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/alpha/apps/kaltura/lib/kContextDataHelper.php b/alpha/apps/kaltura/lib/kContextDataHelper.php index 646e2f40838..94df61dbdfe 100644 --- a/alpha/apps/kaltura/lib/kContextDataHelper.php +++ b/alpha/apps/kaltura/lib/kContextDataHelper.php @@ -302,6 +302,9 @@ private function setContextDataStreamerTypeAndMediaProtocol(accessControlScope $ $protocols[] = PlaybackProtocol::AKAMAI_HDS; $protocols[] = PlaybackProtocol::HDS; + + if ($this->entry->getStreamName()) + $this->streamerType = PlaybackProtocol::RTMP; foreach ($protocols as $protocol) { From eae85003a8cac1b07c76a0e48026084f87cdf561 Mon Sep 17 00:00:00 2001 From: sharonadar Date: Thu, 16 Jan 2014 18:25:32 +0200 Subject: [PATCH 06/11] Backward fix of the clients. --- generator/Php53ClientGenerator.php | 4 ++-- generator/PhpZendClientGenerator.php | 7 ++++--- generator/sources/php53/library/Kaltura/Client/Base.php | 2 ++ generator/sources/zend/Kaltura/Client/ClientBase.php | 3 +++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/generator/Php53ClientGenerator.php b/generator/Php53ClientGenerator.php index 494bd9de231..74cfabc96f6 100644 --- a/generator/Php53ClientGenerator.php +++ b/generator/Php53ClientGenerator.php @@ -493,7 +493,7 @@ function writeClass(DOMElement $classNode) default : // sub object $this->appendLine(" if(!empty(\$xml->{$propName}))"); - $this->appendLine(" \$this->$propName = \Kaltura\Client\ParseUtils::unmarshalObject(\$xml->$propName, $propType);"); + $this->appendLine(" \$this->$propName = \Kaltura\Client\ParseUtils::unmarshalObject(\$xml->$propName, \"{$propType}\");"); break; } } @@ -744,7 +744,7 @@ function writeAction($serviceId, $serviceName, DOMElement $actionNode, $plugin = { $resultTypeClassInfo = $this->getTypeClassInfo($resultType); $resultObjectTypeEscaped = str_replace("\\", "\\\\", $resultTypeClassInfo->getFullyQualifiedName()); - $this->appendLine(" \$resultObject = \\Kaltura\\Client\\ParseUtils::unmarshalObject(\$resultXmlObject->result, \"$resultType\");"); + $this->appendLine(" \$resultObject = \\Kaltura\\Client\\ParseUtils::unmarshalObject(\$resultXmlObject->result, \"{$resultType}\");"); $this->appendLine(" \$this->client->validateObjectType(\$resultObject, \"{$resultObjectTypeEscaped}\");"); } } diff --git a/generator/PhpZendClientGenerator.php b/generator/PhpZendClientGenerator.php index bf6d2d405c0..a094e0bc62e 100644 --- a/generator/PhpZendClientGenerator.php +++ b/generator/PhpZendClientGenerator.php @@ -427,8 +427,9 @@ function writeClass(DOMElement $classNode) break; default : // sub object + $fallback = $propertyNode->getAttribute("type"); $this->appendLine(" if(!empty(\$xml->{$propName}))"); - $this->appendLine(" \$this->$propName = Kaltura_Client_ParseUtils::unmarshalObject(\$xml->$propName, $propType);"); + $this->appendLine(" \$this->$propName = Kaltura_Client_ParseUtils::unmarshalObject(\$xml->$propName, \"$fallback\");"); break; } @@ -646,8 +647,8 @@ function writeAction($serviceId, $serviceName, DOMElement $actionNode, $plugin = default: if ($resultType) { - $resultType = $this->getTypeClass($resultType); $this->appendLine(" \$resultObject = Kaltura_Client_ParseUtils::unmarshalObject(\$resultXmlObject->result, \"$resultType\");"); + $resultType = $this->getTypeClass($resultType); $this->appendLine(" \$this->client->validateObjectType(\$resultObject, \"$resultType\");"); } } @@ -791,4 +792,4 @@ protected function addFile($fileName, $fileContents, $addLicense = true) $fileContents = preg_replace($patterns, $replacements, $fileContents); parent::addFile($fileName, $fileContents, $addLicense); } -} +} \ No newline at end of file diff --git a/generator/sources/php53/library/Kaltura/Client/Base.php b/generator/sources/php53/library/Kaltura/Client/Base.php index 8f567021c0a..c879c2bf7a1 100644 --- a/generator/sources/php53/library/Kaltura/Client/Base.php +++ b/generator/sources/php53/library/Kaltura/Client/Base.php @@ -479,6 +479,8 @@ public function startMultiRequest() public function doMultiRequest() { $xmlData = $this->doQueue(); + if(is_null($xmlData)) + return null; $xml = new \SimpleXMLElement($xmlData); $items = $xml->result->children(); $ret = array(); diff --git a/generator/sources/zend/Kaltura/Client/ClientBase.php b/generator/sources/zend/Kaltura/Client/ClientBase.php index abef072a0fc..89692f2d5f3 100644 --- a/generator/sources/zend/Kaltura/Client/ClientBase.php +++ b/generator/sources/zend/Kaltura/Client/ClientBase.php @@ -586,6 +586,9 @@ public function startMultiRequest() public function doMultiRequest() { $xmlData = $this->doQueue(); + if(is_null($xmlData)) + return null; + $xml = new SimpleXMLElement($xmlData); $items = $xml->result->children(); $ret = array(); From 06b75851c3238c61db1739ce57dbc14695dbd451 Mon Sep 17 00:00:00 2001 From: "eran.kornblau" Date: Sun, 19 Jan 2014 11:07:36 +0200 Subject: [PATCH 07/11] support sending the creatorId field in playlist.update the field should be ignored when its value doesn't change --- api_v3/lib/types/KalturaObject.php | 2 +- api_v3/lib/types/entry/KalturaBaseEntry.php | 7 +++++++ api_v3/lib/types/entry/KalturaPlaylist.php | 3 ++- api_v3/services/PlaylistService.php | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api_v3/lib/types/KalturaObject.php b/api_v3/lib/types/KalturaObject.php index b600e4a74d3..e27642592ea 100644 --- a/api_v3/lib/types/KalturaObject.php +++ b/api_v3/lib/types/KalturaObject.php @@ -686,7 +686,7 @@ public function validateForUsage($sourceObject, $propertiesToSkip = array()) } - private function getObjectPropertyName($propertyName) + protected function getObjectPropertyName($propertyName) { $objectPropertyName = null; $mapBetweenObjects = $this->getMapBetweenObjects(); diff --git a/api_v3/lib/types/entry/KalturaBaseEntry.php b/api_v3/lib/types/entry/KalturaBaseEntry.php index 6188c0ccfd3..cc83f27fac1 100644 --- a/api_v3/lib/types/entry/KalturaBaseEntry.php +++ b/api_v3/lib/types/entry/KalturaBaseEntry.php @@ -626,6 +626,13 @@ public function getExtraFilters() ); } + protected function getObjectPropertyName($propertyName) + { + if ($propertyName == 'creatorId') + return 'creatorPuserId'; + return parent::getObjectPropertyName($propertyName); + } + /* (non-PHPdoc) * @see IFilterable::getFilterDocs() */ diff --git a/api_v3/lib/types/entry/KalturaPlaylist.php b/api_v3/lib/types/entry/KalturaPlaylist.php index 2d77d13b51f..b2935686536 100644 --- a/api_v3/lib/types/entry/KalturaPlaylist.php +++ b/api_v3/lib/types/entry/KalturaPlaylist.php @@ -82,7 +82,8 @@ public function toUpdatableObject ( $object_to_fill , $props_to_skip = array() ) if ($this->playlistType == KalturaPlaylistType::DYNAMIC && $this->filters !== null) $this->filtersToPlaylistContentXml(); - $object_to_fill = new entry(); + if (!$object_to_fill) + $object_to_fill = new entry(); $object_to_fill->setType ( entryType::PLAYLIST ); parent::toUpdatableObject( $object_to_fill ) ; $object_to_fill->setType ( entryType::PLAYLIST ); diff --git a/api_v3/services/PlaylistService.php b/api_v3/services/PlaylistService.php index 0ff50e7d620..9c24320939d 100644 --- a/api_v3/services/PlaylistService.php +++ b/api_v3/services/PlaylistService.php @@ -150,7 +150,7 @@ function updateAction( $id , KalturaPlaylist $playlist , $updateStats = false ) $tmpDbPlaylist = $playlist->toUpdatableObject($tmpDbPlaylist); $playlistUpdate = null; - $playlistUpdate = $playlist->toUpdatableObject($playlistUpdate); + $playlistUpdate = $playlist->toObject($playlistUpdate); $this->checkAndSetValidUserUpdate($playlist, $playlistUpdate); $this->checkAdminOnlyUpdateProperties($playlist); From b0fe46b2c873db24802a752ecc8c2ffd6dbbe767 Mon Sep 17 00:00:00 2001 From: yossipapi Date: Wed, 22 Jan 2014 17:00:32 +0200 Subject: [PATCH 08/11] Front Controller save serialized response enhancements --- .../lib/webservices/APIErrors.class.php | 2 + api_v3/lib/KalturaFrontController.php | 79 ++++++++++--------- api_v3/lib/KalturaJsonProcSerializer.php | 10 +-- api_v3/lib/KalturaJsonSerializer.php | 22 ++---- api_v3/lib/KalturaPhpSerializer.php | 17 +--- api_v3/lib/KalturaSerializer.php | 2 +- api_v3/lib/KalturaXmlSerializer.php | 12 +-- 7 files changed, 55 insertions(+), 89 deletions(-) diff --git a/alpha/apps/kaltura/lib/webservices/APIErrors.class.php b/alpha/apps/kaltura/lib/webservices/APIErrors.class.php index 86d068b9eed..1d02add156c 100644 --- a/alpha/apps/kaltura/lib/webservices/APIErrors.class.php +++ b/alpha/apps/kaltura/lib/webservices/APIErrors.class.php @@ -409,4 +409,6 @@ public static function getErrorData( $errorString, $errorArgsArray = array() ) const ERROR_OCCURED_WHILE_GZUNCOMPRESS_JOB_DATA = "ERROR_OCCURED_WHILE_GZUNCOMPRESS_JOB_DATA;; error accored while gzuncompress job data"; const OBJECT_NOT_FOUND = "OBJECT_NOT_FOUND;;Object not found"; + + const UNKNOWN_RESPONSE_FORMAT = "UNKNOWN_RESPONSE_FORMAT;FORMAT;Response format provided [@FORMAT@] is not recognized by server"; } diff --git a/api_v3/lib/KalturaFrontController.php b/api_v3/lib/KalturaFrontController.php index 0f47a8a1f8a..29154807758 100644 --- a/api_v3/lib/KalturaFrontController.php +++ b/api_v3/lib/KalturaFrontController.php @@ -13,7 +13,6 @@ class KalturaFrontController private $service = ""; private $action = ""; private $disptacher = null; - private $format; private $serializer; private function KalturaFrontController() @@ -90,13 +89,12 @@ public function run() set_error_handler(array(&$this, "errorHandler")); KalturaLog::debug("Params [" . print_r($this->params, true) . "]"); - - if (isset($_REQUEST["ignoreNull"])) - $ignoreNull = ($_REQUEST["ignoreNull"] === "1") ? true : false; - else - $ignoreNull = false; - - $this->setSerializerByFormat($ignoreNull); + try { + $this->setSerializerByFormat(); + } + catch (Exception $e) { + return new kRendererDieError($e->getCode(), $e->getMessage()); + } if ($this->service == "multirequest") { @@ -126,7 +124,7 @@ public function run() $this->end = microtime(true); - return $this->serializeResponse($result, $ignoreNull); + return $this->serializeResponse($result); } public function handleMultiRequest() @@ -253,18 +251,18 @@ public function handleMultiRequest() $this->onRequestEnd($success, $errorCode, $i); if(isset($dependencies[$i])) - { + { foreach($dependencies[$i] as $currentDependency => $dependencyName) { if (strlen(trim($dependencyName)) > 0) $resultPathArray = explode(":",$dependencyName); else - $resultPathArray = array(); + $resultPathArray = array(); - $currValue = $this->getValueFromObject($currentResult, $resultPathArray); + $currValue = $this->getValueFromObject($currentResult, $resultPathArray); $pastResults[$currentDependency] = $currValue; } - } + } $results[$i] = $this->serializer->serialize($currentResult); @@ -424,13 +422,18 @@ public function getExceptionObject($ex) } - public function setSerializerByFormat($ignoreNull = false) + public function setSerializerByFormat() { + if (isset($this->params["ignoreNull"])) + $ignoreNull = ($this->params["ignoreNull"] === "1") ? true : false; + else + $ignoreNull = false; + // Determine the output format (or default to XML) - $this->format = isset($this->params["format"]) ? $this->params["format"] : KalturaResponseType::RESPONSE_TYPE_XML; + $format = isset($this->params["format"]) ? $this->params["format"] : KalturaResponseType::RESPONSE_TYPE_XML; // Create a serializer according to the given format - switch($this->format) + switch($format) { case KalturaResponseType::RESPONSE_TYPE_XML: $serializer = new KalturaXmlSerializer($ignoreNull); @@ -449,11 +452,14 @@ public function setSerializerByFormat($ignoreNull = false) break; default: - $serializer = KalturaPluginManager::loadObject('KalturaSerializer', $this->format); + $serializer = KalturaPluginManager::loadObject('KalturaSerializer', $format); break; } - $this->serializer = $serializer; + if(empty($serializer)) + throw new KalturaAPIException(APIErrors::UNKNOWN_RESPONSE_FORMAT, $format); + + $this->serializer = $serializer; } public function serializeResponse($object) @@ -466,27 +472,24 @@ public function serializeResponse($object) $start = microtime(true); KalturaLog::debug("Serialize start"); - if ( ! empty( $this->serializer ) ) // Got a serializer for the given format? + // Set HTTP headers + if(isset($this->params['content-type'])) { - // Set HTTP headers - if(isset($this->params['content-type'])) - { - header('Content-Type: ' . $this->params['content-type']); - } - else - { - $this->serializer->setHttpHeaders(); - } + header('Content-Type: ' . $this->params['content-type']); + } + else + { + $this->serializer->setHttpHeaders(); + } - // Check if this is multi request if yes than object are already serialized so we will skip otherwise serialize the object - if ($this->service != "multirequest") - $serializedObject = $this->serializer->serialize($object); - else - $serializedObject = $this->handleSerializedObjectArray($object); + // Check if this is multi request if yes than object are already serialized so we will skip otherwise serialize the object + if ($this->service != "multirequest") + $serializedObject = $this->serializer->serialize($object); + else + $serializedObject = $this->handleSerializedObjectArray($object); - // Post processing (handle special cases) - $result = $this->serializer->getHeader() . $serializedObject . $this->serializer->getFooter($this->end - $this->start); - } + // Post processing (handle special cases) + $result = $this->serializer->getHeader() . $serializedObject . $this->serializer->getFooter($this->end - $this->start); KalturaLog::debug("Serialize took - " . (microtime(true) - $start)); return $result; @@ -502,8 +505,8 @@ public function handleSerializedObjectArray($objects) $serializedObject .= $this->serializer->getItemHeader($i-1); $serializedObject .= $objects[$i]; //check if item is the last one to avoid putting footer chars in json and jsonp serializers - if($i != $objectsCount || ($this->format != KalturaResponseType::RESPONSE_TYPE_JSONP && $this->format != KalturaResponseType::RESPONSE_TYPE_JSON)) - $serializedObject .= $this->serializer->getItemFooter(); + $lastItem = ($i == $objectsCount); + $serializedObject .= $this->serializer->getItemFooter($lastItem); } $serializedObject .= $this->serializer->getMulitRequestFooter(); diff --git a/api_v3/lib/KalturaJsonProcSerializer.php b/api_v3/lib/KalturaJsonProcSerializer.php index 17fd44dd33b..f4e7b3f745e 100644 --- a/api_v3/lib/KalturaJsonProcSerializer.php +++ b/api_v3/lib/KalturaJsonProcSerializer.php @@ -25,16 +25,14 @@ public function getFooter($execTime = null) return ");"; } - public function getItemHeader($itemIndex = null) + public function getItemFooter($lastItem = false) { + if(!$lastItem) + return ','; + return ''; } - public function getItemFooter() - { - return ','; - } - public function getMulitRequestHeader($itemsCount = null) { return '['; diff --git a/api_v3/lib/KalturaJsonSerializer.php b/api_v3/lib/KalturaJsonSerializer.php index abc841618ff..234b57d7287 100644 --- a/api_v3/lib/KalturaJsonSerializer.php +++ b/api_v3/lib/KalturaJsonSerializer.php @@ -15,27 +15,15 @@ function serialize($object) $object = parent::prepareSerializedObject($object); return json_encode($object); } - - public function getHeader() - { - return ''; - } - - public function getFooter($execTime = null) - { - return ''; - } - - public function getItemHeader($itemIndex = null) + + public function getItemFooter($lastItem = false) { + if(!$lastItem) + return ','; + return ''; } - public function getItemFooter() - { - return ','; - } - public function getMulitRequestHeader($itemsCount = null) { return '['; diff --git a/api_v3/lib/KalturaPhpSerializer.php b/api_v3/lib/KalturaPhpSerializer.php index 0d0ad2ae577..164ce17fa90 100644 --- a/api_v3/lib/KalturaPhpSerializer.php +++ b/api_v3/lib/KalturaPhpSerializer.php @@ -11,27 +11,12 @@ function serialize($object) $result = serialize($object); // Let PHP's built-in serialize() function do the work return $result; } - - public function getHeader() - { - return ''; - } - - public function getFooter($execTime = null) - { - return ''; - } - + public function getItemHeader($itemIndex = null) { return 'i:' .$itemIndex . ';'; } - public function getItemFooter() - { - return ''; - } - public function getMulitRequestHeader($itemsCount = null) { return 'a:' . $itemsCount . ':{'; diff --git a/api_v3/lib/KalturaSerializer.php b/api_v3/lib/KalturaSerializer.php index 97ec92c7e00..95b9fa704c3 100644 --- a/api_v3/lib/KalturaSerializer.php +++ b/api_v3/lib/KalturaSerializer.php @@ -23,7 +23,7 @@ public function getItemHeader($itemIndex = null) { return '';} public function getFooter($execTime = null) { return '';} public function getMulitRequestFooter() { return '';} - public function getItemFooter() { return '';} + public function getItemFooter($lastItem = false) { return '';} protected function convertExceptionsToPhpArrays($object) { diff --git a/api_v3/lib/KalturaXmlSerializer.php b/api_v3/lib/KalturaXmlSerializer.php index d349cf44814..33e59cefcae 100644 --- a/api_v3/lib/KalturaXmlSerializer.php +++ b/api_v3/lib/KalturaXmlSerializer.php @@ -191,18 +191,8 @@ public function getItemHeader($itemIndex = null) return ''; } - public function getItemFooter() + public function getItemFooter($lastItem = false) { return ''; } - - public function getMulitRequestHeader($itemsCount = null) - { - return ''; - } - - public function getMulitRequestFooter() - { - return ''; - } } From 35d23084b8064e97ff2365368b2e1df8159aa9a3 Mon Sep 17 00:00:00 2001 From: yossipapi Date: Wed, 22 Jan 2014 18:42:07 +0200 Subject: [PATCH 09/11] Avoid chnage in client base --- generator/sources/php53/library/Kaltura/Client/Base.php | 1 + 1 file changed, 1 insertion(+) diff --git a/generator/sources/php53/library/Kaltura/Client/Base.php b/generator/sources/php53/library/Kaltura/Client/Base.php index c879c2bf7a1..8d5b672e0ab 100644 --- a/generator/sources/php53/library/Kaltura/Client/Base.php +++ b/generator/sources/php53/library/Kaltura/Client/Base.php @@ -481,6 +481,7 @@ public function doMultiRequest() $xmlData = $this->doQueue(); if(is_null($xmlData)) return null; + $xml = new \SimpleXMLElement($xmlData); $items = $xml->result->children(); $ret = array(); From 09c735dc3104a516068d00276044f550d1211a87 Mon Sep 17 00:00:00 2001 From: yossipapi Date: Thu, 23 Jan 2014 16:51:48 +0200 Subject: [PATCH 10/11] Additional enhancements to the multirequest serialization fix. 1. Avoid using preg_match twice in front controller 2. JsonPSerilizer extends Json sterilizer so we can re-use the functions from the base class instead of duplicating --- api_v3/lib/KalturaFrontController.php | 23 ++++------------------- api_v3/lib/KalturaJsonProcSerializer.php | 18 ------------------ 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/api_v3/lib/KalturaFrontController.php b/api_v3/lib/KalturaFrontController.php index 29154807758..fc64478b7f4 100644 --- a/api_v3/lib/KalturaFrontController.php +++ b/api_v3/lib/KalturaFrontController.php @@ -190,28 +190,13 @@ public function handleMultiRequest() $currentParams['partnerId'] = $commonParams['partnerId']; } - // check if we need to replace params with prev results + // check if we need to replace params with prev results foreach($currentParams as $key => &$val) { - $matches = array(); - - // keywords: multirequest, result, depend, pass - // figuring out if requested params should be extracted from previous result - // example: if you want to use KalturaPlaylist->playlistContent result from the first request - // in your second request, the second request will contain the following value: - // {1:result:playlistContent} - if (preg_match('/\{([0-9]*)\:result\:?(.*)?\}/', $val, $matches)) - { - $pastResultsIndex = $matches[0]; - $resultIndex = $matches[1]; - - if (count($results) >= $resultIndex) // if the result index is valid - { - $val = $pastResults[$pastResultsIndex]; - } - } + if(isset($pastResults[$val])) + $val = $pastResults[$pastResultsIndex]; } - + // cached parameters should be different when the request is part of a multirequest // as part of multirequest - the cached data is a serialized php object // when not part of multirequest - the cached data is the actual response diff --git a/api_v3/lib/KalturaJsonProcSerializer.php b/api_v3/lib/KalturaJsonProcSerializer.php index f4e7b3f745e..6359ad37f39 100644 --- a/api_v3/lib/KalturaJsonProcSerializer.php +++ b/api_v3/lib/KalturaJsonProcSerializer.php @@ -24,22 +24,4 @@ public function getFooter($execTime = null) { return ");"; } - - public function getItemFooter($lastItem = false) - { - if(!$lastItem) - return ','; - - return ''; - } - - public function getMulitRequestHeader($itemsCount = null) - { - return '['; - } - - public function getMulitRequestFooter() - { - return ']'; - } } From 58dc585ace4d2b8a2f915a3f51c5dcdf017d6a49 Mon Sep 17 00:00:00 2001 From: yossipapi Date: Tue, 28 Jan 2014 16:49:00 +0200 Subject: [PATCH 11/11] Changes after testing. --- api_v3/lib/KalturaFrontController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_v3/lib/KalturaFrontController.php b/api_v3/lib/KalturaFrontController.php index fc64478b7f4..b901eecb3d2 100644 --- a/api_v3/lib/KalturaFrontController.php +++ b/api_v3/lib/KalturaFrontController.php @@ -194,7 +194,7 @@ public function handleMultiRequest() foreach($currentParams as $key => &$val) { if(isset($pastResults[$val])) - $val = $pastResults[$pastResultsIndex]; + $val = $pastResults[$val]; } // cached parameters should be different when the request is part of a multirequest