Forum OpenACS Q&A: Re: Learning to use XOTcl

4: Re: Learning to use XOTcl (response to 3)
Posted by Gustaf Neumann on
Changing the content-type is not the way to go; it would be pretty invasive to force people to change the content-type to use a certain api.

The original problem is that the object-relational interface looks for a class to handle the images, but cannot not find it (since there is no such class defined). The object-relational api contains "get_class_from_db" to generate such a class on the fly from the OpenACS meta model in the database. However, this is only implemented for plain OpenACS object types, but not for types in the content repository (such as "image"). I have looked around in my databases, and found no acs_objects of object_type "image", so photo-album seems to be more or less the only application using this type.

Adding the type is not much code, so i added it just now to xotcl-core

With that fetching images via "get_instance_from_db" is supposed to work.

5: Re: Learning to use XOTcl (response to 4)
Posted by Richard Hamilton on
That sorted that out perfectly, thank you. It also gave me a guided tour of some more of the code which I found very useful.


6: Re: Learning to use XOTcl (response to 4)
Posted by Richard Hamilton on
I have been playing with the ::xo::db API (purely to improve my understanding rather than with a definite objective at this stage) but I have a few questions.

1) I have created an ::xo::db::image object from the database and as an experiment have tried changing the parent_id to that of my xowiki instance (i.e. ::xowiki::Formpage), and the object_type to ::xowiki::File. I also added the live revision_id and creator name to the xowiki_page table, and the revision_id to the xowiki_file table, but the image still doesn't appear in my xowiki instance. Is this because objects of class ::xo::db::image do not fall within xowiki's realm?

2) I tried adding an attribute that is not part of the image content_type attribute list. I was expecting an error. To my astonishment it works, AND it goes into the persistent layer. How is this achieved? Does the ::xo::db layer automatically interface with AMS for additional attributes - even when I haven't defined slots?

server1:nscp 2> ::xo::db::CrClass get_instance_from_db -item_id 1272
server1:nscp 16> ::1272 set creator {Richard Hamilton}
Richard Hamilton
server1:nscp 17> ::1272 save
server1:nscp 3> ::1272 serialize
::xo::db::image create ::1272 -noinit \
        -set creator {Richard Hamilton} \
        -set object_type image \
        -set height 100 \
        -set creation_date {2010-11-01 12:03:55.686724+00} \
        -set creation_user 667 \
        -set object_id 1273 \
        -set description thumbnail \
        -set text /12/72/1273 \
        -set package_id 966 \
        -set width 150 \
        -set nls_language {} \
        -set name {th_19 - nicepic.jpg} \
        -set mime_type image/jpeg \
        -set title {th_19 - nicepic.jpg} \
        -set publish_status ready \
        -set item_id 1272 \
        -set revision_id 1401 \
        -set last_modified {2010-11-06 19:47:21.542161+00} \
        -set publish_date {2010-11-01 12:03:55.686724+00} \
        -set modifying_user {} \
        -set parent_id 1268 \
        -set image_id 1273

3) How do I now remove that extra attribute from the persistent storage layer?

4) As an exercise, how would I go about creating a duplicate of an image object from the content repository as an ::xowiki::File so that it appears in an xowiki instance? Could this be achieved using mixins by creating a subclass of both ::xo::db::image and ::xowiki::File?

Sorry so many questions, but this is such a revelation for me that I want to try to understand as much as possible! :-)


9: Re: Learning to use XOTcl (response to 4)
Posted by Richard Hamilton on

The object with item_id 989 is an xowiki instance

server1=# select item_id, name, content_type from cr_items where parent_id=989;
item_id | name | content_type
1035 | en:weblog | ::xowiki::Page
1038 | en:weblog-portlet | ::xowiki::Object
991 | en:index | ::xowiki::Page
1000 | en:gallery_demo | ::xowiki::Page
1027 | file:2080.jpg | ::xowiki::File
1382 | file:01.jpg | ::xowiki::File
1386 | file:02.jpg | ::xowiki::File
1390 | file:03.jpg | ::xowiki::File
(8 rows)

server1=# select * from images where image_id in (1027,1382,1386,1390);
image_id | width | height
(0 rows)

So now I see that images uploaded to the content repository via xowiki are stored as instances of ::xowiki::File, whilst other images in the content repository have entries in the images table.

Presumably in order to leverage the built-in CR support for images and image resizing etc. I would need to create a subclass of ::xowiki::File that will have all the characteristics of ::xowiki::File objects, whilst also having entries in the images table and being subject to the image:: procedures shown here:

Is this correct, and should I also re-implement these image:: procs as methods for the ::xowiki::File::Image class?