protected function parseOutput($output) { $amf = array(); $outputLower = strtolower($output); $jsonObj = json_decode($outputLower); if (!is_null($jsonObj)) { // Check for json decode errors caused by inproper utf8 encoding. if (json_last_error() != JSON_ERROR_NONE) { $jsonObj = json_decode(utf8_encode($outputLower)); } $jsonObj = $jsonObj->packets; foreach ($jsonObj as $tmp) { // the first data packet is of smaller size of 205 chars if (strlen($tmp->data) > self::MinAMFSizeToTryParse) { $amfTs = $this->getTimestampFromAMF($tmp->data); $amfPts = $tmp->pts; if ($this->shouldSaveAMF($amf, $amfTs, $amfPts)) { $amfData = $amfPts . ';' . $amfTs; array_push($amf, $amfData); } } } KalturaLog::debug('amf array: ' . print_r($amf, true)); } else { KalturaLog::warning('failed to json_decode. returning an empty AMF array'); } return $amf; }
public function createThumnail($position = null, $width = null, $height = null, $frameCount = 1, $targetType = "image2", $dar = null, $vidDur = null) { if (!isset($frameCount)) { $frameCount = 1; } if (!isset($targetType)) { $targetType = "image2"; } KalturaLog::debug("position[{$position}], width[{$width}], height[{$height}], frameCount[{$frameCount}], frameCount[{$frameCount}], dar[{$dar}], vidDur[{$vidDur}]"); if (isset($dar) && $dar > 0 && isset($height)) { $width = floor(round($height * $dar) / 2) * 2; } // TODO - calculate the width and height according to dar $cmdArr = $this->getCommand($position, $width, $height, $frameCount, $targetType, $vidDur); $cmd = $cmdArr[0]; $rv = null; KalturaLog::info("Executing: {$cmd}"); $logFilePath = "{$this->targetPath}.log"; $logFileDir = dirname($logFilePath); if (!file_exists($logFileDir)) { mkdir(dirname($logFilePath), 0665, true); } file_put_contents($logFilePath, $cmd, FILE_APPEND); $output = system($cmd, $rv); KalturaLog::debug("Returned value: '{$rv}'"); if ($rv == 0 && $this->parseOutput($output) == true) { return true; } KalturaLog::warning("First attempt failed due to ffmpeg crash or 'missing-keyframe' issue.\nSecond attempt with 'slow-thumb-capture' mode"); $cmd = $cmdArr[1]; if (isset($cmd)) { if ($position > 30) { KalturaLog::err("Can not run 2nd attempt - 'slow-thumb-capture' is allowed up to 30 sec position"); } else { $rv = null; KalturaLog::info("Executing: {$cmd}"); file_put_contents($logFilePath, $cmd, FILE_APPEND); $output = system($cmd, $rv); KalturaLog::debug("Returned value: '{$rv}'"); if ($rv == 0 && $this->parseOutput($output) == true) { } //return true; } } return $rv ? false : true; }
/** * @param KalturaRelatedFilter $filter * @param KalturaObject $parentObject * @return boolean * @throws KalturaAPIException */ public function apply(KalturaRelatedFilter $filter, KalturaObject $parentObject) { $filterProperty = $this->filterProperty; $parentProperty = $this->parentProperty; KalturaLog::debug("Mapping " . get_class($parentObject) . "::{$parentProperty}[{$parentObject->{$parentProperty}}] to " . get_class($filter) . "::{$filterProperty}"); if (!property_exists($parentObject, $parentProperty)) { throw new KalturaAPIException(KalturaErrors::PROPERTY_IS_NOT_DEFINED, $parentProperty, get_class($parentObject)); } if (!property_exists($filter, $filterProperty)) { throw new KalturaAPIException(KalturaErrors::PROPERTY_IS_NOT_DEFINED, $filterProperty, get_class($filter)); } if (is_null($parentObject->{$parentProperty}) && !$this->allowNull) { KalturaLog::warning("Parent property [" . get_class($parentObject) . "::{$parentProperty}] is null"); return false; } $filter->{$filterProperty} = $parentObject->{$parentProperty}; return true; }
public function getLocalPath($localPath, $remotePath, &$errDescription) { KalturaLog::info("Translating remote path [{$remotePath}] to local path [{$localPath}]"); if (file_exists($localPath)) { if (!$this->fileCacheTimeout) { return true; } clearstatcache(); if (filemtime($localPath) > time() - $this->fileCacheTimeout) { return true; } @unlink($localPath); } $res = $this->fetchFile($remotePath, $localPath, $errDescription); if (!$res) { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { KalturaLog::warning("Going to flush DNS: "); $output = system("ipconfig /flushdns", $rc); KalturaLog::warning($output); } } return $res; }
protected function deleteAllButKeepSmallest(array $flavors) { $smallestFlavor = $this->findSmallestFlavor($flavors); if (is_null($smallestFlavor)) { KalturaLog::warning('Smallest flavor was not found, cannot continue'); return; } $this->deleteFlavorsKeepingConfiguredList($flavors, array($smallestFlavor->flavorParamsId)); }
protected function moveDataFile(KalturaConvertLiveSegmentJobData $data, $localTempAmfFilePath, $sharedTempAmfFilePath) { KalturaLog::debug('moving file from ' . $localTempAmfFilePath . ' to ' . $sharedTempAmfFilePath); kFile::moveFile($localTempAmfFilePath, $sharedTempAmfFilePath, true); clearstatcache(); $fileSize = kFile::fileSize($sharedTempAmfFilePath); $this->setFilePermissions($sharedTempAmfFilePath); if (!$this->checkFileExists($sharedTempAmfFilePath, $fileSize)) { KalturaLog::warning('failed to move file to ' . $sharedTempAmfFilePath); } else { $data->destDataFilePath = $sharedTempAmfFilePath; } }
public function adjustAssetParams($entryId, array &$flavors) { $entry = entryPeer::retrieveByPK($entryId); if (!isset($entry)) { KalturaLog::warning("Bad entry id ({$entryId})."); return; } $partnerId = $entry->getPartnerId(); $profile = MetadataProfilePeer::retrieveBySystemName(self::TRANSCODING_METADATA_PROF_SYSNAME, $partnerId); if (!isset($profile)) { KalturaLog::log("No Transcoding Metadata Profile (sysName:" . self::TRANSCODING_METADATA_PROF_SYSNAME . ", partner:{$partnerId}). Nothing to adjust"); return; } $metadata = MetadataPeer::retrieveByObject($profile->getId(), MetadataObjectType::ENTRY, $entryId); if (!isset($metadata)) { KalturaLog::log("No Metadata for entry({$entryId}), metadata profile (id:" . $profile->getId() . "). Nothing to adjust"); return; } KalturaLog::log("Entry ({$entryId}) has following metadata fields:" . print_r($metadata, 1)); // Retrieve the associated XML file $key = $metadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA); if (!isset($key)) { KalturaLog::log("Entry({$entryId}) metadata object misses file sync key! Nothing to adjust"); return; } $xmlStr = kFileSyncUtils::file_get_contents($key, true, false); if (!isset($xmlStr)) { KalturaLog::log("Entry({$entryId}) metadata object misses valid file sync! Nothing to adjust"); return; } KalturaLog::log("Adjusting: entry({$entryId}),metadata profile(" . self::TRANSCODING_METADATA_PROF_SYSNAME . "),xml==>{$xmlStr}"); $watermarkSettingsStr = null; $imageEntry = null; $imageUrl = null; // Retrieve the custom metadata fields from the asocieted XML $xml = new SimpleXMLElement($xmlStr); $fldName = self::TRANSCODING_METADATA_WATERMMARK_SETTINGS; if (isset($xml->{$fldName})) { $watermarkSettingsStr = (string) $xml->{$fldName}; KalturaLog::log("Found metadata - {$fldName}({$watermarkSettingsStr})"); } $fldName = self::TRANSCODING_METADATA_WATERMMARK_IMAGE_ENTRY; if (isset($xml->{$fldName})) { $imageEntry = (string) $xml->{$fldName}; KalturaLog::log("Found metadata - {$fldName}({$imageEntry})"); } $fldName = self::TRANSCODING_METADATA_WATERMMARK_IMAGE_URL; if (isset($xml->{$fldName})) { $imageUrl = (string) $xml->{$fldName}; KalturaLog::log("Found metadata - {$fldName}({$imageUrl})"); } /* * The imageEntry is preffered if both imageEntry and url are set, * in such case - remove the url */ if (isset($imageEntry) && isset($imageUrl)) { KalturaLog::log("Found both " . self::TRANSCODING_METADATA_WATERMMARK_IMAGE_URL . "({$imageEntry}) and {$fldName}({$imageUrl}). Removing {$fldName}"); $imageUrl = null; // } /* * If custom-metadate contains 'full' WM settings ('watermarkSettingsStr' is set), * adjust it to custom meta imageEntry/imageUrl values, * if those provided. */ if (isset($watermarkSettingsStr)) { $watermarkSettings = json_decode($watermarkSettingsStr); $this->adjustWatermarSettings($watermarkSettings, $imageEntry, $imageUrl); } /* * Loop through the flavor params to update the WM settings, * if it is required. */ foreach ($flavors as $k => $flavor) { KalturaLog::log("Processing flavor id:" . $flavor->getId()); $wmDataObj = null; /* * The 'full' WM settings in the custom metadata overides any exitings WM settings */ if (isset($watermarkSettings)) { $wmDataObj = clone $watermarkSettings; } else { /* * No 'full' settings. * Adjust the existing flavor WM data with custom metadata imageEntry/imageUrl */ $wmDataStr = $flavor->getWatermarkData(); if (isset($wmDataStr)) { $wmDataObj = json_decode($wmDataStr); if ($this->adjustWatermarSettings($wmDataObj, $imageEntry, $imageUrl) == false) { continue; } } } if (isset($wmDataObj)) { $toJson = json_encode($wmDataObj); $flavor->setWatermarkData($toJson); $flavors[$k] = $flavor; KalturaLog::log("Set flavor (" . $flavor->getId() . ") WM to {$toJson}"); } } }
/** * Build a packaged tarball for the client library. * @param $outputPath The path the client library files are located at. * @param $generatorName The name of the client library. */ function createPackage($outputPath, $generatorName, $generatedDate, $overrideGenDate = null) { KalturaLog::info("Trying to package"); $output = shell_exec("tar --version"); if ($output === null) { KalturaLog::warning("Skipping packaging, \"tar\" command not found! On Windows, tar can be installed using Cygwin, and it should be added to the path"); } else { if ($overrideGenDate == null) { $overrideGenDate = $generatedDate; } $fileName = "{$generatorName}_{$overrideGenDate}.tar.gz"; $gzipOutputPath = "../" . $fileName; $cmd = "tar -czf \"{$gzipOutputPath}\" ../" . $generatorName; $oldDir = getcwd(); $outputPath = realpath($outputPath); KalturaLog::debug("Changing dir to [{$outputPath}]"); chdir($outputPath); KalturaLog::info("Executing: {$cmd}"); passthru($cmd); if (file_exists($gzipOutputPath)) { KalturaLog::info("Package created successfully: {$gzipOutputPath}"); } else { KalturaLog::err("Failed to create package"); } KalturaLog::debug("Restoring dir to [{$oldDir}]"); chdir($oldDir); } }
/** * @param array $keys * @param mixed $var */ public function multiGetAndTouch(array $keys) { try { $metas = $this->bucket->get($keys); KalturaLog::debug("key [" . print_r($keys, true) . "]"); $values = array(); foreach ($keys as $key) { $meta = $metas[$key]; if ($meta->error) { KalturaLog::warning($meta->error->getMessage()); } $values[$key] = $meta->value; } return $values; } catch (CouchbaseException $e) { } return false; }
/** * @param int $partnerId * @param string $protocol http or https * @param SessionType $ksType * @param array $userRoles * @param string $objectType class name * @param string $objectId * @param string $startObjectKey * @param string $endObjectKey */ public static function addRecalculateResponseProfileCacheJob($partnerId, $protocol, $ksType, array $userRoles, $objectType, $objectId = null, $startObjectKey = null, $endObjectKey = null) { KalturaLog::debug("Recalculating cache partner[{$partnerId}] protocol[{$protocol}] ks[{$ksType}] roles[" . implode(', ', $userRoles) . "] object[{$objectType}] id [{$objectId}] start[{$startObjectKey}] end[{$endObjectKey}]"); $jobData = new kRecalculateResponseProfileCacheJobData(); $jobData->setProtocol($protocol); $jobData->setKsType($ksType); $jobData->setUserRoles($userRoles); $jobData->setObjectType($objectType); $jobData->setObjectId($objectId); $jobData->setStartObjectKey($startObjectKey); $jobData->setEndObjectKey($endObjectKey); $batchJob = new BatchJob(); $batchJob->setPartnerId($partnerId); if (is_subclass_of($objectType, 'entry')) { $batchJob->setObjectId($objectId); $batchJob->setEntryId($objectId); $batchJob->setObjectType(BatchJobObjectType::ENTRY); } elseif (is_subclass_of($objectType, 'category')) { $batchJob->setObjectId($objectId); $batchJob->setObjectType(BatchJobObjectType::CATEGORY); } else { KalturaLog::warning("Object type [{$objectType}] is not expected to need cache recalculation"); return null; } return self::addJob($batchJob, $jobData, BatchJobType::RECALCULATE_CACHE, RecalculateCacheType::RESPONSE_PROFILE); }
private function isCacheValid(kLiveMediaServer $kMediaServer) { $cacheType = self::getCacheType(); $cacheStore = kCacheManager::getSingleLayerCache($cacheType); if (!$cacheStore) { KalturaLog::warning("Cache store [{$cacheType}] not found"); $lastUpdate = time() - $kMediaServer->getTime(); $expiry = kConf::get('media_server_cache_expiry', 'local', self::DEFAULT_CACHE_EXPIRY); return $lastUpdate <= $expiry; } $key = $this->getId() . '_' . $kMediaServer->getHostname() . '_' . $kMediaServer->getIndex(); KalturaLog::debug("Get cache key [{$key}] from store [{$cacheType}]"); return $cacheStore->get($key); }
private static function getExternalStorageUrl(Partner $partner, asset $asset, FileSyncKey $key, $servePlayManifest = false, $playManifestClientTag = null, $storageId = null) { if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { return null; } if (is_null($storageId) && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) { if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) { // check if having file sync on kaltura dcs return null; } } $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId); if (!$fileSync) { return null; } $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc()); if (!$storage) { return null; } if ($servePlayManifest) { // in case of an https request, if a delivery profile which supports https doesn't exist use an http cdn api host if (infraRequestUtils::getProtocol() == infraRequestUtils::PROTOCOL_HTTPS && DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId(), PlaybackProtocol::HTTP, "https"))) { $url = requestUtils::getApiCdnHost(); } else { $url = infraRequestUtils::PROTOCOL_HTTP . "://" . kConf::get("cdn_api_host"); } $url .= $asset->getPlayManifestUrl($playManifestClientTag, $storageId); } else { $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId())); if ($urlManager) { $dynamicAttrs = new DeliveryProfileDynamicAttributes(); $dynamicAttrs->setFileExtension($asset->getFileExt()); $dynamicAttrs->setStorageId($fileSync->getDc()); $urlManager->setDynamicAttributes($dynamicAttrs); $url = ltrim($urlManager->getFileSyncUrl($fileSync), '/'); if (strpos($url, "://") === false) { $url = rtrim($urlManager->getUrl(), "/") . "/" . $url; } } else { KalturaLog::warning("Couldn't determine delivery profile for storage id"); $url = null; } } return $url; }
private static function getSegmentStartTime($amfArray) { if (count($amfArray) == 0) { KalturaLog::warning("getSegmentStartTime got an empty AMFs array - returning 0 as segment end time"); return 0; } return ($amfArray[0]->ts - $amfArray[0]->pts) / 1000; }
/** * @param array $keys * @param mixed $var */ public function multiGetAndTouch(array $keys) { try { $metas = $this->bucket->get($keys); if ($this->debug) { KalturaLog::debug("key [" . implode(', ', $keys) . "], metas [" . print_r($metas, true) . "]"); } $values = array(); foreach ($keys as $key) { $meta = $metas[$key]; if ($meta->error) { KalturaLog::warning($meta->error->getMessage()); } $values[$key] = $meta->value; } return $values; } catch (CouchbaseException $e) { if ($e->getCode() == self::ERROR_CODE_THE_KEY_DOES_NOT_EXIST_IN_THE_SERVER) { return false; } throw $e; } }
protected function concat(KalturaBatchJob $job, KalturaConcatJobData $data) { $this->updateJob($job, "Files concatenation started", KalturaBatchJobStatus::PROCESSING); $jobData = $job->data; $ffmpegBin = KBatchBase::$taskConfig->params->ffmpegCmd; $ffprobeBin = isset(KBatchBase::$taskConfig->params->ffprobeCmd) ? KBatchBase::$taskConfig->params->ffprobeCmd : "ffprobe"; $mediaInfoBin = isset(KBatchBase::$taskConfig->params->mediaInfoCmd) ? KBatchBase::$taskConfig->params->mediaInfoCmd : "mediainfo"; $fileName = "{$job->entryId}_{$data->flavorAssetId}.mp4"; $localTempFilePath = $this->localTempPath . DIRECTORY_SEPARATOR . $fileName; $sharedTempFilePath = $this->sharedTempPath . DIRECTORY_SEPARATOR . $fileName; $srcFiles = array(); foreach ($data->srcFiles as $srcFile) { /* @var $srcFile KalturaString */ $srcFiles[] = $srcFile->value; } $result = $this->concatFiles($ffmpegBin, $ffprobeBin, $srcFiles, $localTempFilePath, $data->offset, $data->duration); if (!$result) { return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, null, "Failed to concat files", KalturaBatchJobStatus::FAILED); } try { // get the concatenated duration $mediaInfoParser = new KMediaInfoMediaParser($localTempFilePath, $mediaInfoBin); $data->concatenatedDuration = $mediaInfoParser->getMediaInfo()->videoDuration; } catch (Exception $ex) { KalturaLog::warning('failed to get concatenatedDuration ' . print_r($ex)); } return $this->moveFile($job, $data, $localTempFilePath, $sharedTempFilePath); }
} $oldCategory = $oldCategories[$distributionProfile->getDefaultCategory()]; $client->setAccessToken(str_replace('\\', '', json_encode($distributionProfile->getGoogleOAuth2Data()))); if ($demoCategories && $distributionProfile->getUsername() == 'demodistro') { $categories = $demoCategories; } else { try { $youtube = new Google_Service_YouTube($client); $categoriesListResponse = $youtube->videoCategories->listVideoCategories('id,snippet', array('regionCode' => 'us')); $categories = array(); foreach ($categoriesListResponse->getItems() as $category) { $categories[$category['snippet']['title']] = $category['id']; } if ($distributionProfile->getUsername() == 'demodistro') { $demoCategories = $categories; } } catch (Exception $e) { KalturaLog::err($e); continue; } } if (!isset($categories[$oldCategory])) { KalturaLog::warning("Partner [" . $distributionProfile->getPartnerId() . "] Distribution-Profile [{$lastId}] old category [{$oldCategory}] not found"); continue; } $distributionProfile->setDefaultCategory($categories[$oldCategory]); $distributionProfile->save(); } $criteria->add(DistributionProfilePeer::ID, $lastId, Criteria::GREATER_THAN); $distributionProfiles = DistributionProfilePeer::doSelect($criteria); }
/** * @param BatchJob $dbBatchJob * @param kConvertLiveSegmentJobData $data * @return BatchJob */ public static function handleConvertLiveSegmentFinished(BatchJob $dbBatchJob, kConvertLiveSegmentJobData $data) { $liveEntry = entryPeer::retrieveByPKNoFilter($dbBatchJob->getEntryId()); /* @var $liveEntry LiveEntry */ if (!$liveEntry) { KalturaLog::err("Live entry [" . $dbBatchJob->getEntryId() . "] not found"); return $dbBatchJob; } $recordedEntry = entryPeer::retrieveByPKNoFilter($liveEntry->getRecordedEntryId()); if (!$recordedEntry) { KalturaLog::err("Recorded entry [" . $liveEntry->getRecordedEntryId() . "] not found"); return $dbBatchJob; } $asset = assetPeer::retrieveByIdNoFilter($data->getAssetId()); /* @var $asset liveAsset */ if (!$asset) { KalturaLog::err("Live asset [" . $data->getAssetId() . "] not found"); return $dbBatchJob; } $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_PRIMARY; if ($data->getMediaServerIndex() == MediaServerIndex::SECONDARY) { $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_SECONDARY; } $key = $asset->getSyncKey($keyType); $baseName = $asset->getEntryId() . '_' . $asset->getId() . '.ts'; kFileSyncUtils::moveFromFileToDirectory($key, $data->getDestFilePath(), $baseName); if ($data->getMediaServerIndex() == MediaServerIndex::SECONDARY) { return $dbBatchJob; } $files = kFileSyncUtils::dir_get_files($key, false); if (self::hasFileDiscontinuity($files)) { KalturaLog::warning('we have a discontinuity with ts files - not running the concat job for entry [ ' . $dbBatchJob->getEntryId() . ']'); return $dbBatchJob; } if (count($files) > 1) { // find replacing entry id $replacingEntry = self::getReplacingEntry($recordedEntry, $asset); if (is_null($replacingEntry)) { KalturaLog::err("Failed to get replacing entry"); } $flavorParams = assetParamsPeer::retrieveByPKNoFilter($asset->getFlavorParamsId()); if (is_null($flavorParams)) { KalturaLog::err('Failed to retrieve asset params'); return $dbBatchJob; } // create asset $replacingAsset = assetPeer::getNewAsset(assetType::FLAVOR); $replacingAsset->setPartnerId($replacingEntry->getPartnerId()); $replacingAsset->setEntryId($replacingEntry->getId()); $replacingAsset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED); $replacingAsset->setFlavorParamsId($flavorParams->getId()); $replacingAsset->setFromAssetParams($flavorParams); if ($flavorParams->hasTag(assetParams::TAG_SOURCE)) { $replacingAsset->setIsOriginal(true); } $replacingAsset->save(); $job = kJobsManager::addConcatJob($dbBatchJob, $replacingAsset, $files); } return $dbBatchJob; }
/** * Tries to transalte the friendly name of the category to the api value, if not found the distribution progile default will be used * @param Google_Service_YouTube $youtube * @param KalturaYoutubeApiDistributionProfile $distributionProfile * @param string $category * @return int */ protected function translateCategory(Google_Service_YouTube $youtube, KalturaYoutubeApiDistributionProfile $distributionProfile, $categoryName) { if ($categoryName) { $categoriesListResponse = $youtube->videoCategories->listVideoCategories('id,snippet', array('regionCode' => 'us')); foreach ($categoriesListResponse->getItems() as $category) { if ($category['snippet']['title'] == $categoryName) { return $category['id']; } } KalturaLog::warning("Partner [{$distributionProfile->partnerId}] Distribution-Profile [{$distributionProfile->id}] category [{$categoryName}] not found"); } if ($distributionProfile->defaultCategory) { return $distributionProfile->defaultCategory; } return $categoryName; }
public function loadRelatedObjects(KalturaDetachedResponseProfile $responseProfile) { $this->relatedObjects = new KalturaListResponseArray(); foreach ($responseProfile->relatedProfiles as $relatedProfile) { /* @var $relatedProfile KalturaDetachedResponseProfile */ if (!$relatedProfile->filter) { KalturaLog::notice("Related response-profile [{$relatedProfile->name}] has no filter and should not be used as nested profile"); continue; } KalturaLog::debug("Loading related response-profile [{$relatedProfile->name}] with filter [" . get_class($relatedProfile->filter) . "]"); $filter = clone $relatedProfile->filter; /* @var $filter KalturaRelatedFilter */ if ($relatedProfile->mappings) { $applied = true; foreach ($relatedProfile->mappings as $mapping) { /* @var $mapping KalturaResponseProfileMapping */ if (!$mapping->apply($filter, $this)) { $applied = false; break; } } if (!$applied) { KalturaLog::warning("Mappings could not be applied for response-profile [{$relatedProfile->name}]"); continue; } } else { KalturaLog::debug("No mappings defined in response-profile [{$relatedProfile->name}]"); } $pager = $relatedProfile->pager; if (!$pager) { $pager = new KalturaFilterPager(); } $this->relatedObjects[$relatedProfile->name] = $filter->getListResponse($pager, $relatedProfile); } }
public function generate() { $this->load(); $this->_xmlElement = $this->_doc->createElement("xml"); $this->_xmlElement->setAttribute('apiVersion', KALTURA_API_VERSION); $this->_xmlElement->setAttribute('generatedDate', time()); exec("which svnversion 2>/dev/null", $out, $rc); if ($rc === 0) { $apiV3Path = realpath(dirname(__FILE__) . '/../api_v3'); $svnVersion = shell_exec("svnversion {$apiV3Path}"); if ($svnVersion === null) { KalturaLog::warning("Failed to get svn revision number"); } else { $this->_xmlElement->setAttribute('revision', trim($svnVersion)); } } $this->_doc->appendChild($this->_xmlElement); $this->_xmlElement->appendChild(new DOMComment(" Generated on date " . strftime("%d/%m/%y %H:%M:%S", time()) . " ")); $enumsElement = $this->_doc->createElement("enums"); $classesElement = $this->_doc->createElement("classes"); foreach ($this->_types as $typeReflector) { if ($typeReflector->isEnum() || $typeReflector->isStringEnum()) { $enumElement = $this->getEnumElement($typeReflector); $enumsElement->appendChild($enumElement); } else { if (!$typeReflector->isArray()) { $classElement = $this->getClassElement($typeReflector); $classesElement->appendChild($classElement); } } } $servicesElement = $this->_doc->createElement("services"); foreach ($this->_services as $serviceId => $serviceActionItem) { /* @var $serviceActionItem KalturaServiceActionItem */ if (!isset($this->_includeList[strtolower($serviceId)])) { KalturaLog::debug("Service [{$serviceId}] excluded"); continue; } $serviceIncludeList = $this->_includeList[strtolower($serviceId)]; $serviceElement = $this->_doc->createElement("service"); $serviceElement->setAttribute("id", $serviceId); $serviceElement->setAttribute("name", $serviceActionItem->serviceInfo->serviceName); $description = $serviceActionItem->serviceInfo->description; $description = $this->fixDescription($description); $serviceElement->setAttribute("description", $description); $plugin = $this->extractPluginNameFromPackage($serviceActionItem->serviceInfo->package); if ($plugin) { $serviceElement->setAttribute("plugin", $plugin); } foreach ($serviceActionItem->actionMap as $actionId => $actionReflector) { /* @var $actionReflector KalturaActionReflector */ if (!isset($serviceIncludeList[strtolower($actionId)])) { KalturaLog::debug("Action [" . $serviceId . ".{$actionId}] excluded"); continue; } $actionInfo = $actionReflector->getActionInfo(); if ($actionInfo->serverOnly) { continue; } if (strpos($actionInfo->clientgenerator, "ignore") !== false) { continue; } $serviceActionElement = $this->getServiceActionElement($actionReflector); $serviceElement->appendChild($serviceActionElement); } $servicesElement->appendChild($serviceElement); } $pluginsElement = $this->_doc->createElement("plugins"); $this->appendPlugins($pluginsElement); $configurationsElement = $this->_doc->createElement("configurations"); $this->appendConfigurations($configurationsElement); $this->_xmlElement->appendChild($enumsElement); $this->_xmlElement->appendChild($classesElement); $this->_xmlElement->appendChild($servicesElement); $this->_xmlElement->appendChild($pluginsElement); $this->_xmlElement->appendChild($configurationsElement); $this->addFile("KalturaClient.xml", $this->_doc->saveXML()); }
/** * Sync objects between the source and target accounts * @param KalturaServiceBase $targetClientService API service for the current object type * @param array $newObjects array of target objects that should be added/updated * @param array $sourceObjects array of source objects * @param array $distributedMap array of information about previously distributed objects * @param string $targetEntryId * @param string $addArgsFunc special function to extract arguments for the ADD api action * @param string $updateArgsFunc special function to extract arguments for the UPDATE api action * @return array of the synced objects */ protected function syncTargetEntryObjects(KalturaServiceBase $targetClientService, $newObjects, $sourceObjects, $distributedMap, $targetEntryId, $addArgsFunc = null, $updateArgsFunc = null) { $syncedObjects = array(); $distributedMap = empty($distributedMap) ? array() : unserialize($distributedMap); // walk through all new target objects and add/update on target as necessary if (count($newObjects)) { KalturaLog::info('Syncing target objects for source IDs [' . implode(',', array_keys($newObjects)) . ']'); foreach ($newObjects as $sourceObjectId => $targetObject) { if (is_array($distributedMap) && array_key_exists($sourceObjectId, $distributedMap)) { // this object was previously distributed KalturaLog::info('Source object id [' . $sourceObjectId . '] was previously distributed'); $lastDistributedUpdatedAt = isset($distributedMap[$sourceObjectId][self::DISTRIBUTED_INFO_SOURCE_UPDATED_AT]) ? $distributedMap[$sourceObjectId][self::DISTRIBUTED_INFO_SOURCE_UPDATED_AT] : null; $currentSourceUpdatedAt = isset($sourceObjects[$sourceObjectId]->updatedAt) ? $sourceObjects[$sourceObjectId]->updatedAt : null; $targetObjectId = isset($distributedMap[$sourceObjectId][self::DISTRIBUTED_INFO_TARGET_ID]) ? $distributedMap[$sourceObjectId][self::DISTRIBUTED_INFO_TARGET_ID] : null; if (is_null($targetObjectId)) { throw new Exception('Missing previously distributed target object id for source id [' . $sourceObjectId . ']'); } if (!is_null($lastDistributedUpdatedAt) && !is_null($currentSourceUpdatedAt) && $currentSourceUpdatedAt <= $lastDistributedUpdatedAt) { // object wasn't updated since last distributed - just return existing info KalturaLog::info('No need to re-distributed object since it was not updated since last distribution - returning dummy object with target id [' . $targetObjectId . ']'); $targetObject->id = $targetObjectId; $syncedObjects[$sourceObjectId] = $targetObject; } else { // should update existing target object $targetObjectForUpdate = $this->removeInsertOnly($targetObject); $updateArgs = null; if (is_null($updateArgsFunc)) { $updateArgs = array($targetObjectId, $targetObjectForUpdate); } else { $updateArgs = call_user_func_array(array($this, $updateArgsFunc), array($targetObjectId, $targetObjectForUpdate)); } $syncedObjects[$sourceObjectId] = call_user_func_array(array($targetClientService, 'update'), $updateArgs); } unset($distributedMap[$sourceObjectId]); } else { // this object was not previously distributed - should add new target object $addArgs = null; if (is_null($addArgsFunc)) { $addArgs = array($targetEntryId, $targetObject); } else { $addArgs = call_user_func_array(array($this, $addArgsFunc), array($targetObject)); } $syncedObjects[$sourceObjectId] = call_user_func_array(array($targetClientService, 'add'), $addArgs); } } } // check if previously distributed objects should be deleted from the target account if (count($distributedMap)) { KalturaLog::info('Deleting target objects that were deleted in source with IDs [' . implode(',', array_keys($distributedMap)) . ']'); foreach ($distributedMap as $sourceId => $objInfo) { // delete from target account $targetId = isset($objInfo[self::DISTRIBUTED_INFO_TARGET_ID]) ? $objInfo[self::DISTRIBUTED_INFO_TARGET_ID] : null; KalturaLog::info('Deleting previously distributed source object id [' . $sourceId . '] target object id [' . $targetId . ']'); if (is_null($targetId)) { throw new Exception('Missing previously distributed target object id for source id [' . $sourceId . ']'); } try { $targetClientService->delete($targetId); } catch (Exception $e) { $acceptableErrorCodes = array('FLAVOR_ASSET_ID_NOT_FOUND', 'THUMB_ASSET_ID_NOT_FOUND', 'INVALID_OBJECT_ID', 'CAPTION_ASSET_ID_NOT_FOUND', 'INVALID_CUE_POINT_ID'); if (in_array($e->getCode(), $acceptableErrorCodes)) { KalturaLog::warning('Object with id [' . $targetId . '] is already deleted - ignoring exception'); } else { throw $e; } } } } return $syncedObjects; }