Forum OpenACS Development: Re: file-storage items on table cr_items

Collapse
Posted by Dave Bauer on
Wait,

its impossible to get a duplicate name for the same parent_id, as there is a unique constraint.

Iuri can you give us more details why fs::get_folder would break?

Collapse
Posted by Iuri Sampaio on
Because now the API can not find and return the folder_id of a folder inside a parent directory using its name. Since ajax_ui creates its own unique name hidden from the user.

Furthermore, to answer hamilton's question...
if we create a folder and then rename it, the cr_item.name remains the same with the first name instead of the new one.

Hamilton is correct we could do the same as in the new subsite ad_form with pretty_name,name and url

I am using fs::get_folder to validate if there is already a folder using that name. if so bring me its id because i am gonna use it

set package_id [ad_conn package_id]
set root_folder_id [fs_get_root_folder -package_id $package_id]

set parent_id [fs::get_folder -name "contatos" -parent_id $root_folder_id]

#if exists no folders as party_id
set folder__id [fs::get_folder -name "$party_id" -parent_id $parent_id]

if {![exists_and_not_null folder_id]} {
[fs::new_folder -name $party_id -pretty_name $party_id -parent_id $parent_id -creation_user $party_id]
}

So, this is a particular issue i had. I don't know what is the best to do and what this fixing implies along the cr_item table and relations.

Or even if it is very relevant except for my situation.

My view is to follow the standards and make it the simplest way. Let's do it 😊

Collapse
Posted by Hamilton Chua on
Iuri,

Thanks for elaborating. I agree with Dave, it's not necessarily an AjaxFS issue, it might be an issue with fs::rename.

I looked at one installation with File Storage and the sql for fs::rename_folder looks like this

***************

select content_folder__edit_name(
:folder_id,
null,
:name,
null

****************

the plsql proc for content_folder__edit_name looks like

****************
declare
edit_name__folder_id alias for $1;
edit_name__name alias for $2; -- default null
edit_name__label alias for $3; -- default null
edit_name__description alias for $4; -- default null
v_name_already_exists_p integer;
begin

if edit_name__name is not null and edit_name__name != '' then
PERFORM content_item__edit_name(edit_name__folder_id, edit_name__name);
end if;

if edit_name__label is not null and edit_name__label != '' then
update acs_objects
set title = edit_name__label
where object_id = edit_name__folder_id;
end if;

if edit_name__label is not null and edit_name__label != '' and
edit_name__description is not null and edit_name__description != '' then

update cr_folders
set label = edit_name__label,
description = edit_name__description
where folder_id = edit_name__folder_id;

else if(edit_name__label is not null and edit_name__label != '') and
(edit_name__description is null or edit_name__description = '') then
update cr_folders
set label = edit_name__label
where folder_id = edit_name__folder_id;

end if; end if;

return 0;
end;
****************

The plsql proc has code to rename the cr.item name BUT since that parameter is getting "null" it's not doing the rename. Only cr_folder.label and acs_objects.title are changed.