Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql,v
diff -u -r1.72.2.7 -r1.72.2.8
--- openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql	16 May 2016 10:38:40 -0000	1.72.2.7
+++ openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql	27 Nov 2016 10:10:37 -0000	1.72.2.8
@@ -1574,38 +1574,46 @@
 $$ LANGUAGE plpgsql stable strict;
 
 
-select define_function_args('content_item__set_live_revision','revision_id,publish_status;ready,publish_date;now()');
+select define_function_args('content_item__set_live_revision','revision_id,publish_status;ready,publish_date;now(),is_latest;f');
 --
--- procedure content_item__set_live_revision/1,2,3
+-- procedure content_item__set_live_revision/1,2,3,4
 --
 CREATE OR REPLACE FUNCTION content_item__set_live_revision(
-   set_live_revision__revision_id integer,
-   set_live_revision__publish_status varchar default 'ready',
-   set_live_revision__publish_date timestamptz default now()
+   p__revision_id integer,
+   p__publish_status varchar default 'ready',
+   p__publish_date timestamptz default now(),
+   p__is_latest boolean default false
 ) RETURNS integer AS $$
 DECLARE
 BEGIN
 
-  update
-    cr_items
+  if p__is_latest then
+    update cr_items
+      set
+            live_revision = p__revision_id,
+    	    publish_status = p__publish_status,
+            latest_revision = p__revision_id   
+      where
+	    item_id = (select item_id
+               from   cr_revisions
+               where  revision_id = p__revision_id);
+  else
+    update cr_items
+      set
+            live_revision = p__revision_id,
+    	    publish_status = p__publish_status
+      where
+	    item_id = (select item_id
+               from   cr_revisions
+               where  revision_id = p__revision_id);
+  end if;
+   
+  update cr_revisions
   set
-    live_revision = set_live_revision__revision_id,
-    publish_status = set_live_revision__publish_status
+    publish_date = p__publish_date
   where
-    item_id = (select
-                 item_id
-               from
-                 cr_revisions
-               where
-                 revision_id = set_live_revision__revision_id);
+    revision_id = p__revision_id;
 
-  update
-    cr_revisions
-  set
-    publish_date = set_live_revision__publish_date
-  where
-    revision_id = set_live_revision__revision_id;
-
   return 0; 
 END;
 $$ LANGUAGE plpgsql;
