WordPress.org

Ready to get started?Download WordPress

Forums

The Welcomizer
[resolved] Database not updating? (5 posts)

  1. Sebastien Laframboise
    Member
    Plugin Author

    Posted 3 years ago #

    Does anyone understand why the new field 'on_event' is not added to the table?

    Thanks for your help.

    http://wordpress.org/extend/plugins/the-welcomizer/

    --------------
    twiz-index.php
    --------------

    /* Database version check */
    function twizUpdateDbCheck() {

    $myTwiz = new Twiz();

    if( get_option('twiz_db_version') != $myTwiz->dbVersion ){

    $ok = $myTwiz->install();
    }
    }

    /* dbversion check */
    add_action('plugins_loaded', 'twizUpdateDbCheck');

    -------------
    twiz.class.php
    -------------

    const F_ON_EVENT = 'on_event';

    function install(){

    global $wpdb;

    $sql = "CREATE TABLE ".$this->table." (".
    self::F_ID . " int NOT NULL AUTO_INCREMENT, ".
    self::F_SECTION_ID . " varchar(22) NOT NULL default '".self::DEFAULT_SECTION."', ".
    self::F_STATUS . " tinyint(3) NOT NULL default 0, ".
    self::F_LAYER_ID . " varchar(50) NOT NULL default '', ".
    self::F_ON_EVENT . " varchar(15) NOT NULL default '', ".
    self::F_START_DELAY . " int(5) NOT NULL default 0, ".
    self::F_DURATION . " int(5) NOT NULL default 0, ".
    self::F_START_TOP_POS_SIGN . " varchar(1) NOT NULL default '', ".
    self::F_START_TOP_POS . " int(5) default NULL, ".
    self::F_START_LEFT_POS_SIGN . " varchar(1) NOT NULL default '', ".
    self::F_START_LEFT_POS . " int(5) default NULL, ".
    self::F_POSITION . " varchar(8) NOT NULL default '', ".
    self::F_MOVE_TOP_POS_SIGN_A . " varchar(1) NOT NULL default '', ".
    self::F_MOVE_TOP_POS_A . " int(5) default NULL, ".
    self::F_MOVE_LEFT_POS_SIGN_A . " varchar(1) NOT NULL default '', ".
    self::F_MOVE_LEFT_POS_A . " int(5) default NULL, ".
    self::F_MOVE_TOP_POS_SIGN_B . " varchar(1) NOT NULL default '', ".
    self::F_MOVE_TOP_POS_B . " int(5) default NULL, ".
    self::F_MOVE_LEFT_POS_SIGN_B . " varchar(1) NOT NULL default '', ".
    self::F_MOVE_LEFT_POS_B . " int(5) default NULL, ".
    self::F_OPTIONS_A . " text NOT NULL default '', ".
    self::F_OPTIONS_B . " text NOT NULL default '', ".
    self::F_EXTRA_JS_A . " text NOT NULL default '', ".
    self::F_EXTRA_JS_B . " text NOT NULL default '', " .
    "PRIMARY KEY (". self::F_ID . "));";

    if ( $wpdb->get_var( "show tables like '".$this->table."'" ) != $this->table ) {

    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

    dbDelta($sql);

    $code = update_option('twiz_db_version', $this->dbVersion);
    $code = update_option('twiz_global_status', '1');

    }else{

    if( get_option('twiz_db_version') != $this->dbVersion ){

    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

    dbDelta($sql);

    $code = update_option('twiz_db_version', $this->dbVersion);
    }
    }

    return true;
    }

  2. Sebastien Laframboise
    Member
    Plugin Author

    Posted 3 years ago #

    I have now modified the code to this.

    ...
    $dbversion = get_option('twiz_db_version');

    if( $dbversion != $this->dbVersion ){
    ...

  3. Sebastien Laframboise
    Member
    Plugin Author

    Posted 3 years ago #

    When adding new fields, do we need to put them at the end?

  4. Sebastien Laframboise
    Member
    Plugin Author

    Posted 3 years ago #

    This code is working, have a nice day.

    ....
    dbDelta($sql);

    $code = update_option('twiz_db_version', $this->dbVersion);
    $code = update_option('twiz_global_status', '0');

    }else{

    $dbversion = get_option('twiz_db_version');

    if( $dbversion != $this->dbVersion ){

    /* Add the new field */
    $sql = "ALTER TABLE ".$this->table .
    " ADD ".self::F_ON_EVENT." varchar(15) NOT NULL default '' after ".self::F_LAYER_ID."";
    $code = $wpdb->query($sql);

    /* update anythying else */
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

    dbDelta($sql);

    $code = update_option('twiz_db_version', $this->dbVersion);
    }
    }

    return true;
    }

  5. Sebastien Laframboise
    Member
    Plugin Author

    Posted 3 years ago #

    This one is going to make a better job:

    dbDelta($sql);

    $code = update_option('twiz_db_version', $this->dbVersion);
    $code = update_option('twiz_global_status', '0');

    }else{

    $dbversion = get_option('twiz_db_version');

    if( $dbversion != $this->dbVersion ){

    /* Add the new field */
    $altersql = "ALTER TABLE ".$this->table .
    " ADD ".self::F_ON_EVENT." varchar(15) NOT NULL default '' after ".self::F_LAYER_ID."";
    $code = $wpdb->query($altersql);

    /* update anythying else */
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

    dbDelta($sql);

    $code = update_option('twiz_db_version', $this->dbVersion);
    }
    }

    return true;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic