public function watchFolder(KalturaDropFolder $folder)
 {
     $this->dropFolder = $folder;
     $this->fileTransferMgr = self::getFileTransferManager($this->dropFolder);
     KalturaLog::info('Watching folder [' . $this->dropFolder->id . ']');
     $physicalFiles = $this->getDropFolderFilesFromPhysicalFolder();
     if (count($physicalFiles) > 0) {
         $dropFolderFilesMap = $this->loadDropFolderFiles();
     } else {
         $dropFolderFilesMap = array();
     }
     $maxModificationTime = 0;
     foreach ($physicalFiles as &$physicalFile) {
         /* @var $physicalFile FileObject */
         $physicalFileName = $physicalFile->filename;
         $utfFileName = kString::stripUtf8InvalidChars($physicalFileName);
         if ($physicalFileName != $utfFileName) {
             KalturaLog::info("File name [{$physicalFileName}] is not utf-8 compatible, Skipping file...");
             continue;
         }
         if (!kXml::isXMLValidContent($utfFileName)) {
             KalturaLog::info("File name [{$physicalFileName}] contains invalid XML characters, Skipping file...");
             continue;
         }
         if ($this->dropFolder->incremental && $physicalFile->modificationTime < $this->dropFolder->lastFileTimestamp) {
             KalturaLog::info("File modification time [" . $physicalFile->modificationTime . "] predates drop folder last timestamp [" . $this->dropFolder->lastFileTimestamp . "]. Skipping.");
             if (isset($dropFolderFilesMap[$physicalFileName])) {
                 unset($dropFolderFilesMap[$physicalFileName]);
             }
             continue;
         }
         if ($this->validatePhysicalFile($physicalFileName)) {
             $maxModificationTime = $physicalFile->modificationTime > $maxModificationTime ? $physicalFile->modificationTime : $maxModificationTime;
             KalturaLog::info('Watch file [' . $physicalFileName . ']');
             if (!array_key_exists($physicalFileName, $dropFolderFilesMap)) {
                 try {
                     $lastModificationTime = $physicalFile->modificationTime;
                     $fileSize = $physicalFile->fileSize;
                     $this->handleFileAdded($physicalFileName, $fileSize, $lastModificationTime);
                 } catch (Exception $e) {
                     KalturaLog::err("Error handling drop folder file [{$physicalFileName}] " . $e->getMessage());
                 }
             } else {
                 $dropFolderFile = $dropFolderFilesMap[$physicalFileName];
                 //if file exist in the folder remove it from the map
                 //all the files that are left in a map will be marked as PURGED
                 unset($dropFolderFilesMap[$physicalFileName]);
                 $this->handleExistingDropFolderFile($dropFolderFile);
             }
         }
     }
     foreach ($dropFolderFilesMap as $dropFolderFile) {
         $this->handleFilePurged($dropFolderFile->id);
     }
     if ($this->dropFolder->incremental && $maxModificationTime > $this->dropFolder->lastFileTimestamp) {
         $updateDropFolder = new KalturaDropFolder();
         $updateDropFolder->lastFileTimestamp = $maxModificationTime;
         $this->dropFolderPlugin->dropFolder->update($this->dropFolder->id, $updateDropFolder);
     }
 }
 /**
  * Parse content of caption asset and index it
  *
  * @action parse
  * @param string $captionAssetId
  * @throws KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND
  */
 function parseAction($captionAssetId)
 {
     $captionAsset = assetPeer::retrieveById($captionAssetId);
     if (!$captionAsset) {
         throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId);
     }
     $captionAssetItems = CaptionAssetItemPeer::retrieveByAssetId($captionAssetId);
     foreach ($captionAssetItems as $captionAssetItem) {
         /* @var $captionAssetItem CaptionAssetItem */
         $captionAssetItem->delete();
     }
     // make sure that all old items are deleted from the sphinx before creating the new ones
     kEventsManager::flushEvents();
     $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $content = kFileSyncUtils::file_get_contents($syncKey, true, false);
     if (!$content) {
         return;
     }
     $captionsContentManager = kCaptionsContentManager::getCoreContentManager($captionAsset->getContainerFormat());
     if (!$captionsContentManager) {
         return;
     }
     $itemsData = $captionsContentManager->parse($content);
     foreach ($itemsData as $itemData) {
         $item = new CaptionAssetItem();
         $item->setCaptionAssetId($captionAsset->getId());
         $item->setEntryId($captionAsset->getEntryId());
         $item->setPartnerId($captionAsset->getPartnerId());
         $item->setStartTime($itemData['startTime']);
         $item->setEndTime($itemData['endTime']);
         $content = '';
         foreach ($itemData['content'] as $curChunk) {
             $content .= $curChunk['text'];
         }
         //Make sure there are no invalid chars in the caption asset items to avoid braking the search request by providing invalid XML
         $content = kString::stripUtf8InvalidChars($content);
         $content = kXml::stripXMLInvalidChars($content);
         $item->setContent($content);
         $item->save();
     }
 }
