function node_gallery_update_6300 in Node Gallery 6.3
MAJOR UPGRADE - please don't blindly update from 2.x to 3.x! Your data will migrate, but some of your settings and most of your theming will need to be redone.
File
- ./
node_gallery.install, line 752 - Install, update and uninstall functions for the node_gallery module.
Code
function node_gallery_update_6300() {
$ret = array();
// Fast fail before changing any data for those who don't read docs
$lb2dir = drupal_get_path('module', 'node_gallery') . '/contrib/node_gallery_lightbox2';
if (is_dir($lb2dir)) {
$t = get_t();
$msg = $t('Node Gallery Lightbox2 module directory was found, and it has been removed with the release of Node Gallery version 3. Please <a href="!link">follow the directions given on Drupal.org</a> regarding module upgrading.', array(
'!link' => url('http://drupal.org/node/250790'),
));
$ret['#abort'] = array(
'success' => FALSE,
'query' => $msg,
);
return $ret;
}
$missing = array();
foreach (node_gallery_required_modules() as $module) {
if (!module_exists($module)) {
$missing[] = $module;
}
}
if (module_exists('node_gallery_access')) {
$ret['#abort'] = array(
'success' => FALSE,
'query' => "Node Gallery Access is enabled, and there isn't a version of it that works with Node Gallery 3.0. Please disable the module, or sit tight until it's updated.",
);
return $ret;
}
if (count($missing) > 0) {
$ret['#abort'] = array(
'success' => FALSE,
'query' => 'Required Node Gallery 3.0+ modules not found: ' . join(',', $missing),
);
return $ret;
}
// Create new tables
$schema = node_gallery_schema();
foreach (array(
'node_gallery_galleries',
'node_gallery_images',
'node_gallery_relationships',
) as $table) {
if (!db_table_exists($table)) {
db_create_table($ret, $table, $schema[$table]);
if (!db_table_exists($table)) {
// Table creation failed
$ret['#abort'] = array(
'success' => FALSE,
'query' => 'Failed to create table $table.',
);
return $ret;
}
}
}
// Update gallery and image content types with new imagefield
node_gallery_setup_content_types();
cache_clear_all();
if (db_table_exists('node_galleries')) {
// Just to make sure we have tabula rasa, we wipe the tables
$ret[] = update_sql('DELETE FROM {node_gallery_galleries}');
$ret[] = update_sql('DELETE FROM {node_gallery_images}');
// Migrate galleries from old table to new
$ret[] = update_sql('INSERT INTO {node_gallery_galleries} (SELECT DISTINCT gid, NULL FROM {node_galleries})');
// Migrate cover images
$ret[] = update_sql('UPDATE {node_gallery_galleries} new JOIN {node_galleries} old ON new.gid = old.gid SET cover_image = nid WHERE is_cover > 0');
// Migrate images from old table to new
$ret[] = update_sql('INSERT INTO {node_gallery_images} (SELECT nid,gid,weight FROM {node_galleries})');
_migrate_files_to_imagefields();
db_drop_table($ret, 'node_galleries');
}
_migrate_node_gallery_variables();
// We call this to add the admin-thumbnail preset
node_gallery_install_imagecache_presets();
node_gallery_set_imagecache_permissions();
cache_clear_all();
drupal_set_message(t('Node Gallery upgrade complete. Please review !upgrade_txt_link.', array(
'!upgrade_txt_link' => l('UPGRADING.txt', drupal_get_path('module', 'node_gallery') . '/UPGRADING.txt'),
)));
return $ret;
}