Index: openacs-4/packages/edit-this-page/edit-this-page.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/edit-this-page.info,v
diff -u -N -r1.19 -r1.20
--- openacs-4/packages/edit-this-page/edit-this-page.info 5 Aug 2018 21:56:22 -0000 1.19
+++ openacs-4/packages/edit-this-page/edit-this-page.info 31 Jul 2024 11:48:04 -0000 1.20
@@ -7,7 +7,7 @@
f
f
-
+
postgresql
@@ -17,7 +17,7 @@
An easy-to-use content management system.
An Easy to use publishing system with versioning and permissions.
-
+
Index: openacs-4/packages/edit-this-page/www/etp-swap-oracle.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/www/Attic/etp-swap-oracle.xql,v
diff -u -N
--- openacs-4/packages/edit-this-page/www/etp-swap-oracle.xql 31 Oct 2001 04:55:52 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,32 +0,0 @@
-
-
- oracle8.1.6
-
-
-
- select tree_sortkey, item_id
- from cr_items
- where parent_id = etp.get_folder_id(:package_id)
- and tree_sortkey < :sort_key
- order by tree_sortkey desc
-
-
-
-
-
- select tree_sortkey, item_id
- from cr_items
- where tree_sortkey >= :prev_sort_key
- order by tree_sortkey
-
-
-
-
-
- update cr_items
- set tree_sortkey = :new_sortkey
- where item_id = :item_id
-
-
-
-
Index: openacs-4/packages/edit-this-page/www/etp-swap-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/www/Attic/etp-swap-postgresql.xql,v
diff -u -N
--- openacs-4/packages/edit-this-page/www/etp-swap-postgresql.xql 3 Dec 2001 18:33:37 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,32 +0,0 @@
-
-
- postgresql7.1
-
-
-
- select tree_sortkey, item_id
- from cr_items
- where parent_id = etp__get_folder_id(:package_id)
- and tree_sortkey < :sort_key
- order by tree_sortkey desc
-
-
-
-
-
- select tree_sortkey, item_id
- from cr_items
- where tree_sortkey >= :prev_sort_key
- order by tree_sortkey
-
-
-
-
-
- update cr_items
- set tree_sortkey = :new_sortkey
- where item_id = :item_id
-
-
-
-
Index: openacs-4/packages/edit-this-page/www/etp-swap.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/www/etp-swap.tcl,v
diff -u -N -r1.2 -r1.3
--- openacs-4/packages/edit-this-page/www/etp-swap.tcl 20 Jan 2018 22:42:50 -0000 1.2
+++ openacs-4/packages/edit-this-page/www/etp-swap.tcl 31 Jul 2024 11:48:04 -0000 1.3
@@ -4,11 +4,18 @@
@author Luke Pond (dlpond@pobox.com)
@creation-date 2001-06-01
- Swaps the page with the given sort order
- with the one preceding it.
+ Swaps the page with the given sort order with the one preceding
+ it.
} {
- sort_order
+ sort_order:notnull
+} -validate {
+ is_binary {
+ if {![regexp {^[0-1]+$} $sort_order]} {
+ ad_complain [_ acs-templating.Invalid_number]
+ return
+ }
+ }
}
etp::check_write_access
@@ -17,29 +24,57 @@
set package_id [ad_conn package_id]
-db_foreach get_prev_key "" {
- set prev_sort_key $tree_sortkey
- break;
-}
+set folder_id [::etp::get_folder_id $package_id]
+set prev_sort_key [db_string get_prev_key {
+ select tree_sortkey
+ from cr_items
+ where parent_id = :folder_id
+ and tree_sortkey < :sort_key
+ order by tree_sortkey desc
+ fetch first 1 rows only
+}]
+
db_transaction {
-db_foreach get_all_keys "" {
+ db_foreach get_all_keys {
+ select tree_sortkey, item_id
+ from cr_items
+ where tree_sortkey >= :prev_sort_key
+ order by tree_sortkey
+ } {
+ if {[regsub "^$prev_sort_key" $tree_sortkey $sort_key new_sortkey] ||
+ [regsub "^$sort_key" $tree_sortkey $prev_sort_key new_sortkey]} {
- if {[regsub "^$prev_sort_key" $tree_sortkey $sort_key new_sortkey] ||
- [regsub "^$sort_key" $tree_sortkey $prev_sort_key new_sortkey]} {
+ #
+ # Because tree_sortkey is unique, we need to use this
+ # swapping idiom. We assume "0" to be a safe temporary
+ # value for a sortkey.
+ #
+ db_dml c_eq_a_key {
+ update cr_items set
+ tree_sortkey = '0'
+ where tree_sortkey = :new_sortkey
+ }
- # fortunately tree_sortkey is not unique, so it doesn't matter
- # if we temporarily have two rows with the same key here.
+ db_dml a_eq_b_key {
+ update cr_items set
+ tree_sortkey = :new_sortkey
+ where item_id = :item_id
+ }
- db_dml update_key ""
+ db_dml b_eq_c_key {
+ update cr_items set
+ tree_sortkey = :tree_sortkey
+ where tree_sortkey = '0'
+ }
- } else {
- # because of how we ordered the select, we're done.
- # db_foreach will flush the remaining result rows.
- break
+ } else {
+ # because of how we ordered the select, we're done.
+ # db_foreach will flush the remaining result rows.
+ break
+ }
}
-}
}