publish::write_content (public)

 publish::write_content revision_id [ args... ]

Defined in packages/acs-content-repository/tcl/publish-procs.tcl

Parameters:
revision_id - The id of the revision to write
Options:
-item_id
{default The item_id of the revision} Specifies the item to which this revision belongs (merely for optimization purposes)
-text
If specified, indicates that the content of the revision is readable text (clob), not a binary file
-root_path
{default All paths in the PublishPaths parameter} Write the content to this path only.
Returns:
The relative URL of the file that was written, or an empty string on failure
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 publish::handle_binary_file publish::handle_binary_file (public) publish::write_content publish::write_content publish::handle_binary_file->publish::write_content content::item::content_is_null content::item::content_is_null (public) publish::write_content->content::item::content_is_null content::item::get content::item::get (public) publish::write_content->content::item::get content::item::get_virtual_path content::item::get_virtual_path (public) publish::write_content->content::item::get_virtual_path db_exec_plsql db_exec_plsql (public) publish::write_content->db_exec_plsql db_string db_string (public) publish::write_content->db_string

Testcases:
No testcase defined.
Source code:

  template::util::get_opts $args

  if { ![info exists opts(root_path)] } {
    set root_path ""
  } else {
    set root_path $opts(root_path)
  }

  db_transaction {

      # Get the item id if none specified
      if { ![info exists opts(item_id)] } {
          set item_id [db_string get_one_revision ""]

      if { [template::util::is_nil item_id] } {
          ns_log warning "publish::write_content: No such revision $revision_id"
          return ""
      }
      } else {
      set item_id $opts(item_id)
      }


      #set file_url [item::get_extended_url $item_id -revision_id $revision_id]
      set base_path [content::item::get_virtual_path -item_id $item_id]
      content::item::get -item_id $item_id -array_name item_info
      set mime_type $item_info(mime_type)
      set ext [db_string get_extension {
      select file_extension from cr_mime_types where mime_type = :mime_type
      }]
      set file_url $base_url.$ext

      # LARS HACK: Delete the file if it already exists
      # Not sure what we should really do here, since on the one hand, the below db commands
      # crap out if the file already exists, but on the other hand, we shouldn't accidentally
      # overwrite files
      if { [file exists $root_path$file_url] } {
          file delete -- $root_path$file_url
      }

      # Write blob/text to file
      ns_log debug " publish::write_content: writing item $item_id to $file_url"

      if { [info exists opts(text)] } {
          db_transaction {
              db_exec_plsql gcv_get_revision_id {
                  begin
                  content_revision.to_temporary_clob(:revision_id);
                  end;
              }

              # Query for values from a previous revision

              set text [db_string gcv_get_previous_content ""]
          }

      write_multiple_files $file_url $text $root_path
      } else {

      # Determine if the blob is null. If it is, give up (or else the
      # ns_ora blob_get_file will crash).
      if { [content::item::content_is_null $revision_id] } {
          ns_log warning "publish::write_content: No content supplied for revision $revision_id"
          return ""
      }

      # Write the blob
      write_multiple_blobs $file_url $revision_id $root_path
      }
  }

  # Return either the full path or the relative URL
  return $file_url
Generic XQL file:
<fullquery name="publish::write_content.get_one_revision">
    <querytext>

             select item_id from cr_revisions where revision_id = :revision_id

      </querytext>
</fullquery>
packages/acs-content-repository/tcl/publish-procs.xql

PostgreSQL XQL file:
<fullquery name="publish::write_content.get_previous_content">
    <querytext>

    select
      content
    from
      cr_revisions
    where
      revision_id = :revision_id

      </querytext>
</fullquery>
packages/acs-content-repository/tcl/publish-procs-postgresql.xql

Oracle XQL file:
<fullquery name="publish::write_content.get_previous_content">
    <querytext>

                       select
                         content
                       from
                         cr_content_text
                       where
                         revision_id = :revision_id

      </querytext>
</fullquery>
packages/acs-content-repository/tcl/publish-procs-oracle.xql

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