Forum OpenACS Development: Re: Error in deleting a version in file-storage

Collapse
Posted by Claudio Pasolini on
I remember that there was two funcions with the same name, one of wich was broken. You should therefore drop the function calling content_revision__del and keep only this:
create or replace function content_revision__delete (integer)
returns integer as '
declare
  delete__revision_id    alias for $1;
  v_item_id              cr_items.item_id%TYPE;
  v_latest_revision      cr_revisions.revision_id%TYPE;
  v_live_revision        cr_revisions.revision_id%TYPE;
  v_rec                  record;
begin

  -- Get item id and latest/live revisions
  select item_id into v_item_id from cr_revisions
    where revision_id = delete__revision_id;

  select
    latest_revision, live_revision
  into
    v_latest_revision, v_live_revision
  from
    cr_items
  where
    item_id = v_item_id;

  -- Recalculate latest revision
  if v_latest_revision = delete__revision_id then
      for v_rec in
          select r.revision_id
            from cr_revisions r, acs_objects o
           where o.object_id = r.revision_id
             and r.item_id = v_item_id
             and r.revision_id <> delete__revision_id
        order by o.creation_date desc
      LOOP

          v_latest_revision := v_rec.revision_id;
          exit;
      end LOOP;
      if NOT FOUND then
         v_latest_revision := null;
      end if;

      update cr_items set latest_revision = v_latest_revision
      where item_id = v_item_id;
  end if;

  -- Clear live revision
  if v_live_revision = delete__revision_id then
    update cr_items set live_revision = null
      where item_id = v_item_id;
  end if;

  -- Clear the audit
  delete from cr_item_publish_audit
    where old_revision = delete__revision_id
       or new_revision = delete__revision_id;

  -- Delete the revision
  PERFORM acs_object__delete(delete__revision_id);

  return 0;
end;' language 'plpgsql';

select define_function_args('content_revision__delete','revision_id');

create or replace function content_revision__delete (integer) returns integer as ' declare delete__revision_id alias for $1; begin PERFORM content_revision__del(delete__revision_id); return 0; end;' language 'plpgsql';