Forum OpenACS Development: Re: new vers of acs_object__name(object_id)

Collapse
Posted by Gustaf Neumann on
jim,

where have you found this version of acs_object__name()? AFIKT, it is not in any of the recent versions of OpenACS. The part with the regular expressions looks strange to me. The current version can be viewed the easiest on [1]

-g

[1] https://github.com/openacs/openacs-core/blob/master/packages/acs-kernel/sql/postgresql/acs-objects-create.sql#L1010

Collapse
Posted by Jim Lynch on
> where have you found this version of acs_object__name()?

I took a copy of acs_object__name(obj_id) and I altered it myself.

The current version ends up with a blank name if acs_objects.title contains #foo.bar# and message foo.bar in lang_messages is blank or null.

The regex looks for "#pkg_key.msg_key#" and splits the keys so I can query for it, and test for blank/nullness, with the idea being, if that turns out to be blank or null, it's probably not the name we want. If that's the case, I let the existing code get the name by the method that was already there, I didn't change any of that.

-Jim

Collapse
Posted by Jim Lynch on
If you want justification for at least trying it, I'll contend that my addition isn't all that intrusive... the only way it "wakes up" is if acs_objects.title is non blank, and only then if the title follows the form "#pkg_key.msg_key#".

If the query after that finds there IS something in the message, that text is used as the object name, so I'm letting the original developer finish his work... or not, and either way, aca_object__name() (well, my version) tries a little harder to come up with a nonblank object name. If someone changes group__new() so that it puts the group name in the lang_messages table, my code will use that name.

The only way acs_object__name() can lose now, is if there does not exist a name method for the object type (or for any supertypes), or the name method itself returns blank.

-Jim

Collapse
Posted by Gustaf Neumann on
i am still confused, what the intention of your posting is: are you reporting a bug or do you want to discuss some extensions? What does "Recently, someone altered acs_group__new() so that it would add a row to the lang_messages table" refer to? Please be more precise.

If "title" in acs_objects is not specified, it should be NULL, if it is specified as the empty string, then it should be ''.

Collapse
Posted by Jim Lynch on
Gustaf,

This is a bug report with a suggested fix. The bug is, acs_object__name() returns a string from acs_objecs.title that looks like (pound sign)acs-translations.group_title_2702(pound sign), which gets looked up. The value it returns (from the table lang_messages) is blank, so that's what the old version of acs_object__name() returns. The "Recently..." comment refers to that change, which may not be complete.

To shed light on the problem, try this:

  • Create an application_group,
  • Find its object_id,
  • In psql, run: select title from acs_objects where object_id = theGroupId;
  • Still in psql, run: select acs_object__name(theGroupID);
  • Still psql, run select message from lang_messages where psckage_key = 'acs-translations' and message_key = 'group_title_(theGroupID)';
  • You should notice that the result of this query is either blank or null, and is why blank is displayed when group names are displayed.
My intent for my change to acs_object__name() is to fix the blank-group-name problem and be sufficiently nonintrusive so that (1) I'm avoiding interfering with the developer who started this change, and (2) acs_object__name() should work whether he completes his work or not.

-Jim

Collapse
Posted by Gustaf Neumann on
Jim,

the best place for bug reports is the bug tracker. The result below looks ok to me.

Do you get different results for acs_object__name()? I still don't see the connection with acs-translations.

-g

openacs.org=# select object_id, title from acs_objects where object_type = 'application_group';
 object_id |           title            
-----------+----------------------------
      3830 | Main Site Parties
     44322 | OpenACS Parties
     46079 | demo Parties
     46194 | Test Subsite Parties
     46238 | Projects Parties
     46273 | OpenACS Subsite Parties
     47519 | dotWRK Parties
     57366 | dotLRN Parties
    128847 | OpenACS Governance Parties
    179469 | CVS Committers
(10 rows)

openacs.org=# select acs_object__name(3830);
 acs_object__name  
-------------------
 Main Site Parties
(1 row)

openacs.org=# select message from lang_messages where package_key = 'acs-translations';
 message 
---------
(0 rows)

Collapse
Posted by Jim Lynch on
Gustaf,

You're right, the titles look good, and, those groups have been around on openacs.org ro maybe 10 or 20 years.

What do you find on a group created today or so?

-Jim

Collapse
Posted by Gustaf Neumann on
Applications groups created today don't look different. Today in ds/shell:
application_group::new -group_name foo
in psql
openacs.org=# select object_id, title, creation_date from acs_objects where object_type = 'application_group';
 object_id |           title            |         creation_date         
-----------+----------------------------+-------------------------------
      3830 | Main Site Parties          | 2002-07-11 22:08:20+02
     44322 | OpenACS Parties            | 2002-08-12 21:20:32+02
     46079 | demo Parties               | 2002-08-13 20:47:17+02
     46194 | Test Subsite Parties       | 2002-08-20 21:44:29+02
     46238 | Projects Parties           | 2002-08-20 21:48:27+02
     46273 | OpenACS Subsite Parties    | 2002-08-20 21:52:09+02
     47519 | dotWRK Parties             | 2002-09-23 23:10:55+02
     57366 | dotLRN Parties             | 2002-10-31 17:21:02+01
    128847 | OpenACS Governance Parties | 2003-09-28 20:15:03.255242+02
    179469 | CVS Committers             | 2004-05-04 10:52:55.872763+02
   4216650 | foo                        | 2015-01-02 09:06:42.58954+01
(11 rows)

openacs.org=# select acs_object__name(4216650);
 acs_object__name 
------------------
 foo
(1 row)
Do you get different results?

-g

Collapse
Posted by Jim Lynch on
sorry for delay... I have some results to show you, but first do you happen to know the &#...; for #?

-Jim

Collapse
Posted by Benjamin Brink on
stackoverflow.com/questions/3025171/whats-the-html-character-entity-for-the-sign
Collapse
Posted by Jim Lynch on

Hi, here are the results...

using this query:


        select 
            o.object_type, 
            o.creation_date::date, 
            o.title
        from 
            acs_objects o,
            lang_messages m,
            (select object_id, regexp_matches(title, '#([^.#]*).([^.#]*)#') as matcha from acs_objects) r
        where 
            o.object_id = r.object_id
          and
            r.matcha[1] = m.package_key
          and
            r.matcha[2] = m.message_key
          and
            (m.message is null or m.message = '')
        order by 
            o.title;
I get:

    object_type    | creation_date |                title                
-------------------+---------------+-------------------------------------
 application_group | 2014-02-05    | #acs-translations.group_title_1727#
 application_group | 2014-02-23    | #acs-translations.group_title_1958#
 application_group | 2014-12-22    | #acs-translations.group_title_2702#
(3 rows)
without the \ char at the start of the title field.

Collapse
Posted by Jim Lynch on
without the r and lang_message NULL or '', I get 70 rows.
Collapse
Posted by Jim Lynch on
As far as intent for posting, yes, this is a bug report (with suggested fix), and I'm also totally willing to discuss this way potentially other ways to solve it.

-Jim