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

Collapse
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
::1272
server1:nscp 16> ::1272 set creator {Richard Hamilton}
Richard Hamilton
server1:nscp 17> ::1272 save
1272
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! 😊

Regards
Richard