Fork me on GitHub

selectObjectArray help  Bottom

  • ok, in my module i am changing around all the tables, adding one then splitting data from one table into the new one. my pntables had been edited to reflect the change, now in my upgrade function i am trying to get the data from certain columns in the original table and copy them to the new table. the data still exists in the tables (i checked) but using dbutil selectonjectarray function the only data it returns are the columns that the pntables file specifies as in that tablen.


    example of tables fucntion

    Code

    function Welcome_pntables()
    {
        // Initialise table array
        $pntable = array();

        // Full table definition
        $pntable['welcomedata'] = DBUtil::getLimitedTablename('welcomedata');
        $pntable['welcomedata_column'] = array ('welid'         => 'pn_id',
                                              'blurb'           => 'pn_blurb',
                                              'bcolor'          => 'pn_color',
                                              'layout'          => 'pn_layout');
       
       

        $pntable['welcomedata_column_def'] = array('welid'      => 'I NOTNULL AUTO PRIMARY',
                                                 'blurb'        => "X NOTNULL DEFAULT ''",
                                                 'bcolor'       => "X NOTNULL DEFAULT ''",
                                                 'layout'       => "X NOTNULL DEFAULT 'left'");

        $pntable['welcomedata_primary_key_column'] = 'welid';
       
       
        //image tables added version 0.4
        $pntable['welcomeimages'] = DBUtil::getLimitedTablename('welcomeimages');
        $pntable['welcomeimages_column'] = array ('iid'         => 'pn_id',
                                              'imageurl'        => 'pn_imageurl',
                                              'width'           => 'pn_width',
                                              'imagelink'       => 'pn_imagelink',
                                              'thumb'           => 'pn_thumb',
                                              'newwindow'       => 'pn_newwindow',
                                              'isblock'         => 'pn_isblock',
                                              'parnetid'        => 'pn_parentid');
       
        $pntable['welcomeimages_column_def'] = array('iid'      => 'I NOTNULL AUTO PRIMARY',
                                                 'imageurl'     => 'X DEFAULT NULL',
                                                 'width'        => 'I NULL',
                                                 'imagelink'    => "X NOTNULL DEFAULT ''",
                                                 'thumb'        => "X NOTNULL DEFAULT ''",
                                                 'newwindow'    => 'I1 DEFAULT 0',
                                                 'isblock'      => 'I1 DEFAULT 0',
                                                 'parnetid'     => 'I NULL');

        $pntable['welcomeimages_primary_key_column'] = 'iid';
        // end of image tables added at version 0.4
       
        $pntable['welcomedata'] = DBUtil::getLimitedTablename('welcomedata');
        $pntable['welcomeimages'] = DBUtil::getLimitedTablename('welcomeimages');
        return $pntable;
    }



    the data in the "welcomeimages" table used to all be in the "welcomedata" table but it is being split out into its own table.

    so in my upgrade function theres a switch and for this versions case i create the new table

    Code

    case 0.3:   
                if (!DBUtil::createTable('welcomeimages')) {
                    return false;
                }
                // get all welcome items
                $objArray = DBUtil::selectObjectArray('welcomedata');
                foreach ($objArray as $item) {
                                return LogUtil::registerError($item);


    what is returned is

    Code

    4
    blurb
    #DCDCDC
    left



    that info corresponds exactly to the columns that are still left in the pntables file for that table. however that data is not missing from the SQL table


    can someone help me i need to figure out how to migrate those columns from one table to another.
  • First a quick hint, if you want to print out the data in an array use

    Code

    print_r($array_to_print);die

    This will print out your array and immediately return. Very handy.

    Now on to your problem. My guess is that you have changed the layout of the data table for welcome data and removed the image related items, correct? The problem is that you are defining a new structure and then trying to use that new structure on an old table. If you do this, then zikula does not know about those columns and ignores that data. Here is a suggestion about how to solve this

    1) Get the old data the old fashioned way using mysql statements. There are functions in DBUtil that can help.
    2) Create your new tables using DBUtil.
    3) Parse the old data into arrays that match the new table structure.
    4) Insert the data into the new tables. Again there are DBUtil functions to help with this
    5) Drop the old table.
    For this to work, I would recommend that you rename your new tables so that none of them have the same name as your old table.

    Hope this helps.
  • 0 users

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