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);
     }
 }
예제 #2
0
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     $this->validateForUsage($object_to_fill, $props_to_skip);
     // will check that not useable properties are not set
     $class = get_class($this);
     // enables extension with default empty object
     if (is_null($object_to_fill)) {
         KalturaLog::err("No object supplied for type [{$class}]");
         return null;
     }
     $typeReflector = KalturaTypeReflectorCacher::get($class);
     foreach ($this->getMapBetweenObjects() as $this_prop => $object_prop) {
         if (is_numeric($this_prop)) {
             $this_prop = $object_prop;
         }
         $value = $this->{$this_prop};
         if (is_null($value)) {
             continue;
         }
         if ($props_to_skip && is_array($props_to_skip) && in_array($this_prop, $props_to_skip)) {
             continue;
         }
         $propertyInfo = $typeReflector->getProperty($this_prop);
         if (!$propertyInfo) {
             KalturaLog::alert("property [{$this_prop}] was not found on object class [{$class}]");
             continue;
         }
         if ($value instanceof KalturaNullField) {
             $value = null;
         } elseif ($value instanceof KalturaTypedArray) {
             $value = $value->toObjectsArray();
         } elseif ($propertyInfo->isComplexType() && $value instanceof KalturaObject) {
             $value = $value->toObject();
         } elseif ($propertyInfo->isDynamicEnum()) {
             $propertyType = $propertyInfo->getType();
             $enumType = call_user_func(array($propertyType, 'getEnumClass'));
             $value = kPluginableEnumsManager::apiToCore($enumType, $value);
         } elseif ($propertyInfo->getDynamicType() && strlen($value)) {
             $propertyType = $propertyInfo->getDynamicType();
             $enumType = call_user_func(array($propertyType, 'getEnumClass'));
             $values = explode(',', $value);
             $finalValues = array();
             foreach ($values as $val) {
                 $finalValues[] = kPluginableEnumsManager::apiToCore($enumType, $val);
             }
             $value = implode(',', $finalValues);
         } elseif (is_string($value) && !kXml::isXMLValidContent($value)) {
             throw new KalturaAPIException(KalturaErrors::INVALID_PARAMETER_CHAR, $this_prop);
         }
         $setter_callback = array($object_to_fill, "set{$object_prop}");
         if (is_callable($setter_callback)) {
             call_user_func_array($setter_callback, array($value));
         } else {
             KalturaLog::alert("setter for property [{$object_prop}] was not found on object class [" . get_class($object_to_fill) . "] defined as property [{$this_prop}] on api class [{$class}]");
         }
     }
     return $object_to_fill;
 }
 public function getTargetUserId()
 {
     $value = $this->castSimpleType("string", $this->paramsGrouped["targetUserId"]);
     if (!kXml::isXMLValidContent($value)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_PARAMETER_CHAR, 'targetUserId');
     }
     return $value;
 }
 private function buildObject(KalturaTypeReflector $typeReflector, array &$params, $objectName)
 {
     // if objectType was specified, we will use it only if the anotation type is it's base type
     if (array_key_exists("objectType", $params)) {
         $possibleType = $params["objectType"];
         if (strtolower($possibleType) !== strtolower($typeReflector->getType())) {
             if ($typeReflector->isParentOf($possibleType)) {
                 $newTypeReflector = KalturaTypeReflectorCacher::get($possibleType);
                 if ($newTypeReflector) {
                     $typeReflector = $newTypeReflector;
                 }
             }
         }
     }
     if ($typeReflector->isAbstract()) {
         throw new KalturaAPIException(KalturaErrors::OBJECT_TYPE_ABSTRACT, $typeReflector->getType());
     }
     $class = $typeReflector->getType();
     $obj = new $class();
     $properties = $typeReflector->getProperties();
     foreach ($params as $name => $value) {
         $isNull = false;
         if (kString::endsWith($name, '__null')) {
             $name = str_replace('__null', '', $name);
             $isNull = true;
         }
         if (!array_key_exists($name, $properties)) {
             continue;
         }
         $property = $properties[$name];
         /* @var $property KalturaPropertyInfo */
         $type = $property->getType();
         if ($isNull && !$property->isArray()) {
             $obj->{$name} = new KalturaNullField();
             continue;
         }
         if ($property->isSimpleType()) {
             if ($property->isTime()) {
                 $type = "time";
             }
             $value = $this->castSimpleType($type, $value);
             if (!kXml::isXMLValidContent($value)) {
                 throw new KalturaAPIException(KalturaErrors::INVALID_PARAMETER_CHAR, $name);
             }
             $this->validateParameter($name, $value, $property);
             $obj->{$name} = $value;
             continue;
         }
         if ($property->isEnum()) {
             if (strtolower($value) == 'true') {
                 $value = 1;
             }
             if (strtolower($value) == 'false') {
                 $value = 0;
             }
             if (!$property->getTypeReflector()->checkEnumValue($value)) {
                 throw new KalturaAPIException(KalturaErrors::INVALID_ENUM_VALUE, $value, $name, $property->getType());
             }
             if ($type == 'KalturaNullableBoolean') {
                 $obj->{$name} = KalturaNullableBoolean::toBoolean($value);
                 continue;
             }
             $obj->{$name} = $this->castSimpleType("int", $value);
             continue;
         }
         if ($property->isStringEnum()) {
             if (!$property->getTypeReflector()->checkStringEnumValue($value)) {
                 throw new KalturaAPIException(KalturaErrors::INVALID_ENUM_VALUE, $value, $name, $property->getType());
             }
             $value = $this->castSimpleType("string", $value);
             if (!kXml::isXMLValidContent($value)) {
                 throw new KalturaAPIException(KalturaErrors::INVALID_PARAMETER_CHAR, $name);
             }
             $obj->{$name} = $value;
             continue;
         }
         if ($property->isArray() && is_array($value)) {
             $arrayObj = new $type();
             if ($property->isAssociativeArray()) {
                 foreach ($value as $arrayItemKey => $arrayItemParams) {
                     if ($arrayItemKey === '-') {
                         break;
                     }
                     $arrayObj[$arrayItemKey] = $this->buildObject($property->getArrayTypeReflector(), $arrayItemParams, "{$objectName}:{$name}");
                 }
             } else {
                 ksort($value);
                 foreach ($value as $arrayItemKey => $arrayItemParams) {
                     if ($arrayItemKey === '-') {
                         break;
                     }
                     $arrayObj[] = $this->buildObject($property->getArrayTypeReflector(), $arrayItemParams, "{$objectName}:{$name}");
                 }
             }
             $obj->{$name} = $arrayObj;
             continue;
         }
         if ($property->isComplexType() && is_array($value)) {
             $obj->{$name} = $this->buildObject($property->getTypeReflector(), $value, "{$objectName}:{$name}");
             continue;
         }
         if ($property->isFile()) {
             $obj->{$name} = $value;
             continue;
         }
     }
     return $obj;
 }