function bundle_inherit_update_7000 in Bundle Inherit 7
Rename bundle_hierarchy table to bundle_inherit.
Creates the new bundle_inherit table, copies over bundle_hierarchy data to the bundle_inherit table and, finally, drop the old bundle_hierarchy table.
File
- ./
bundle_inherit.install, line 94 - Bundle Inherit module install file.
Code
function bundle_inherit_update_7000() {
// Find out if we're running MySQL 5.5.
if ($result = db_query("SELECT version();")
->fetchField()) {
if (version_compare($result, '5.5', '>=')) {
if (db_query("RENAME TABLE bundle_hierarchy TO bundle_inherit")) {
return t('Renamed bundle_hierarchy table to bundle_inherit.');
}
}
}
// If the script gets here we're either not running MySQL, or not running
// MySQL < 5.5 or for whatever reason the query didn't work.
// We must copy and rename the table manually.
// Get table from the schema definition, force a rebuild to make sure the
// updated schema definition will be found.
$table = drupal_get_schema('bundle_inherit', TRUE);
try {
db_create_table('bundle_inherit', $table);
} catch (DatabaseSchemaObjectExistsException $e) {
// Do nothing, the table already exists.
}
// Grab all the data from the old table.
$data = db_query("SELECT * FROM bundle_hierarchy")
->fetchAll();
foreach ($data as $record) {
if (!drupal_write_record('bundle_inherit', $record)) {
// If we encounter a single error, stop immediately.
return FALSE;
}
}
return t('Renamed bundle_hierarchy table to bundle_inherit.');
}