Beispiel #3
0
 private function getServiceActionElement(KalturaActionReflector $actionReflector)
 {
     $outputTypeReflector = $actionReflector->getActionOutputType();
     $actionInfo = $actionReflector->getActionInfo();
     $actionParams = $actionReflector->getActionParams();
     $outputType = null;
     if ($outputTypeReflector) {
         $outputType = $outputTypeReflector->getType();
     }
     $actionElement = $this->_doc->createElement("action");
     $actionElement->setAttribute("name", $actionReflector->getActionName());
     foreach ($actionParams as $actionParam) {
         /* @var $actionParam KalturaParamInfo */
         $actionParamElement = $this->_doc->createElement("param");
         $actionParamElement->setAttribute("name", $actionParam->getName());
         if ($actionParam->isAssociativeArray()) {
             $actionParamElement->setAttribute("type", "map");
             $actionParamElement->setAttribute("arrayType", $actionParam->getArrayType());
         } elseif ($actionParam->isArray()) {
             $actionParamElement->setAttribute("type", "array");
             $actionParamElement->setAttribute("arrayType", $actionParam->getArrayType());
         } elseif ($actionParam->isEnum()) {
             $actionParamElement->setAttribute("type", "int");
             $actionParamElement->setAttribute("enumType", $actionParam->getType());
         } else {
             if ($actionParam->isStringEnum()) {
                 $actionParamElement->setAttribute("type", "string");
                 $actionParamElement->setAttribute("enumType", $actionParam->getType());
             } else {
                 $actionParamElement->setAttribute("type", $actionParam->getType());
             }
         }
         $actionParamElement->setAttribute("optional", $actionParam->isOptional() ? "1" : "0");
         if ($actionParam->isOptional()) {
             $defaultValue = $actionParam->getDefaultValue();
             if ($defaultValue === null) {
                 $defaultValue = "null";
             }
             switch ($actionParam->getType()) {
                 case "bool":
                     if ($defaultValue === true) {
                         $actionParamElement->setAttribute("default", "true");
                     } else {
                         if ($defaultValue === false) {
                             $actionParamElement->setAttribute("default", "false");
                         }
                     }
                     break;
                 case "bigint":
                 case "int":
                 case "float":
                 case "string":
                     $actionParamElement->setAttribute("default", $defaultValue);
                     break;
                 default:
                     if ($actionParam->isEnum()) {
                         $actionParamElement->setAttribute("default", $defaultValue);
                     } else {
                         $actionParamElement->setAttribute("default", "null");
                     }
             }
         }
         $description = $actionParam->getDescription();
         $description = $this->fixDescription($description);
         $actionParamElement->setAttribute("description", $description);
         $actionElement->appendChild($actionParamElement);
     }
     $resultElement = $this->_doc->createElement("result");
     $arrayType = null;
     if ($outputTypeReflector) {
         if ($outputTypeReflector->isAssociativeArray()) {
             $resultElement->setAttribute("type", "map");
             $arrayType = $outputTypeReflector->getArrayType();
             $resultElement->setAttribute("arrayType", $arrayType);
         } else {
             if ($outputTypeReflector->isArray()) {
                 $resultElement->setAttribute("type", "array");
                 $arrayType = $outputTypeReflector->getArrayType();
                 $resultElement->setAttribute("arrayType", $arrayType);
             } else {
                 $resultElement->setAttribute("type", $outputType);
             }
         }
     }
     $description = $actionInfo->description;
     $description = $this->fixDescription($description);
     $actionElement->setAttribute("description", kString::stripUtf8InvalidChars($description));
     $actionElement->setAttribute("enableInMultiRequest", $outputType === 'file' ? "0" : "1");
     $actionElement->appendChild($resultElement);
     return $actionElement;
 }
 private function castSimpleType($type, $var)
 {
     switch ($type) {
         case "int":
             return (int) $var;
         case "string":
             return kString::stripUtf8InvalidChars((string) $var);
         case "bool":
             if (strtolower($var) === "false") {
                 return false;
             } else {
                 return (bool) $var;
             }
         case "float":
             return (double) $var;
     }
     return null;
 }
 private function castSimpleType($type, $var)
 {
     switch ($type) {
         case "int":
             return (int) $var;
         case "string":
             return kString::stripUtf8InvalidChars((string) $var);
         case "bool":
             if (strtolower($var) === "false") {
                 return false;
             } else {
                 return (bool) $var;
             }
         case "float":
             return (double) $var;
         case "bigint":
             return (double) $var;
         case "time":
             if (!$this->disableRelativeTime) {
                 $var = kTime::getRelativeTime($var);
             }
             return $var;
     }
     return null;
 }
