Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-image.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-image.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-image.sql 27 Sep 2001 22:48:16 -0000 1.3 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-image.sql 15 Nov 2001 01:47:13 -0000 1.4 @@ -104,6 +104,22 @@ Binary file stored in file-system */ +-- DRB: This code has some serious problem, IMO. It's impossible to derive a new +-- type from "image" and make use of it, for starters. Photo-album uses two +-- content types to store a photograph - pa_photo and image. pa_photo would, in +-- the world of real object-oriented languages, be derived from image and there's +-- really no reason not to do so in the OpenACS object type system. The current +-- style requires separate content_items and content_revisions for both the +-- pa_photo extended type and the image base type. They're only tied together +-- by the coincidence of both being the live revision at the same time. Delete +-- one or the other and guess what, that association's broken! + +-- This is not, to put it mildly, clean. Nor is it efficient to fill the RDBMS +-- with twice as many objects as you need... + +-- The Oracle version does allow a non-image type to be specified, as does my +-- alternative down below. This needs a little more straightening out. + create function image__new (varchar,integer,integer,integer,varchar,integer,varchar,varchar,varchar,varchar,boolean,timestamp,varchar,integer,integer,integer ) returns integer as ' declare @@ -196,6 +212,118 @@ return v_item_id; end; ' language 'plpgsql'; +-- DRB's version + +create function image__new (varchar,integer,integer,integer,varchar,integer,varchar,varchar,varchar,varchar,varchar, + varchar,timestamp,integer, integer) returns integer as ' + declare + p_name alias for $1; + p_parent_id alias for $2; -- default null + p_item_id alias for $3; -- default null + p_revision_id alias for $4; -- default null + p_mime_type alias for $5; -- default jpeg + p_creation_user alias for $6; -- default null + p_creation_ip alias for $7; -- default null + p_title alias for $8; -- default null + p_description alias for $9; -- default null + p_storage_type alias for $10; + p_content_type alias for $11; + p_nls_language alias for $12; + p_publish_date alias for $13; + p_height alias for $14; + p_width alias for $15; + + v_item_id cr_items.item_id%TYPE; + v_revision_id cr_revisions.revision_id%TYPE; + begin + + if content_item__is_subclass(p_content_type, ''image'') = ''f'' then + raise EXCEPTION ''-20000: image__new can only be called for an image type''; + end if; + + v_item_id := content_item__new ( + p_name, + p_parent_id, + p_item_id, + null, + current_timestamp, + p_creation_user, + p_parent_id, + p_creation_ip, + ''content_item'', + p_content_type, + null, + null, + null, + null, + null, + p_storage_type + ); + + -- We will let the caller fill in the LOB data or file path. + + v_revision_id := content_revision__new ( + p_title, + p_description, + p_publish_date, + p_mime_type, + p_nls_language, + null, + v_item_id, + p_revision_id, + current_timestamp, + p_creation_user, + p_creation_ip + ); + + insert into images + (image_id, height, width) + values + (v_revision_id, p_height, p_width); + + return v_item_id; +end; ' language 'plpgsql'; + +create function image__new_revision(integer, integer, varchar, varchar, timestamp, varchar, varchar, + integer, varchar, integer, integer) returns integer as ' +declare + p_item_id alias for $1; + p_revision_id alias for $2; + p_title alias for $3; + p_description alias for $4; + p_publish_date alias for $5; + p_mime_type alias for $6; + p_nls_language alias for $7; + p_creation_user alias for $8; + p_creation_ip alias for $9; + p_height alias for $10; + p_width alias for $11; + +begin + -- We will let the caller fill in the LOB data or file path. + + v_revision_id := content_revision__new ( + p_title, + p_description, + p_publish_date, + p_mime_type, + p_nls_language, + null, + p_item_id, + p_revision_id, + current_timestamp, + p_creation_user, + p_creation_ip + ); + + insert into images + (image_id, height, width) + values + (v_revision_id, p_height, p_width); + + return v_revision_id; +end;' language 'plpgsql'; + create function image__delete (integer) returns integer as ' declare @@ -220,4 +348,3 @@ PERFORM content_item__delete (v_item_id); return 1; end; ' language 'plpgsql'; -