• Resolved sebwordpress

    (@sebwordpress)


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

    Thanks for your help.

    https://www.ads-software.com/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;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sebwordpress

    (@sebwordpress)

    I have now modified the code to this.


    $dbversion = get_option(‘twiz_db_version’);

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

    Thread Starter sebwordpress

    (@sebwordpress)

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

    Thread Starter sebwordpress

    (@sebwordpress)

    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;
    }

    Thread Starter sebwordpress

    (@sebwordpress)

    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;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: The Welcomizer] Database not updating?’ is closed to new replies.