Index: openacs-4/packages/acs-admin/www/apm/index-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/www/apm/index-postgresql.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-admin/www/apm/index-postgresql.xql 27 Apr 2001 01:41:12 -0000 1.1 +++ openacs-4/packages/acs-admin/www/apm/index-postgresql.xql 4 May 2001 06:04:28 -0000 1.2 @@ -13,7 +13,7 @@ and v2.installed_p and apm_package_version__sortable_version_name(v2.version_name) > apm_package_version__sortable_version_name(v.version_name)) as superseded_p, - (select count(*) where distribution_tarball is not null) as tarball_p + (select count(*) where item_id is not null) as tarball_p from apm_package_versions v, apm_package_types t where t.package_key = v.package_key [ad_dimensional_sql $dimensional_list where and] Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql,v diff -u -r1.15 -r1.16 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql 3 May 2001 04:00:49 -0000 1.15 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql 4 May 2001 06:04:28 -0000 1.16 @@ -205,7 +205,14 @@ create unique index cr_items_unique_id on cr_items(parent_id, item_id); create index cr_items_by_parent_id on cr_items(parent_id); +-- DCW, this can't be defined in the apm_package_versions table defintion, +-- because cr_items is created afterwards. +alter table apm_package_versions add + constraint apm_package_ver_item_id_fk + foreign key (item_id) references cr_items(item_id); + + create function cr_items_tree_insert_tr () returns opaque as ' declare v_parent_sk varchar; Index: openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql,v diff -u -r1.14 -r1.15 --- openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql 28 Apr 2001 17:35:30 -0000 1.14 +++ openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql 4 May 2001 06:04:28 -0000 1.15 @@ -261,8 +261,13 @@ cvs_import_results text, activation_date timestamp, deactivation_date timestamp, - -- FIXME: use this as the blob_id - distribution_tarball integer, + -- FIXME: store the tarball in the content-repository + -- distribution_tarball blob, + item_id integer, + -- This constraint can't be adde yet, as the cr_items table + -- has not been created yet. + -- constraint apm_package_ver_item_id_fk + -- references cr_items(item_id), distribution_uri varchar(1500), distribution_date timestamp, constraint apm_package_vers_id_name_un unique(package_key, version_name) @@ -369,11 +374,9 @@ XXX (bquinn): do we really care about this enough to keep the information around? '; -comment on column apm_package_versions.distribution_tarball is ' - The archive of the distribution. - XXX (bquinn): This should definitely be moved - to the content repository and renamed distribution_archive, or simply - stored in the file system. +comment on column apm_package_versions.item_id is ' + item_id is a reference to the distribution_tarball which is stored in the content + repository. '; comment on column apm_package_versions.distribution_uri is ' @@ -649,7 +652,7 @@ v.activation_date, v.deactivation_date, -- dbms_lob.getlength(distribution_tarball) tarball_length, -- FIXME: - 0 as tarball_length, + case when item_id is not null then 1 else 0 end as tarball_length, distribution_uri, distribution_date from apm_package_types t, apm_package_versions v where v.package_key = t.package_key; Index: openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 3 May 2001 04:25:30 -0000 1.9 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 4 May 2001 06:04:28 -0000 1.10 @@ -385,6 +385,12 @@ if {[regexp {^[0-9]+$} $val match]} { ns_pg blob_select_file $db $val $file + } elseif {[file exists $val]} { + set ifp [open $val r] + set ofp [open $file w] + ns_cpfp $ifp $ofp + close $ifp + close $ofp } else { error "lob id is not an integer" } Index: openacs-4/packages/acs-tcl/tcl/apm-file-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-file-procs-oracle.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-tcl/tcl/apm-file-procs-oracle.xql 27 Apr 2001 17:39:16 -0000 1.3 +++ openacs-4/packages/acs-tcl/tcl/apm-file-procs-oracle.xql 4 May 2001 06:04:28 -0000 1.4 @@ -2,6 +2,64 @@ oracle8.1.6 + + + + +begin + :1 := content_item.new(name => 'tarball-for-package-version-${version_id}', + creation_ip => :creation_ip + ); +end; + + + + + + + + begin + :1 := content_revision.new(title => '${package_key}-tarball', + description => 'gzipped tarfile', + text => 'not_important', + mime_type => 'application/x-compressed', + item_id => :item_id, + creation_user => :user_id, + creation_ip => :creation_ip + ); + + update cr_items + set live_revision = :1 + where item_id = :item_id; + end; + + + + + + + + update cr_revisions + set content = empty_blob() + where revision_id = :revision_id + returning content into :1 + + + + + + + + + select content + from cr_revisions + where revision_id = (select content_item.get_latest_revision(item_id) + from apm_package_versions + where version_id = :version_id) + + + + Index: openacs-4/packages/acs-tcl/tcl/apm-file-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-file-procs-postgresql.xql,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-tcl/tcl/apm-file-procs-postgresql.xql 27 Apr 2001 17:39:16 -0000 1.7 +++ openacs-4/packages/acs-tcl/tcl/apm-file-procs-postgresql.xql 4 May 2001 06:04:28 -0000 1.8 @@ -3,22 +3,85 @@ postgresql7.1 - - + - FIX ME LOB (DRB - *all* large objects should be handled by the content - repository so I'm leaving this wart for now. - update apm_package_versions - set distribution_tarball = empty_blob(), - distribution_uri = null, - distribution_date = sysdate - where version_id = :version_id - returning distribution_tarball into :1 - + +select content_item__new( + 'tarball-for-package-version-${version_id}', + null, + null, + null, + now(), + null, + null, + :creation_ip, + 'content_item', + 'content_revision', + null, + null, + 'text/plain', + null, + null, + 'file' + ) + + + + + declare + v_revision_id integer; + begin + + v_revision_id := content_revision__new( + '${package_key}-tarball', + 'gzipped tarfile', + now(), + 'text/plain', + null, + 'not_important', + :item_id, + null, + now(), + :user_id, + :creation_ip + ); + + update cr_items + set live_revision = v_revision_id + where item_id = :item_id; + + return v_revision_id; + + end; + + + + + + + + update cr_revisions + set content = '[cr_create_content_file $item_id $revision_id $tmpfile]' + where revision_id = :revision_id + + + + + + + select '[cr_fs_path]' || content + from cr_revisions + where revision_id = (select content_item__get_latest_revision(item_id) + from apm_package_versions + where version_id = :version_id) + + + + Index: openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl 20 Apr 2001 22:05:47 -0000 1.4 +++ openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl 4 May 2001 06:04:28 -0000 1.5 @@ -104,10 +104,20 @@ overwriting any existing files. } { + set apm_file [ns_tmpnam] - db_blob_get_file distribution_tar_ball_select "select distribution_tarball from apm_package_versions where version_id = :version_id" $apm_file + db_blob_get_file distribution_tar_ball_select { + select content + from cr_revisions + where revision_id = (select content_item.get_latest_revision(item_id) + from apm_package_versions + where version_id = :version_id) + } $apm_file + + #db_blob_get_file distribution_tar_ball_select "select distribution_tarball from apm_package_versions where version_id = :version_id" $apm_file + file mkdir $dir # cd, gunzip, and untar all in the same subprocess (to avoid having to # chdir first). @@ -118,7 +128,8 @@ ad_proc -private apm_generate_tarball { version_id } { - Generates a tarball for a version, placing it in the version's distribution_tarball blob. + Generates a tarball for a version, placing it in the content repository. + DCW - 2001-05-03, change to use the content repository for tarball storage. } { set files [apm_version_file_list $version_id] @@ -148,15 +159,71 @@ # At this point, the APM tarball is sitting in $tmpfile. Save it in the database. - db_dml apm_tarball_insert { - update apm_package_versions - set distribution_tarball = empty_blob(), - distribution_uri = null, - distribution_date = sysdate - where version_id = :version_id - returning distribution_tarball into :1 - } -blob_files [list $tmpfile] + set creation_ip [ad_conn peeraddr] + set user_id [ad_verify_and_get_user_id] + set create_item " + begin + :1 := content_item.new(name => 'tarball-for-package-version-${version_id}', + creation_ip => :creation_ip + ); + end;" + + set create_revision " + begin + :1 := content_revision.new(title => '${package_key}-tarball', + description => 'gzipped tarfile', + text => 'not_important', + mime_type => 'text/plain', + item_id => :item_id, + creation_user => :user_id, + creation_ip => :creation_ip + ); + + update cr_items + set live_revision = :1 + where item_id = :item_id; + end;" + + set update_tarball " + update cr_revisions + set content = empty_blob() + where revision_id = :revision_id + returning content into :1" + + db_1row item_exists_p {select case when item_id is null then 0 else item_id end as item_id + from apm_package_versions + where version_id = :version_id} + + if {!$item_id} { + # content item hasen't been created yet - create one. + + set item_id [db_exec_plsql create_item $create_item] + db_dml set_item_id "update apm_package_versions + set item_id = :item_id + where version_id = :version_id" + set revision_id [db_exec_plsql create_revision $create_revision] + db_dml update_tarball $update_tarball -blob_files [list $tmpfile] + + } else { + #tarball exists, so all we have to do is to make a new revision for it + #Let's check if a current revision exists: + if {![db_0or1row get_revision_id "select live_revision as revision_id + from cr_items + where item_id = :item_id"] || [empty_string_p $revision_id]} { + # It's an insert rather than an update + + set revision_id [db_exec_plsql create_revision $create_revision] + db_dml update_tarball $update_tarball -blob_files [list $tmpfile] + + } else { + # it's merely an update + + db_dml update_tarball $update_tarball -blob_files [list $tmpfile] + + } + } + file delete $tmpfile } Index: openacs-4/packages/acs-tcl/tcl/apm-file-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-file-procs.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-tcl/tcl/apm-file-procs.xql 24 Apr 2001 23:59:24 -0000 1.2 +++ openacs-4/packages/acs-tcl/tcl/apm-file-procs.xql 4 May 2001 06:04:28 -0000 1.3 @@ -1,18 +1,42 @@ - + - select file_type_key from apm_package_file_types + + select case when item_id is null then 0 else item_id end as item_id + from apm_package_versions + where version_id = :version_id + - + - select distribution_tarball from apm_package_versions where version_id = :version_id + + update apm_package_versions + set item_id = :item_id + where version_id = :version_id + + + + + select live_revision as revision_id + from cr_items + where item_id = :item_id + + + + + + + + select file_type_key from apm_package_file_types + +