You are here

function update_fix_schema_version in Drupal 4

Same name and namespace in other branches
  1. 5 update.php \update_fix_schema_version()

If the schema version for Drupal core is stored in the variables table (4.6.x and earlier) move it to the schema_version column of the system table.

This function may be removed when update 156 is removed, which is the last update in the 4.6 to 4.7 migration.

1 call to update_fix_schema_version()
update.php in ./update.php
Administrative page for handling updates from one Drupal version to another.

File

./update.php, line 136
Administrative page for handling updates from one Drupal version to another.

Code

function update_fix_schema_version() {
  if ($update_start = variable_get('update_start', FALSE)) {

    // Some updates were made to the 4.6 branch and 4.7 branch. This sets
    // temporary variables to prevent the updates from being executed twice and
    // throwing errors.
    switch ($update_start) {
      case '2005-04-14':
        variable_set('update_132_done', TRUE);
        break;
      case '2005-05-06':
        variable_set('update_132_done', TRUE);
        variable_set('update_135_done', TRUE);
        break;
      case '2005-05-07':
        variable_set('update_132_done', TRUE);
        variable_set('update_135_done', TRUE);
        variable_set('update_137_done', TRUE);
        break;
    }

    // The schema_version column (added below) was changed during 4.7beta.
    // Update_170 is only for those beta users.
    variable_set('update_170_done', TRUE);
    $sql_updates = array(
      '2004-10-31: first update since Drupal 4.5.0 release' => 110,
      '2004-11-07' => 111,
      '2004-11-15' => 112,
      '2004-11-28' => 113,
      '2004-12-05' => 114,
      '2005-01-07' => 115,
      '2005-01-14' => 116,
      '2005-01-18' => 117,
      '2005-01-19' => 118,
      '2005-01-20' => 119,
      '2005-01-25' => 120,
      '2005-01-26' => 121,
      '2005-01-27' => 122,
      '2005-01-28' => 123,
      '2005-02-11' => 124,
      '2005-02-23' => 125,
      '2005-03-03' => 126,
      '2005-03-18' => 127,
      '2005-03-21' => 128,
      // The following three updates were made on the 4.6 branch
      '2005-04-14' => 128,
      '2005-05-06' => 128,
      '2005-05-07' => 128,
      '2005-04-08: first update since Drupal 4.6.0 release' => 129,
      '2005-04-10' => 130,
      '2005-04-11' => 131,
      '2005-04-14' => 132,
      '2005-04-24' => 133,
      '2005-04-30' => 134,
      '2005-05-06' => 135,
      '2005-05-08' => 136,
      '2005-05-09' => 137,
      '2005-05-10' => 138,
      '2005-05-11' => 139,
      '2005-05-12' => 140,
      '2005-05-22' => 141,
      '2005-07-29' => 142,
      '2005-07-30' => 143,
      '2005-08-08' => 144,
      '2005-08-15' => 145,
      '2005-08-25' => 146,
      '2005-09-07' => 147,
      '2005-09-18' => 148,
      '2005-09-27' => 149,
      '2005-10-15' => 150,
      '2005-10-23' => 151,
      '2005-10-28' => 152,
      '2005-11-03' => 153,
      '2005-11-14' => 154,
      '2005-11-27' => 155,
      '2005-12-03' => 156,
    );

    // Add schema version column
    switch ($GLOBALS['db_type']) {
      case 'pgsql':
        $ret = array();
        db_add_column($ret, 'system', 'schema_version', 'smallint', array(
          'not null' => TRUE,
          'default' => -1,
        ));
        break;
      case 'mysql':
      case 'mysqli':
        db_query('ALTER TABLE {system} ADD schema_version smallint(3) not null default -1');
        break;
    }

    // Set all enabled (contrib) modules to schema version 0 (installed)
    db_query('UPDATE {system} SET schema_version = 0 WHERE status = 1');

    // Set schema version for core
    drupal_set_installed_schema_version('system', $sql_updates[$update_start]);
    variable_del('update_start');
  }
}