addons upgrade system

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:
 
You can look at XenForo_Application::$version or XenForo_Application::$versionId and work out from there what database changes are required.
 
Unless you mean the installed add-on version... for that I would need to look into the code to check.
 
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;)
 
Unless you mean the installed add-on version... for that I would need to look into the code to check.
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
 
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;)
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;
    }
 
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', '')
        ");
    }

}
 
Top Bottom