Forum OpenACS Development: Best way to fix this community logo problem?

When an admin uploads a new logo for a community, the file is placed in that community's public file folder.  Currently it has a few problems;  it isn't viewable because it has no live revision (and causes a server error if you try to view details) and it has a lovely name like this:  logo-comm.gif-C:\Documents and Settings\bergfeld_2\My Documents\docs\dotlrn\graphics\logo-comm.gif-3615

I tried a few things to improve the situation:
- changed the file's title to the friendlier Community Icon
- set the live revision properly

However, setting the live revision just moves us on to the next problem, which is that there is no template for an item of type "image". And on, and on.... each problem I fix just reveals another.

I finally decided to try approaching the problem from a different angle.  There's really no reason for these files to show up in file storage at all;  they really should just reside in the CR.  The reason the file is in file-storage is simple;  the file upload code deliberately sets the parent_id to that of the shared community folder when it calls cr_import_content.

I looked at other code which uses cr_import_content and saw that is is possible to set the parent_id to "", which I tried and that seemed to work fine.  Now, before I go on and modify the upload and revert code for the logo to delete the existing item in the CR (as they will end up being orphaned otherwise), I wanted to ask the collective wisdom of the community if this is the best way to fix the problem? Perhaps there was some good reason for having this file in file storage that I'm just overlooking at the moment....

Collapse
Posted by Dave Bauer on
It should not need a template. Only "text/*" mime types should be served with a template.

The only reason you don't want to store it with parent_id="" (NULL) is that everything that is created like that is put into the -100 folder. This will not allow two files with the same name to be uploaded in any community sitewide.

Collapse
Posted by Janine Ohmer on
Hi Dave,

file-storage/www/view/index.vuh calls content::init, which does this:

        select
          content_item.get_live_revision(content_item.get_template(:item_id, :context)) as template_id,
          content_template.get_path(content_item.get_template(:item_id, :context), :template_root) as template_url
        from
          dual

get_template is returning null, because there isn't one, and so get_path errors out. Maybe there is a way around this but I'm not familiar enough with the code to see it. I tried having get_path return null if the template_id passed in was null, but then I end up with that "Content Item Not found" message. Things work better if the content item has type file_storage_object instead of image, but then other things don't work, plus that's probably not a good general solution. I think it was at this point that I figured I must be heading in the wrong direction. :)

It would actually be better not to store the logo in file-storage anyway, since it's not a file the users need to see. Is there some other object_id I can use for the parent?

Collapse
Posted by Dave Bauer on
Ah. I see. It should use file_storage__new_file to store the logo in file-storage. It sets the file as a file_storage_object content type.

You could give the community logos names like "community_logo_${community_id}" and put them all in -100 perhaps.

As long as there is a seperate UI to add/edit/delete them they don't need to be in file-storage.

Collapse
Posted by Janine Ohmer on
Thanks, Dave - I think putting them in -100 is the best solution.
Collapse
Posted by Don Baccus on
Putting it in "-100" is fine though the magic number's annoying (we should have a PL/[pg]SQL function that returns the global file storage folder).

Oh, wait, we do, look at this!

"create or replace view content_item_globals as
select -100 as c_root_folder_id;"

Just select c_root_folder_id from content_item_globals ... good.

Since we should be moving more and more towards using the template-assigned-to-cr-type mechanism, wouldn't it be better to add a template to the image type now (since someday we'll want this) rather than kludge your code to store the icon as a file-storage-object in a folder that's not managed by file-storage?  I don't think its difficult ...

Collapse
Posted by Janine Ohmer on
Well, yes and no.  I'm not kludging it to store as a file storage object - I'm storing it as an image, in a place where users can't get to it so it doesn't have to be displayable.  It's only the display aspect that's broken without a template.  And even if displaying worked I'd still prefer to store it someplace where users won't see it;  it's messy to have the community logo, arguably an internal detail, sitting in the shared/public files folder for all to see.  So unless there is some other, better place to hide these files, I think the solution is ok even if a template is also needed for other images.
Collapse
Posted by Don Baccus on
Ahhh, OK, hiding it this way is fine, and of course if no .vuh or other generalized script is going to display it using the type+template mechanism there's no reason for you to do the content repository mod.