%3 ::xowiki::UploadFile ::xowiki::UploadFile store_file ::xowiki::Upload ::xowiki::Upload store_file ::xowiki::UploadFile->::xowiki::Upload ::xowiki::UploadPhotoForm ::xowiki::UploadPhotoForm store_file ::xowiki::UploadPhotoForm->::xowiki::Upload ::nx::Object ::nx::Object ::xowiki::Upload->::nx::Object

Class ::xowiki::UploadPhotoForm

::xowiki::UploadPhotoForm[i] create ... \
           [ -content_type content_type ] \
           [ -file_name file_name ] \
           [ -parent_object parent_object ] \
           [ -tmpfile tmpfile ]

Class for storing files as instances of photo.form.
Defined in packages/xowiki/tcl/xowiki-uploader-procs.tcl

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::xowiki::Upload[i]
::nx::Class create ::xowiki::UploadPhotoForm \
     -superclass ::xowiki::Upload

Methods (to be applied on instances)

  • store_file (scripted, public)

     <instance of xowiki::UploadPhotoForm[i]> store_file

    Ignore everything, which does not have an image/* mime type.

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    if {![string match image/* ${:content_type}]} {
      ns_log notice "ignore store_file operation for ${:file_name} mimetype ${:content_type}"
      return {status_code 200 message ok}
    }
    #
    # Mime type is ok, save the file under the filename either as a
    # new item or as a new revision.
    #
    set package_id [${:parent_object} package_id]
    set parent_id [${:parent_object} item_id]
    
    set photo_object [::$package_id get_page_from_name -name en:${:file_name} -parent_id $parent_id]
    if {$photo_object ne ""} {
      #
      # The photo page instance exists already, create a new revision.
      #
      ns_log notice "Photo ${:file_name} exists already"
      $photo_object set title ${:file_name}
      set f [::xowiki::formfield::file new -object $photo_object -name "image" -destroy_on_cleanup]
      $f set value ${:file_name}
      $f content-type ${:content_type}
      $f set tmpfile ${:tmpfile}
      $f convert_to_internal
      $photo_object save
    } else {
      #
      # Create a new page instance of photo.form.
      #
      ns_log notice "new Photo ${:file_name}"
      set photoFormObj [::$package_id instantiate_forms  -parent_id $parent_id -forms en:photo.form]
      set photo_object [$photoFormObj create_form_page_instance  -name en:${:file_name}  -nls_language en_US  -creation_user [::xo::cc user_id]  -parent_id $parent_id  -package_id $package_id  -instance_attributes [list image [list name ${:file_name}]]]
      $photo_object title ${:file_name}
      $photo_object publish_status "ready"
      $photo_object save_new ;# to obtain item_id needed by the form-field
      set f [::xowiki::formfield::file new -object $photo_object -name "image" -destroy_on_cleanup]
      $f set value ${:file_name}
      $f content-type ${:content_type}
      $f set tmpfile ${:tmpfile}
      $f convert_to_internal
    }
    
    return {status_code 201 message created}