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

addons upgrade system

Discussion in 'XenForo Development Discussions' started by DroidHost, Jun 28, 2011.

  1. DroidHost

    DroidHost Well-Known Member

    I was wondering in case of upgrading an addon let say from 1.1 -> 1.2
    and there are changes in the tables of the database
    could we detacte which is the current version
    so if it is 1.0 ... we insert some tables ,,,
    and if it is 1.1 we will insert diffrent set of tables
    according to the changes ,,,
    hope it is clear ... :coffee:
     
  2. Kier

    Kier XenForo Developer Staff Member

    You can look at XenForo_Application::$version or XenForo_Application::$versionId and work out from there what database changes are required.
     
  3. Kier

    Kier XenForo Developer Staff Member

    Unless you mean the installed add-on version... for that I would need to look into the code to check.
     
  4. ragtek

    ragtek Guest

    the static install method have 2 parameters => $existingAddOn, $addOnData

    check the content of this 2 vars and you'll see that they contain everything what you need;)
     
    DroidHost likes this.
  5. DroidHost

    DroidHost Well-Known Member

    yes an installed addon ..... that the admin using right now ... and the admin is upgrading it
    we need to access while doing that ..
    I am not sure if u understand me or not but if not tell me write it in different way
     
  6. DroidHost

    DroidHost Well-Known Member

    where should these go ?
    this is my class
    Code:
    class DroidHost_Bannar_Installer
    {
        public static function installer()
        {
            self::_createTables();
    
            return true;
        }
    then this is going to be this ?
    Code:
    class DroidHost_Bannar_Installer
    {
        public static function installer($existingAddOn, $addOnData)
        {
            self::_createTables();
    
            return true;
        }
     
  7. Bob

    Bob Well-Known Member

    this is how I do mine...

    PHP:
    class XordSportsbook_Install
    {
        private static 
    $_instance;

        protected 
    $_db;

        public static final function 
    getInstance()
        {
            if (!
    self::$_instance)
            {
                
    self::$_instance = new self;
            }

            return 
    self::$_instance;
        }

        protected function 
    _getDb()
        {
            if (
    $this->_db === null)
            {
                
    $this->_db XenForo_Application::get('db');
            }

            return 
    $this->_db;
        }

        public static function 
    build($existingAddOn$addOnData)
        {
            
    $startVersion 1;
            
    $endVersion $addOnData['version_id'];

            if (
    $existingAddOn)
            {
                
    $startVersion $existingAddOn['version_id'] + 1;
            }

            
    $install self::getInstance();

            for (
    $i $startVersion$i <= $endVersion$i++)
            {
                
    $method '_installVersion' $i;

                if (
    method_exists($install$method) === false)
                {
                    continue;
                }

                
    $install->$method();
            }
        }

        protected function 
    _installVersion1()
        {
            
    $db $this->_getDb();

            
    $db->query("
                ALTER TABLE xf_user
                ADD sportsbook_cash BIGINT(20) UNSIGNED NOT NULL DEFAULT '500'
            "
    );
        }

        protected function 
    _installVersion2()
        {
            
    $db->query("
                CREATE TABLE IF NOT EXISTS xordsportsbook_category (
                    category_id int(10) unsigned NOT NULL AUTO_INCREMENT,
                    category_name varchar(255) NOT NULL,
                    category_abbr varchar(25) NOT NULL,
                    PRIMARY KEY (category_id)
                ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
            "
    );
        }

        protected function 
    _installVersion3()
        {
            
    $db $this->_getDb();

            
    $db->query("
                INSERT INTO xf_content_type
                    (content_type, addon_id, fields)
                VALUES
                    ('sportsbook_event', 'XordSportsbook', ''),
                    ('sportsbook_comment', 'XordSportsbook', ''),
                    ('sportsbook_wager', 'XordSportsbook', '')
            "
    );
        }

    }    
     
  8. SheepCow

    SheepCow Well-Known Member

Share This Page