Esempio n. 1
0
 public function validateForUpdate($sourceObject, $propertiesToSkip = array())
 {
     $updatableProperties = array();
     $className = get_class($this);
     $reflector = KalturaTypeReflectorCacher::get($className);
     $properties = $reflector->getProperties();
     if ($reflector->requiresUpdatePermission() && !kPermissionManager::getUpdatePermitted($className, kApiParameterPermissionItem::ALL_VALUES_IDENTIFIER)) {
         throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $className);
     }
     foreach ($properties as $property) {
         $propertyName = $property->getName();
         if (in_array($propertyName, $propertiesToSkip)) {
             continue;
         }
         if ($this->{$propertyName} !== null) {
             // check if property value is being changed - if not, just continue to the next
             $objectPropertyName = $this->getObjectPropertyName($propertyName);
             $getter_callback = array($sourceObject, "get{$objectPropertyName}");
             if (is_callable($getter_callback)) {
                 $value = call_user_func($getter_callback);
                 if ($value === $this->{$propertyName} || is_bool($this->{$propertyName}) && $value === (int) $this->{$propertyName}) {
                     continue;
                 }
             }
             if ($property->isReadOnly() || $property->isInsertOnly()) {
                 throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NOT_UPDATABLE, $this->getFormattedPropertyNameWithClassName($propertyName));
             }
             // property requires update permissions, verify that the current user has it
             if ($property->requiresUpdatePermission()) {
                 if (!kPermissionManager::getUpdatePermitted($this->getDeclaringClassName($propertyName), $propertyName)) {
                     //throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     //TODO: not throwing exception to not break clients that sends -1 as null for integer values (etc...)
                     KalturaLog::err('Current user has not update permission for property ' . $this->getFormattedPropertyNameWithClassName($propertyName));
                     $e = new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_NO_UPDATE_PERMISSION, $this->getFormattedPropertyNameWithClassName($propertyName));
                     $this->{$propertyName} = null;
                     header($this->getDeclaringClassName($propertyName) . '-' . $propertyName . ' error: ' . $e->getMessage());
                 }
             }
             $this->validateHtmlTags($className, $property);
         }
     }
     return $updatableProperties;
 }