Fork me on GitHub

Mod Initialisation & Activation OK, but no table created  Bottom

  • Im rebuilding a module i made some time ago, i want to make it pnAPI Compliant.

    But i have a little big problem, the module seems to initialise and activate correctly, but Postnuke doesn't create the table.

    these are the files:
    pntables.php:

    Code

    <?php
    function liricas2_pntables()
    {
        // Initialise table array
        $pntable = array();
       
        // Set The Table Prefix
        $liricas = pnConfigGetVar('prefix') . '_liricas2';
       
        // Set the table name
        $pntable['Liricas2'] = $liricas;
       
        // Set The Ref Data Table
        $pntable['Liricas2_column'] = array('lid' => $liricas. '.pn_lid',
                        'uid' => $liricas. '.pn_uid',
                        'sender' => $liricas. '.pn_sender',
                        'mail' => $liricas. '.pn_mail',
                        'liricas' => $liricas. '.pn_lyrics',
                        'artist' => $liricas. '.pn_artist',
                        'song' => $liricas. '.pn_song');
        // Return the table information
        return $pntable;
    }

    ?>


    pninit.php:

    Code

    <?php
    function liricas2_init()
    {
        list($dbconn) = pnDBGetConn();
        $pntable = pnDBGetTables();

        $liricastable = $pntable['Liricas2'];
        $liricascolumn = &$pntable['Liricas2_column'];

        $sql = "CREATE TABLE $liricastable (
                $liricascolumn[lid] int(10) NOT NULL,
            $liricascolumn[uid] int(10) NOT NULL ,
            $liricascolumn[sender] text,
            $liricascolumn[mail] text,
            $liricascolumn[liricas] text,
            $liricascolumn[artist] varchar(200) NOT NULL,
            $liricascolumn[song] varchar(200) NOT NULL,

                PRIMARY KEY($liricascolumn[lid]))"
    ;
        $dbconn->Execute($sql);

        if ($dbconn->ErrorNo() != 0) {

            pnSessionSetVar('errormsg', _CREATETABLEFAILED . " : " . $dbconn->ErrorMsg());
            return false;
        }

        pnModSetVar('Liricas2', 'songsperpage', 50);
        // Initialisation successful
        return true;
    }


    function liricas2_upgrade($oldversion)
    {
        return true;
    }


    function liricas2_delete()
    {

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

        $sql = "DROP TABLE IF EXISTS $pntable[Liricas2]";
        $dbconn->Execute($sql);

        if ($dbconn->ErrorNo() != 0) {
                pnSessionSetVar('errormsg', _DROPTABLEFAILED . " : " . $sql);
            return false;
        }
        // Deletion successful
        return true;
    }

    ?>



    i've read in a post that this could be a typo, but i cant find anything (been looking at the code like 3 hours!!!!! cry )

    BTW i use a bilingual style of coding :shock: (just to minimize words length)
  • The pntables idea is a great idea, but it doesn't work so good when creating the tables themselves. The problem with your code is in the line where you set the PRIMARY KEY.

    Your code looks like this:

    Code

    PRIMARY key($liricascolumn[lid]))";


    The problem is that that line gets changed by the system to become:

    Code

    PRIMARY key(nuke_liricas2.pn_lid))";


    But what it needs to be is:

    Code

    PRIMARY key(pn_lid))";


    So if you look at the Template module or the Example module or most any other existing module you will find that they all use the $liricascolumn[lid] convention for everything except the line that says what the primary key is. At that point they use the actual value of pn_lid. In a way defeating the purpose of the pntables idea. Not totally of course since the benefits out weigh the problem.

    Here is the solution though if you want the pninit.php file to completely use the $liricascolumn[lid] convention.

    Code

    $PK1=explode(".",$liricascolumn[lid]);
        $sql = "CREATE TABLE $liricastable (
            $liricascolumn[lid] int(10) NOT NULL,
            $liricascolumn[uid] int(10) NOT NULL ,
            $liricascolumn[sender] text,
            $liricascolumn[mail] text,
            $liricascolumn[liricas] text,
            $liricascolumn[artist] varchar(200) NOT NULL,
            $liricascolumn[song] varchar(200) NOT NULL,
            PRIMARY KEY($PK1[1]))"
    ;


    Hope that helps.
    -Chris
  • mmmm... that WAS a problem (forgot to copy & paste that ;) ) but the problem persist!!

    now the pninit is:

    Code

    function liricas2_init()
    {
        list($dbconn) = pnDBGetConn();
        $pntable = pnDBGetTables();

        $liricastable = $pntable['Liricas2'];
        $liricascolumn = &$pntable['Liricas2_column'];
        $PK1=explode(".",$liricascolumn[lid]);

        $sql = "CREATE TABLE $liricastable (
                $liricascolumn[lid] int(10) NOT NULL,
            $liricascolumn[uid] int(10) NOT NULL ,
            $liricascolumn[sender] text,
            $liricascolumn[mail] text,
            $liricascolumn[liricas] text,
            $liricascolumn[artist] varchar(200) NOT NULL,
            $liricascolumn[song] varchar(200) NOT NULL,

                PRIMARY KEY($PK1[1]))"
    ;
        $dbconn->Execute($sql);
        ...


    all the rest remains the same.

    Module Initialise, Activates but still NO TABLES ARE CREATED!!! cry cry cry
  • I have copied and pasted the original code that you posted into a test module on my site. The only change that I have made to the code is the change that I explained in my previous post that you have shown in your last post. It installs without any errors and the database table is created just fine.

    This tells me that your module directory is probably not named liricas2. The functions need to be named after the directory that they are in. When you install the module the Modules module looks in the directory for a file named pninit.php. If it finds it then it looks for a function named moduleDirectoryName_init(). If it finds it then it runs it. If the Modules module doesn't find a file named pninit.php or a function called moduleDirectoryName_init() then it makes the determination that the module doesn't need any special functions to install itself and returns without error. I think if you put a die("Hey Sucker"); line just inside the liricas2_init() function that you'll find it never gets executed. Of course I could be wrong, it's happened before.

    If your directory is named correctly then my next check would be to make sure that the mysql user that you are using has the necessary permissions to create tables.
    Hope that helps.
    -Chris
  • icon_redface yeap, Capslock On when i pressed "L" on the directory name icon_redface

    but NOW im more amazed: i copy the module name from the function (before the _init()) and pasted it into the directory name (good way of not making typo's). BUT NOTHING CHANGED!!!

    But now i know THAT is the problem.

    I even put a syntax error on the liricas2_init() function, but it just initialise and activate!!

    i think im going to cry (again) cry cry cry
  • Make sure that you remove the module (in Admin->Modules) and then regenerate the list. If you rename the directory you need to regenerate the list because as far as the system is concerned it is looking at a new module.

    -Chris
  • Solved...

    How ? I Don't know...

    I was trying, regenerating, initialising, etc. suddenly a phone call.

    last try before picking up the phone, Deactivate, Remove, Regenerate...

    Answered the phone, went to talk.

    When i return, just clicked Initialise, Activate and Voila! table made !!! :shock:

    BTW, thank you very,very,very much, sometimes im justa a pain in the ass ;)

This list is based on users active over the last 60 minutes.