/**
  * Binds an UploadFileDescription with the target instance.
  *
  * @access protected
  * @author Jerome Bogaerts <*****@*****.**>
  * @param  Property property The property to bind the data.
  * @param  UploadFileDescription desc the upload file description.
  * @return void
  */
 protected function bindUploadFileDescription(core_kernel_classes_Property $property, tao_helpers_form_data_UploadFileDescription $desc)
 {
     $instance = $this->getTargetInstance();
     // Delete old files.
     foreach ($instance->getPropertyValues($property) as $oF) {
         $oldFile = new core_kernel_versioning_File($oF);
         $oldFile->delete(true);
     }
     $name = $desc->getName();
     $size = $desc->getSize();
     if (!empty($name) && !empty($size)) {
         // Move the file at the right place.
         $source = $desc->getTmpPath();
         $repository = tao_models_classes_TaoService::singleton()->getUploadFileSource();
         $file = $repository->spawnFile($source, $desc->getName());
         tao_helpers_File::remove($source);
         $instance->setPropertyValue($property, $file->getUri());
         // Update the UploadFileDescription with the stored file.
         $desc->setFile($file);
     }
 }
 /**
  * Binds an UploadFileDescription with the target instance.
  *
  * @access protected
  * @author Jerome Bogaerts <*****@*****.**>
  * @param  core_kernel_classes_Property $property The property to bind the data.
  * @param  tao_helpers_form_data_UploadFileDescription $desc the upload file description.
  * @return void
  */
 protected function bindUploadFileDescription(core_kernel_classes_Property $property, tao_helpers_form_data_UploadFileDescription $desc)
 {
     $instance = $this->getTargetInstance();
     // If form has delete action, remove file
     if ($desc->getAction() == tao_helpers_form_data_UploadFileDescription::FORM_ACTION_DELETE) {
         $this->removeFile($property);
     } elseif ($desc->getAction() == tao_helpers_form_data_UploadFileDescription::FORM_ACTION_ADD) {
         $name = $desc->getName();
         $size = $desc->getSize();
         if (!empty($name) && !empty($size)) {
             // Remove old
             $this->removeFile($property);
             // Move the file at the right place.
             $source = $desc->getTmpPath();
             $serial = tao_models_classes_TaoService::singleton()->storeUploadedFile($source, $name);
             tao_helpers_File::remove($source);
             // Create association between item & file, database side
             $instance->editPropertyValues($property, $serial);
             // Update the UploadFileDescription with the stored file.
             $desc->setFile($serial);
         }
     }
 }