Beispiel #6
0
 public function doFromObject($partner, KalturaDetachedResponseProfile $responseProfile = null)
 {
     parent::doFromObject($partner);
     $this->name = kString::stripUtf8InvalidChars($this->name);
     $this->description = kString::stripUtf8InvalidChars($this->description);
     $this->adminName = kString::stripUtf8InvalidChars($this->adminName);
     $this->additionalParams = KalturaKeyValueArray::fromKeyValueArray($partner->getAdditionalParams());
     if (!$this->host) {
         $this->host = null;
     }
     if (!$this->cdnHost) {
         $this->cdnHost = null;
     }
 }
 public function doFromObject($source_object, KalturaDetachedResponseProfile $responseProfile = null)
 {
     parent::doFromObject($source_object, $responseProfile);
     $permissions = PermissionPeer::retrievePartnerLevelPermissions($source_object->getId());
     $this->permissions = KalturaPermissionArray::fromDbArray($permissions);
     $this->limits = KalturaSystemPartnerLimitArray::fromPartner($source_object);
     $this->restrictEntryByMetadata = $source_object->getShouldApplyAccessControlOnEntryMetadata();
     $dbAutoModerationEntryFilter = $source_object->getAutoModerateEntryFilter();
     if ($dbAutoModerationEntryFilter) {
         $this->autoModerateEntryFilter = new KalturaBaseEntryFilter();
         $this->autoModerateEntryFilter->fromObject($dbAutoModerationEntryFilter);
     }
     $this->partnerName = kString::stripUtf8InvalidChars($this->partnerName);
     $this->description = kString::stripUtf8InvalidChars($this->description);
     $this->adminName = kString::stripUtf8InvalidChars($this->adminName);
     if ($this->deliveryProfileIds) {
         $this->deliveryProfileIds = json_encode($this->deliveryProfileIds);
     }
 }
 public function fromPartner(Partner $partner)
 {
     parent::fromObject($partner);
     $this->name = kString::stripUtf8InvalidChars($this->name);
     $this->description = kString::stripUtf8InvalidChars($this->description);
     $this->adminName = kString::stripUtf8InvalidChars($this->adminName);
     $this->additionalParams = KalturaKeyValueArray::fromKeyValueArray($partner->getAdditionalParams());
     return $this;
 }
 public function fromObject($source_object)
 {
     parent::fromObject($source_object);
     $permissions = PermissionPeer::retrievePartnerLevelPermissions($source_object->getId());
     $this->permissions = KalturaPermissionArray::fromDbArray($permissions);
     $this->limits = KalturaSystemPartnerLimitArray::fromPartner($source_object);
     $dbAutoModerationEntryFilter = $source_object->getAutoModerateEntryFilter();
     if ($dbAutoModerationEntryFilter) {
         $this->autoModerateEntryFilter = new KalturaBaseEntryFilter();
         $this->autoModerateEntryFilter->fromObject($dbAutoModerationEntryFilter);
     }
     $this->partnerName = kString::stripUtf8InvalidChars($this->partnerName);
     $this->description = kString::stripUtf8InvalidChars($this->description);
     $this->adminName = kString::stripUtf8InvalidChars($this->adminName);
 }