--
-- image__new_revision/12
--
create or replace function image__new_revision(
  p_item_id integer,
  p_revision_id integer,
  p_title character varying,
  p_description character varying,
  p_publish_date timestamp with time zone,
  p_mime_type character varying,
  p_nls_language character varying,
  p_creation_user integer,
  p_creation_ip character varying,
  p_height integer,
  p_width integer,
  p_package_id integer DEFAULT NULL::integer
) returns int4 as $$

DECLARE
   v_revision_id      integer;
   v_package_id       acs_objects.package_id%TYPE;
BEGIN
    -- We will let the caller fill in the LOB data or file path.

    if p_package_id is null then
      v_package_id := acs_object__package_id(p_item_id);
    else
      v_package_id := p_package_id;
    end if;

    v_revision_id := content_revision__new (
      p_title,
      p_description,
      p_publish_date,
      p_mime_type,
      p_nls_language,
      null,               -- content_length
      p_item_id,
      p_revision_id,
      current_timestamp,
      p_creation_user,
      p_creation_ip,
      null,               -- content_length
      v_package_id
    );

    insert into images
    (image_id, height, width)
    values
    (v_revision_id, p_height, p_width);

    return v_revision_id;
END;
$$ language plpgsql;