fs::add_version (public)

 fs::add_version -item_id item_id [ -name name ] \
    [ -package_id package_id ] [ -mime_type mime_type ] \
    [ -tmp_filename tmp_filename ] [ -content_body content_body ] \
    [ -creation_user creation_user ] [ -creation_ip creation_ip ] \
    [ -title title ] [ -description description ] \
    [ -suppress_notify_p suppress_notify_p ] \
    [ -storage_type storage_type ] [ -no_callback ]

Defined in packages/file-storage/tcl/file-storage-procs.tcl

Create a new version of a file storage item.

Switches:
-item_id (required)
-name (optional)
-package_id (optional)
-mime_type (optional)
-tmp_filename (optional)
absolute path to a file on the filesystem. when specified, the new revision data will come from this file.
-content_body (optional)
Text content for the new revision. When 'tmp_filename' is missing, the new revision data will come from here.
-creation_user (optional)
-creation_ip (optional)
-title (optional)
-description (optional)
-suppress_notify_p (optional, defaults to "f")
-storage_type (optional)
-no_callback (optional, boolean)
Returns:
revision_id

Partial Call Graph (max 5 caller/called nodes):
%3 test_fs_add_delete_copy fs_add_delete_copy (test file-storage) fs::add_version fs::add_version test_fs_add_delete_copy->fs::add_version test_fs_add_file_to_folder fs_add_file_to_folder (test file-storage) test_fs_add_file_to_folder->fs::add_version ad_conn ad_conn (public) fs::add_version->ad_conn ad_file ad_file (public) fs::add_version->ad_file callback callback (public) fs::add_version->callback content::item::set_live_revision content::item::set_live_revision (public) fs::add_version->content::item::set_live_revision content::revision::new content::revision::new (public) fs::add_version->content::revision::new fs::add_file fs::add_file (public) fs::add_file->fs::add_version fs::impl::fs_object::put fs::impl::fs_object::put (private) fs::impl::fs_object::put->fs::add_version packages/file-storage/www/file-add.tcl packages/file-storage/ www/file-add.tcl packages/file-storage/www/file-add.tcl->fs::add_version packages/file-storage/www/folder-zip-add.tcl packages/file-storage/ www/folder-zip-add.tcl packages/file-storage/www/folder-zip-add.tcl->fs::add_version

Testcases:
fs_add_delete_copy, fs_add_file_to_folder
Source code:
    if {![info exists content_body] && ![info exists tmp_filename]} {
        error "No data supplied for the new version."
    }

    #
    # Obtain optional information for the new version from the
    # existing item.
    #
    db_1row get_item_info {
        select coalesce(:storage_type, i.storage_type) as storage_type,
               coalesce(:name, i.name) as name,
               coalesce(:package_id, o.package_id) as package_id,
               coalesce(:title, r.title) as title,
               coalesce(:description, r.description) as description,
               coalesce(:mime_type, r.mime_type) as mime_type,
               i.parent_id
        from cr_items i
             -- we may not have a live revision here yet
             left join cr_revisions r
               on r.revision_id = i.live_revision,
             acs_objects o
        where i.item_id = :item_id
          and o.object_id = i.item_id
    }

    #
    # Obtain other possibly missing information from the connection
    # context.
    #
    if {$package_id eq ""} {
        set package_id [ad_conn package_id]
    }
    if {$creation_user eq ""} {
        set creation_user [ad_conn user_id]
    }
    if {$creation_ip eq ""} {
        set creation_ip [ns_conn peeraddr]
    }

    if {[info exists tmp_filename]} {
        #
        # The new revision will come from a file.
        #

        # This check also happens in content repository, but as something
        # similar was already here and mimetype coming from this was used
        # afterwards, we kept this behavior.
        set mime_type [cr_check_mime_type  -filename  $name  -mime_type $mime_type  -file      $tmp_filename]

        set tmp_size [ad_file size $tmp_filename]
        set revision_id [cr_import_content  -item_id $item_id  -storage_type $storage_type  -creation_user $creation_user  -creation_ip $creation_ip  -other_type "file_storage_object"  -image_type "file_storage_object"  -title $title  -description $description  -package_id $package_id  $parent_id  $tmp_filename  $tmp_size  $mime_type  $name]

        content::item::set_live_revision -revision_id $revision_id
    } else {
        #
        # The new revision will come from text content.
        #

        set revision_id [content::revision::new  -item_id $item_id  -title $title  -description $description  -content $content_body  -mime_type $mime_type  -creation_user $creation_user  -creation_ip $creation_ip  -package_id $package_id  -is_live "t"  -storage_type $storage_type]
    }

    # apisano - This is what we had before (postgres code):
    # begin
    # perform acs_object__update_last_modified
    # (:parent_id,:creation_user,:creation_ip);
    # perform
    # acs_object__update_last_modified(:item_id,:creation_user,:creation_ip);
    # return null;
    # end;
    # Could be refactored with the recursive query below, which will
    # not go over the context hierarchy, but over the "filesystem"
    # hierarchy, which makes more sense, and update modification
    # metadata for the whole tree.
    # However, I wonder if there is really need for all of this... If
    # there is, one should probably have this logic at the content
    # repository level, rather than here.
    db_dml update_last_modified {
        with recursive fs_hierarchy as (
            select object_id, parent_id
              from fs_objects
             where object_id = :item_id

            union

            select p.object_id, p.parent_id
              from fs_objects p,
                   fs_hierarchy c
             where p.object_id = c.parent_id
        )
        update acs_objects set
          modifying_user = :creation_user,
          modifying_ip   = :creation_ip,
          last_modified  = current_timestamp
        where object_id in (select object_id from fs_hierarchy)
    }

    if {[string is false $suppress_notify_p]} {
        fs::do_notifications  -folder_id $parent_id  -filename $title  -item_id $revision_id  -action "new_version"  -package_id $package_id
    }

    #It's safe to rebuild RSS repeatedly, assuming it's not too expensive.
    set folder_info [fs::get_folder_package_and_root $parent_id]
    set db_package_id [lindex $folder_info 0]
    if { [parameter::get -package_id $db_package_id -parameter ExposeRssP -default 0] } {
        fs::rss::build_feeds $parent_id
    }

    if {!$no_callback_p} {
        callback fs::file_revision_new  -package_id [ad_conn package_id]  -file_id $item_id  -parent_id $parent_id
    }

    return $revision_id
Generic XQL file:
<fullquery name="fs::add_version.get_storage_type">
    <querytext>
    select storage_type from cr_items where item_id=:item_id
  </querytext>
</fullquery>
packages/file-storage/tcl/file-storage-procs.xql

PostgreSQL XQL file:
packages/file-storage/tcl/file-storage-procs-postgresql.xql

Oracle XQL file:
packages/file-storage/tcl/file-storage-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: