Forum OpenACS Development: file-storage items on table cr_items

Collapse
Posted by Iuri Sampaio on
I realized that filestorage was creating new folders with the field "name" on table cr_items with all records as "file-storage-new-folder"

Moreover some APIs such as fs::get_folder broke because it searches the folder id using as arguments the name and the parent_folder_id

This behavior happens only when ajax-file-storage-ui is set up.

I believe the issue must be anything in the javascript code.
I test without ajax it worked fine except for the special char issues.

Ajax still is a bit tricky to me.
I will give a shot anyway and post here.

if someone has ever fixed this before,please let me know

Collapse
Posted by Hamilton Chua on
I believe this stems from the behavior where AjaxFS creates a blank folder first. It appears as a textfield in the tree, when you enter a new folder name, it does a rename of the folder from "New Folder".

I think the name defaults to

"file-storage-new-folder-$unique_id"

I hate to answer a question with a question or two BUT ...

In regular file storage with no AjaxFS, if you create a folder and then rename that folder, does fs::get_folder still work ? Where and how are you using fs::get_folder ?

On the AjaxFS side, we could fix this by asking the user for the foldername before creating a folder instead of the current behavior.

However, before I attempt the fix I would like to know how you and other devs are using fs:get_folder and the other fs api where you pass the name as a parameter specially after a folder or file has been renamed.

Collapse
Posted by Dave Bauer on
This issue is, somehwhere when the folder is renamed the label is set but the cr_items.name is not also updated to match.

This might be in ajaxfs or in file-storage itself.

Collapse
Posted by Michael Steigman on
Check out content_item__edit_name and content_item__move (which the tcl API calls):

http://fisheye.openacs.org/browse/OpenACS/openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql?r=HEAD

cr_items name and acs_objects title are both updated but cr_revisions title is not. Perhaps it's a question of semantics? Should the item name be used in the FS UI? We can discuss at OCT.

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.

Collapse
Posted by Dave Bauer on
You can't create two folders with the same name and parent_id.

There is a constraint on the cr_items table that prevents this.

Unless your version of fs::get_folder is doing something strange.

Perhaps you can check the query that is running for fs::get_folder and the values for any bind variables, and if possible try out the same query in psql and paste the query and results here.

Collapse
Posted by Iuri Sampaio on
I didnt create two folders with thesame info.
every folder is unique and its name is the user_id of the system user.

Where did you see that?

Collapse
Posted by Dave Bauer on
Sorry I read

"
I realized that filestorage was creating new folders with the field "name" on table cr_items with all records as "file-storage-new-folder""

so I thought the problem you were referring to was about the cr_items.name.