Change to the Gallery module life-cycle

View: New views
1 Messages — Rating Filter:   Alert me  

Change to the Gallery module life-cycle

by Bharat Mediratta :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


This is a heads up that I've changed the module lifecycle again.  This
time I've added an upgrade() function into the xxx_install classes.
This allows us to separate out initial installs from subsequent upgrades.

I can go into detail about the rationale, if you want.  In a nutshell,
the old approach was going to force new installs to run through the
evolutionary path from schema 0 up to the latest schema.  The new code
path lets initial installs just start with the latest stuff.  And as a
side benefit, it simplifies the install() code a bit so for trivial
modules it's that much less code to write.

Old code for foo_installer.php:
  static function install() {
    $db = Database::instance();
    $version = module::get_version("foo", 0);
    if ($version == 0) {
      // install some tables
      module::set_version("foo", 1);
    }

    if ($version == 1) {
      // alter tables
      module::set_version("foo", 2);
    }

    if ($version == 2) {
      // alter tables
      module::set_version("foo", 3);
    }
  }

New code for foo_installer.php:
  static function install() {
    // install THE LATEST table schema (version 3)
    module::set_version("foo", 3);
  }

  static function upgrade($version) {
    if ($version == 1) {
      // upgrade tables from schema 1 to schema 2
      module::set_version("foo", 2);
    }

    if ($version == 2) {
      // upgrade tables from schema 2 to schema 3
      module::set_version("foo", 3);
    }
  }

The most fundamental change is that the install() code now skips right
to schema version 3, so installs are fast and don't go through a lot of
cruft to get there.

-Bharat


------------------------------------------------------------------------------
__[ g a l l e r y - d e v e l ]_________________________

[ list info/archive --> http://gallery.sf.net/lists.php ]
[ gallery info/FAQ/download --> http://gallery.sf.net ]