Forum OpenACS Development: CR and content_template defined wrong

Collapse
Posted by Lars Pind on
There's a design flaw in how cr_templates/content_template works.

In CR, you can defined "content_types" and "item_subtypes".

Both are related.

content_type extends content_revision, and has a row in cr_revisions.

item_subtype extends content_item, and has a row in cr_items.

Problem statement:

content_template is defined as an item_subtype, but used as a content_type.

lars=# select object_type, supertype, table_name, id_column, package_name from acs_object_types where object_type = 'content_template';
  object_type    |  supertype  |  table_name  |  id_column  |  package_name
------------------+--------------+--------------+-------------+------------------
content_template | content_item | cr_templates | template_id | content_template
(1 row)

Notice how its supertype is 'content_item', meaning it's an item_subtype.

create table cr_templates (
  template_id      integer
          constraint cr_template_id_fk references
          cr_items on delete cascade
          constraint cr_templates_pk
                  primary key
);

Notice how the column references cr_items, not cr_revisions.

This is consitent with the information in the acs_object_types table:

lars=# select object_type, supertype, table_name, id_column, package_name from acs_object_types where object_type = 'content_template';
  object_type    |  supertype  |  table_name  |  id_column  |  package_name
------------------+--------------+--------------+-------------+------------------
content_template | content_item | cr_templates | template_id | content_template
(1 row)

Now for how it's being used:

lars=# select item_id, name, live_revision, content_type from cr_items where content_type = 'content_template';
item_id |        name        | live_revision |  content_type
---------+----------------------+---------------+------------------
    544 | file-storage-default |          545 | content_template
    284 | default_template    |          285 | content_template
(2 rows)

Note how content_type says 'content_template', which is illegal since content_template is not a content_type.

So given that content_template's supertype is content_item, you'd think that object_id 284 is a content_template, but in fact, it's not:

lars=# select object_id, object_type from acs_objects where object_id = 284;
object_id | object_type
-----------+--------------
      284 | content_item
(1 row)

Yet, there's still a row in cr_templates:

lars=# select * from cr_templates where template_id = 284;
template_id
-------------
        284
(1 row)

So the default template's live_revision ID is 285, let's look closer at that:

lars=# select revision_id, item_id, title, content from cr_revisions where revision_id = 285;
revision_id | item_id |  title  |              content
-------------+---------+----------+-------------------------------------
        285 |    284 | Template | <html><body><content></body></html>
(1 row)

Which object_type does this object have?

lars=# select object_id, object_type from acs_objects where object_id = 285;
object_id |  object_type
-----------+------------------
      285 | content_template
(1 row)

content_template. But there's no row in cr_templates:

lars=# select * from cr_templates where template_id = 285;
template_id
-------------
(0 rows)

There should be according to the definition of the object_type.

PROPOSED CHANGE (not for current release, for 5.1):

- In types-create.sql, create content_template as a content_type, not an object_type.

- content_template__new needs to create a new content revision, and insert into cr_templates with the revision_id, not the item_id.

- Need to add a content_template__new_revision function.

Probably some other things as well.

The purpose of this post is to figure out to what extend people currently depend on the existing behavior, what other people's experiences are, and how we should go about fixing this.

/Lars

Collapse
Posted by Jeff Davis on
Does anything really use content templates? openacs.org doesn't have any, nor do any of the other sites I checked on.

You can see if there are any on your install via:

select * from cr_items where content_type = content_template';
(there will be one for the default template but I would guess its the only one for most people).
Collapse
Posted by Ola Hansson on
File storage uses it in 5.0 so it might be necessery to write complex upgrade scripts from 5.0 to 5.1 unless it is being addressed in 5.0.

File Storage is the only package I know of which uses content templates at this point ...

/Ola

Collapse
Posted by Jun Yamog on
Hi,

I currently use content_template heavily.  Although I did notice what Lars say. :)  Although it does support versioning fine with no problem.  I think... no unit testing yet.  I do agree that it not correct that its not inheriting from content_revision.  But this call works.

<fullquery name="bcms::template::add_template.add_template">
        <querytext>
            select content_revision__new(:title, :description, now(), 'text/html', null, :content, :template_id, null, now(), :creation_user_id, :creation_ip)
        </querytext>
    </fullquery>

I agree with the above changes.  I will also test once its been change.  Since I think I really use content_templates far more that most.  I do suggest not to have content_template__new_revision since the generic content_revision__new works ok.

Hmmmm maybe that explains why select content_template__delete(:template_id) is needed.  And generic content_item__delete does not work.

BTW content_item__get_path(i.item_id, ir.item_id) has a real big problem.  Maybe pg only, still investigating.  That plsql make use of cursors.  Which when hit many times... pg goes sky rocket.  Anybody has this problem too?

Collapse
Posted by Jun Yamog on
Hmmm looking at the post again.

I have to disagree that content_template__new will make a revision.  It should NOT.  This is similar to content_item__new.

Collapse
Posted by Lars Pind on
content_template__new should not parallel content_item__new (because 'content_item' is not a content_type), but rather something like image__new (because 'image' *is* a content_type).

image__new does create a new revision.

/Lars

Collapse
Posted by Jun Yamog on
Yeah right.  Once the changes has been made content_template__new should be logical to create a revision.
Collapse
Posted by Dave Bauer on
Let's fix this or decide not to and comment it in the code and APIs.

We are definitely starting to use templates.