Search

This is a question to all extension developers:
If I'd like to automatically update the database after a new version of an extension is installed, how do I do this?

You can implement update($previousVersion) function in extension driver and run database queries there (pseudo code):

function update($previousVersion) {
    if (floatval($previousVersion) < 1.2) {
        $db = Administration::instance()->Database;
        $db->query('ALTER TABLE example ADD column type default value');
    }
}

:).

ahwayakchih is most correct. As an example, this is the update function from the latest version of the Select Box Link field:

public function update($previousVersion){   
    if(version_compare($previousVersion, '1.6', '<')){
        $this->_Parent->Database->query("ALTER TABLE `sym_fields_selectbox_link` ADD `limit` INT(4) UNSIGNED NOT NULL DEFAULT '20'");
        $this->_Parent->Database->query("ALTER TABLE `sym_fields_selectbox_link` CHANGE `related_field_id` `related_field_id` VARCHAR(255) NOT NULL");
    }
    return true;
}

Just realised I need to update $this->_Parent->Database->query( to be Administration::instance()->Database->query(, but either will work.

Thank you guys!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details