Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Including files from another module looses data ?!?
  • Posted: 18.09.2003, 21:00
     
    rgasch
    rank:
    Steering Committee Steering Committee
    registered:
     January 2003
    Status:
    offline
    last visit:
    19.11.08
    Posts:
    567
    Hi,

    I am experiencing some rather strange behaviour which I can't quite figure out. Maybe someone where has an idea what's going on. Let me explain:

    I have a module for which I'm writing a search-addon. The core search functionality is abstracted in my module's library which then in turn calls some other functions. In my PN search code, I do the following:

    Code

    $search_results  = v4bProject_getProjectsAll (-1, __OP_VIEW_ALL, 'name', $q);


    and in v4bProject_getProjectsAll() I do the following:

    Code

    $projlist = v4bProjects_buildProjectIDListFromPermssions ();

    which I then use to build a query.

    In v4bProjects_buildProjectIDListFromPermssions() I do the following:

    Code

    require ('modules/v4bProjects/inc/table_init.inc');

    which basically does the following:

    Code

    list($dbconn)            = pnDBGetConn();
    $pntables                  = pnDBGetTables();
    $permission_table     = $pntables['v4b_projects_permission'];
    $permission_column  = &$pntables['v4b_projects_permission_column'];
    $project_table           = $pntables['v4b_projects_project'];
    $project_column        = &$pntables['v4b_projects_project_column'];


    For some strange reason though, the variables which are assigned in table_init.inc are not preserved in the v4bProjects_buildProjectIDListFromPermssions() when this function is called through my new PN search function. If I call the same function from my module, it works.

    I'm pretty sure that I have the require() and require_once() functions correct. I've tried changing them to a non-existing file and promply received the expected error.

    I know this is pretty vague, but I'd appreciate any ideas people have as to what I'm doing wrong. How come my code works as expected when called from my module but fails when called from a file integrated into the PN search functionality? Why would the table names I assign in table_init.inc not be preserved?

    Thanks/Greetings
    --> R
  • Posted: 21.09.2003, 16:36
     
    rgasch
    rank:
    Steering Committee Steering Committee
    registered:
     January 2003
    Status:
    offline
    last visit:
    19.11.08
    Posts:
    567
    OK, i"ve figured out what the problem is, however I still don't know why it is happening and what to do about it:

    The problem seems to be that if I do a

    Code

    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();

    in my custom search code (which is located in postnuke/includes/search), the $pntable stuture returned to me only contains the standard PN tables, but not any of the table definitions which are added in my module's pntables.php.

    Which brings me to 2 questions:
    1) Why is this happening?
    2) What can I do to fix this?

    Yes, I could just add the table definitions to my search code (which is really ugly), but the problem is that my search functionality is abstracted in my module's code which then also fails since the pnDBGetTables() call returns only the default PN tables, which then leads to my code generating invalid SQL.

    If I do the same thing from my module, it works. How can I get my search code to do the same thing (ie: pull in all table definitions from my module into the global pntables structure)?

    Greetings/Thanks
    --> R
  • Posted: 22.09.2003, 00:18
     
    rgasch
    rank:
    Steering Committee Steering Committee
    registered:
     January 2003
    Status:
    offline
    last visit:
    19.11.08
    Posts:
    567
    OK, I figured out what's going on. If you want to include all the definitions from a module other than the one you're currently in, use

    Code

    pnModDBInfoLoad ('yourModulName');

    to pull all it's definitions into the PN system. Once I did this, my code worked as expected.

    Greetings
    --> R
  • Posted: 22.09.2003, 03:58
     
    rank:
    Moderator Moderator
    registered:
     March 2002
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    7720
    Robert,

    What with all the goings here over the last few days i'd not had time to reply. Anyway your analysis correct. You need pnModDBLoadInfo when accessing module tables from outside of the module (e.g. search function). It should also be noted that blocks are also counted here.

    -Mark
  • Posted: 22.09.2003, 16:17
     
    rgasch
    rank:
    Steering Committee Steering Committee
    registered:
     January 2003
    Status:
    offline
    last visit:
    19.11.08
    Posts:
    567

    markwest

    Robert,

    What with all the goings here over the last few days i'd not had time to reply. Anyway your analysis correct. You need pnModDBLoadInfo when accessing module tables from outside of the module (e.g. search function). It should also be noted that blocks are also counted here.

    -Mark


    No Problem; it seems most of us are too busy for the 24 hours a day provides ... thanks for taking the time to confirm the results of my search through the code tree (grep is your friend :P )...

    BTW (I hate to bother you), but could you also confirm my question/idea/hunch about http://forums.postnu…e=viewtopic&t=16795?

    Thanks a lot
    --> R
  • Posted: 22.09.2003, 16:22
     
    rank:
    Moderator Moderator
    registered:
     March 2002
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    7720
    Robert,

    Also take a look at the pnAPI guide on noc.postnuke.com. When I first started I looked through the entire API set to familiarise myself with the possibilitues. PN .8 will see a lot more use pnModDBLoadInfo as the core pntables is substantially smaller.

    I'll take a look at the other thread this evening as i'm at work at the moment and have just popped in for a few minutes.

    -Mark

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula