1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need some help with upgrading the install file of my add on

Discussion in 'XenForo Development Discussions' started by wang, Mar 3, 2016.

  1. wang

    wang Well-Known Member

    Hello,

    I have made some changes to several tables for my articles manager add on, but the upgrader for the new version does not carry those changes to the new version.

    I am following Resource Manager add on 's install and upgrade example, but it is not working for me. The current version id of the add on is 121. For the new version I had 20, but upon upgrade I got an error message saying that this version was older than the one that I was trying to upgrade from. So I changed it to 200. The upgrade did go fine, but the new database changes were not added. This is what I have.

    PHP:
    public static function install($previous)
        {
            
    $db XenForo_Application::get('db');

            if (!
    $previous)
            {
                foreach (
    self::getTables() AS $tableName => $tableSql)
                {
                    try
                    {
                        
    $db->query($tableSql);
                    }
                    catch (
    Zend_Db_Exception $e) {}
                }

                foreach (
    self::getAlters() AS $tableName => $alterSql)
                {
                    try
                    {
                        
    $db->query($alterSql);
                    }
                    catch (
    Zend_Db_Exception $e) {}
                }

                foreach (
    self::getData() AS $tableName => $dataSql)
                {
                    
    $db->query($dataSql);
                }
            }
            else
            {
                
    // upgrades
                
    if ($previous['version_id'] < 200)
                {
                    try
                    {
                        
    $db->query("
                            ALTER TABLE xf_table_name
                              CHANGE old_field new_field int(10) unsigned NOT NULL auto_increment,
                              ADD new_field_name blob NOT NULL,                     
                        "
    );
                    }
                    catch (
    Zend_Db_Exception $e) {}
                   
                }
            }
        }
    What I am doing wrong? I have been working on this for hours now and no luck so far. I have tried different variations with the version id, but the result has been the same. Some help will be much appreciated.
     
  2. Lawrence

    Lawrence Well-Known Member

    $db->query("
    ALTER TABLE xf_table_name
    CHANGE old_field new_field int(10) unsigned NOT NULL auto_increment,
    ADD new_field_name blob NOT NULL,
    ");

    Most likely the comma after NOT NULL
     
    wang likes this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    The query is erroring. There shouldn't be a trailing comma after blob NOT NULL

    What he said ^^
     
    Amaury and wang like this.
  4. wang

    wang Well-Known Member

    Many many thanks to both of you. I can not believe that I had missed that.
     
  5. Brogan

    Brogan XenForo Moderator Staff Member

    It was a comma chameleon.

    /gets coat
     
    Amaury, Lawrence, Dan and 2 others like this.
  6. wang

    wang Well-Known Member

    That comma chameleon caused me literally hours trying to find it.
     

Share This Page