View source
<?php
define('NODE_GALLERY_DEFAULT_GALLERY_TYPE', 'node_gallery_gallery');
define('NODE_GALLERY_DEFAULT_IMAGE_TYPE', 'node_gallery_image');
define('NODE_GALLERY_DEFAULT_IMAGE_FIELD', 'field_node_gallery_image');
if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install') {
include_once dirname(__FILE__) . '/node_gallery.inc';
}
else {
module_load_include('inc', 'node_gallery');
}
function node_gallery_schema() {
$schema = array();
$schema['node_gallery_relationships'] = array(
'fields' => array(
'rid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => t('Node Gallery Relationship ID'),
),
'gallery_type' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 255,
'description' => t('Node Gallery Gallery Content Type.'),
),
'image_type' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 255,
'description' => t('Node Gallery Image Content Type.'),
),
'imagefield_name' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 255,
'description' => t('The name of the imagefield that contains the image on an image node.'),
),
'settings' => array(
'type' => 'text',
'not null' => FALSE,
'serialize' => TRUE,
),
),
'primary key' => array(
'rid',
),
);
$schema['node_gallery_images'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Image node id.'),
),
'gid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Gallery node id.'),
),
'weight' => array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'nid',
),
'indexes' => array(
'gallery' => array(
'gid',
),
),
);
$schema['node_gallery_galleries'] = array(
'fields' => array(
'gid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Gallery node id.'),
),
'cover_image' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
'description' => t('Node Id of the Cover Image'),
),
'img_count' => array(
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Gallery images count.'),
),
'pub_img_count' => array(
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Gallery published images count.'),
),
),
'primary key' => array(
'gid',
),
'unique keys' => array(
'cover_image' => array(
'cover_image',
),
),
'indexes' => array(
'img_count' => array(
'img_count',
),
'pub_img_count' => array(
'pub_img_count',
),
),
);
return $schema;
}
function node_gallery_required_modules() {
return array(
'content',
'views',
'filefield',
'imageapi',
'imagecache',
'imagefield',
);
}
function node_gallery_type_exists($type) {
include_once './' . drupal_get_path('module', 'node') . '/node.module';
include_once './' . drupal_get_path('module', 'user') . '/user.module';
$types = node_get_types();
$types = array_change_key_case($types, CASE_LOWER);
return array_key_exists($type, $types);
}
function node_gallery_install_cck_type($type = '<create>', $filename = '') {
if (file_exists($filename)) {
$macro = implode('', file($filename));
}
else {
drupal_set_message(t('Unable to read cck file !file for import. Exiting.', array(
'!file' => $filename,
)), 'error');
return;
}
if ($type != '<create>') {
if ($type == NODE_GALLERY_DEFAULT_IMAGE_TYPE) {
$content = array();
eval($macro);
$param = array(
'type_name' => $type,
);
$param = array_merge($param, array_pop($content['fields']));
if (!node_gallery_cck_field_exists($param)) {
content_field_instance_create($param);
}
}
}
else {
require_once './' . drupal_get_path('module', 'content') . '/modules/content_copy/content_copy.module';
$form_state = array(
'values' => array(
'type_name' => $type,
'macro' => $macro,
),
);
drupal_execute('content_copy_import_form', $form_state);
content_clear_type_cache();
}
}
function _migrate_files_to_imagefields() {
$total = db_result(db_query('SELECT COUNT(nid) FROM {node_galleries}'));
$result = db_query('SELECT nid, fid FROM {node_galleries}');
$count = 0;
while ($r = db_fetch_array($result)) {
$count++;
if ($count % 50 == 0) {
$image = node_load(NULL, NULL, TRUE);
}
$image = node_load($r['nid']);
$file = db_fetch_array(db_query('SELECT fid, uid, filename, filepath, filemime, filesize, status, timestamp FROM {files} WHERE fid = %d', $r['fid']));
$image->field_node_gallery_image[0] = $file;
$image->field_node_gallery_image[0]['data'] = array(
'alt' => $image->title,
'title' => $image->title,
);
$image->field_node_gallery_image[0]['origname'] = $file['filename'];
$image->field_node_gallery_image[0]['list'] = 1;
node_save($image);
db_query('DELETE FROM {node_galleries} WHERE nid = %d', $image->nid);
}
drupal_set_message(t('Upgraded !number total images to imagefield.', array(
'!number' => $total,
)));
}
function node_gallery_setup_content_type($type) {
$path = drupal_get_path('module', 'node_gallery') . "/cck_types";
$cck_file = $path . "/" . $type . ".cck";
$action = node_gallery_type_exists($type) ? $type : '<create>';
node_gallery_install_cck_type($action, $cck_file);
drupal_set_message(t('Node type %type created/modified.', array(
'%type' => $type,
)));
}
function node_gallery_setup_content_types() {
foreach (array(
NODE_GALLERY_DEFAULT_GALLERY_TYPE,
NODE_GALLERY_DEFAULT_IMAGE_TYPE,
) as $type) {
node_gallery_setup_content_type($type);
}
}
function node_gallery_install() {
module_enable(node_gallery_required_modules());
if (variable_get('node_gallery_install_defaults', TRUE)) {
node_gallery_setup_content_types();
}
$ret = drupal_install_schema('node_gallery');
if (variable_get('node_gallery_install_defaults', TRUE)) {
node_gallery_install_imagecache_presets();
node_gallery_set_imagecache_permissions();
node_gallery_set_default_view_node_gallery_permissions();
}
}
function node_gallery_requirements($phase) {
$t = get_t();
$requirements['node_gallery'] = array();
if (module_exists('node_images')) {
$requirements['node_gallery'][] = array(
'title' => 'Node Gallery',
'value' => 'Node Images module installed',
'description' => $t('The Node Images module is installed, and it conflicts with Node Gallery. Please disable it via the <a href="!link">modules page</a>.', array(
'!link' => url('admin/build/modules'),
)),
'severity' => REQUIREMENT_ERROR,
);
}
$lb2dir = drupal_get_path('module', 'node_gallery') . '/contrib/node_gallery_lightbox2';
if (module_exists('node_gallery_lightbox2') || is_dir($lb2dir)) {
$requirements['node_gallery'][] = array(
'title' => 'Node Gallery',
'value' => 'Node Gallery Lightbox2 module installed',
'description' => $t('The Node Gallery Lightbox2 module is available, 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' => 'http://drupal.org/node/250790',
)),
'severity' => REQUIREMENT_ERROR,
);
}
switch ($phase) {
case 'runtime':
if (module_exists('og')) {
$modules = module_list();
$ng_last = FALSE;
while ($module = array_shift($modules)) {
if ($module == 'node_gallery') {
break;
}
elseif ($module == 'og') {
$ng_last = TRUE;
break;
}
}
if (!$ng_last) {
$requirements['node_gallery'][] = array(
'title' => 'Node Gallery',
'value' => 'Node Gallery has a lighter weight than OG',
'description' => $t('Many of the breadcrumb features in Node Gallery when used with OG depend on Node Gallery having a module weight greater than OG. If you are using Node Gallery content types as standard group posts in OG, the breadcrumbs on image node pages may not look right. To fix them, please <a href="!link">adjust the module weights</a> so that this message no longer appears.', array(
'!link' => 'http://drupal.org/node/110238',
)),
'severity' => REQUIREMENT_INFO,
);
}
}
if (module_exists('imageapi') && !module_exists('imageapi_gd') && !module_exists('imageapi_imagemagick')) {
$requirements['node_gallery'][] = array(
'title' => 'Node Gallery',
'value' => 'Image toolkit not installed',
'description' => $t('Image API requires that an image toolkit be enabled before it will work! Please enable an image toolkit on the <a href="!link">modules page</a>.', array(
'!link' => url('admin/build/modules'),
)),
'severity' => REQUIREMENT_ERROR,
);
}
break;
default:
break;
}
return $requirements['node_gallery'];
}
function node_gallery_enable() {
$exists = db_result(db_query("SELECT COUNT(*) from {node_gallery_relationships} WHERE image_type = '%s'", NODE_GALLERY_DEFAULT_GALLERY_TYPE));
if ($exists == 0) {
drupal_get_schema(NULL, TRUE);
node_gallery_install_default_settings();
}
}
function node_gallery_uninstall() {
global $conf;
include_once './' . drupal_get_path('module', 'node') . '/node.module';
include_once './' . drupal_get_path('module', 'user') . '/user.module';
$types = node_get_types();
foreach (array(
NODE_GALLERY_DEFAULT_GALLERY_TYPE,
NODE_GALLERY_DEFAULT_IMAGE_TYPE,
) as $content_type) {
if (in_array($content_type, array_keys($types))) {
drupal_set_message(t('The !content_type content type is still present. You may !delete_link.', array(
'!content_type' => $content_type,
'!delete_link' => l(t('delete it'), 'admin/content/node-type/' . str_replace('_', '-', $content_type) . '/delete', array(
'attributes' => array(
'target' => '_blank',
),
)),
)));
}
}
foreach (array(
'node-gallery-cover',
'node-gallery-display',
'node-gallery-thumbnail',
) as $preset_name) {
$preset = imagecache_preset_by_name($preset_name);
if ($preset['presetid']) {
drupal_set_message(t('The !preset_name imagecache preset is still present. You may !delete_link.', array(
'!preset_name' => $preset_name,
'!delete_link' => l(t('delete it'), 'admin/build/imagecache/' . $preset['presetid'] . '/delete', array(
'attributes' => array(
'target' => '_blank',
),
)),
)));
}
}
$param = array(
'type_name' => NODE_GALLERY_DEFAULT_IMAGE_TYPE,
'field_name' => NODE_GALLERY_DEFAULT_IMAGE_FIELD,
);
if (node_gallery_cck_field_exists($param)) {
drupal_set_message(t('The !field field is still present. You may !delete_link.', array(
'!field' => NODE_GALLERY_DEFAULT_IMAGE_FIELD,
'!delete_link' => l(t('delete it'), 'admin/content/node-type/' . NODE_GALLERY_DEFAULT_IMAGE_TYPE . '/fields/' . NODE_GALLERY_DEFAULT_IMAGE_FIELD . '/remove', array(
'attributes' => array(
'target' => '_blank',
),
)),
)));
}
$ret = drupal_uninstall_schema('node_gallery');
$variables = array(
'node_gallery_galleries_summary_view',
'node_gallery_install_defaults',
'node_gallery_plupload_integration',
'node_gallery_plupload_manage_images_integration',
'node_gallery_plupload_manage_images_limit',
'node_gallery_plupload_wizard',
'node_gallery_jquery_ui_integration',
'node_gallery_sort_images_max',
);
foreach ($variables as $var) {
variable_del($var);
}
cache_clear_all();
}
function node_gallery_install_default_settings() {
$rel = new stdClass();
$rel->gallery_type = NODE_GALLERY_DEFAULT_GALLERY_TYPE;
$rel->image_type = NODE_GALLERY_DEFAULT_IMAGE_TYPE;
$rel->imagefield_name = 'field_node_gallery_image';
$rel->settings = node_gallery_relationship_settings_defaults();
drupal_write_record('node_gallery_relationships', $rel);
}
function node_gallery_install_imagecache_presets() {
$presets = imagecache_presets(TRUE);
$preset_names = array();
if ($presets != '') {
foreach ($presets as $preset) {
$preset_names[] = $preset['presetname'];
}
}
$imagecache_presets = array();
$imagecache_actions = array();
if (!in_array('node-gallery-thumbnail', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-thumbnail',
);
$imagecache_actions['node-gallery-thumbnail'][] = array(
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => 100,
'height' => 100,
),
'weight' => 0,
);
}
if (!in_array('node-gallery-cover', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-cover',
);
$imagecache_actions['node-gallery-cover'][] = array(
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => 150,
'height' => 150,
),
'weight' => 0,
);
}
if (!in_array('node-gallery-display', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-display',
);
$imagecache_actions['node-gallery-display'][] = array(
'action' => 'imagecache_scale',
'data' => array(
'height' => 1500,
),
'weight' => 0,
);
$imagecache_actions['node-gallery-display'][] = array(
'action' => 'imagecache_scale',
'data' => array(
'width' => 600,
),
'weight' => 1,
);
}
if (!in_array('node-gallery-admin-thumbnail', $preset_names)) {
$imagecache_presets[] = array(
'presetname' => 'node-gallery-admin-thumbnail',
);
$imagecache_actions['node-gallery-admin-thumbnail'][] = array(
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => 50,
'height' => 50,
),
'weight' => 0,
);
}
foreach ($imagecache_presets as $preset) {
$preset = imagecache_preset_save($preset);
foreach ($imagecache_actions[$preset['presetname']] as $action) {
$action['presetid'] = $preset['presetid'];
imagecache_action_save($action);
}
drupal_set_message(t('ImageCache preset %id: %name and corresponding actions saved.', array(
'%id' => $preset['presetid'],
'%name' => $preset['presetname'],
)));
}
}
function _node_gallery_add_permissions($rid, $permissions) {
if (!is_array($permissions)) {
$permissions = explode(', ', $permissions);
}
$current_perms = explode(', ', db_result(db_query("SELECT perm FROM {permission} WHERE rid=%d", $rid)));
foreach ($permissions as $permission) {
if (!in_array($permission, $current_perms)) {
$current_perms[] = $permission;
}
}
$current_perms = implode(', ', $current_perms);
$return = db_query("UPDATE {permission} SET perm= '%s' WHERE rid=%d", $current_perms, $rid);
return $return;
}
function _node_gallery_give_all_users_permission($permissions) {
$rids = array(
DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID,
);
foreach ($rids as $rid) {
_node_gallery_add_permissions($rid, $permissions);
}
}
function node_gallery_set_default_view_node_gallery_permissions() {
$perms = array(
'view node gallery',
);
_node_gallery_give_all_users_permission($perms);
}
function node_gallery_set_imagecache_permissions() {
$perms = array(
'view imagecache node-gallery-cover',
'view imagecache node-gallery-thumbnail',
'view imagecache node-gallery-display',
'view imagecache node-gallery-admin-thumbnail',
);
_node_gallery_give_all_users_permission($perms);
}
function _migrate_node_gallery_variables() {
global $conf;
$node_types = array_keys(node_get_types());
foreach ($conf as $key => $value) {
if (strpos($key, 'node_gallery_') === 0) {
$t = substr($key, 13);
if (in_array($t, $node_types)) {
$var = variable_get($key, array());
if (!isset($var['gallery_type'])) {
continue;
}
$rel = new stdClass();
$rel->gallery_type = $var['gallery_type'];
$rel->image_type = $var['image_type'];
$rel->imagefield_name = 'field_node_gallery_image';
$field_instance = array();
if ($var['upload_limits']['general']['file_extension'] != 'jpg jpeg gif png') {
$field_instance['widget']['file_extensions'] = $var['upload_limits']['general']['file_extension'];
}
if ($var['upload_limits']['general']['file_resolution'] != 0) {
$field_instance['widget']['max_resolution'] = $var['upload_limits']['general']['file_resolution'];
}
$field_instance['widget']['max_filesize_per_file'] = $var['upload_limits']['general']['file_max_size'] . 'M';
$field_instance['widget']['max_filesize_per_node'] = $var['upload_limits']['general']['file_max_size'] . 'M';
if (count($var['upload_limits']['roles']) > 0) {
drupal_set_message(t("Imagefield doesn't provide per-role file limits without extra modules. If you wish to maintain those, please use the !module module.", array(
'!module' => l(t('Node Limit Number'), 'http://drupal.org/project/node_limitnumber'),
)));
}
if (isset($var['gallery_directory'])) {
if (strpos($var['gallery_directory'], '%') === FALSE) {
$field_instance['widget']['file_path'] = $var['gallery_directory'];
}
else {
if (!module_exists('filefield_paths')) {
drupal_set_message(t("Imagefield doesn't provide tokenized paths without extra modules. If you wish to maintain those, please use the !module module.", array(
'!module' => l(t('FileField Paths'), 'http://drupal.org/project/filefield_paths'),
)));
}
}
}
$rel->settings = array_merge(node_gallery_relationship_settings_defaults(), $var);
drupal_write_record('node_gallery_relationships', $rel);
variable_del($key);
}
}
}
if (variable_get('node_images_page_fragment', FALSE)) {
drupal_set_message(t('You have selected "Use Named Anchors on Image Previous and Next links" in your configuration. This setting is now set on a per-relationship basis. Please <a href="@relationship_page">configure your relationships</a> to re-apply your previous setting.', array(
'@relationship_page' => url('admin/settings/node_gallery'),
)), 'warning');
variable_del('node_images_page_fragment');
}
foreach (array(
'node_gallery_page_number',
'node_images_page_number',
) as $v) {
$value = variable_get($v, 20);
switch ($v) {
case 'node_gallery_page_number':
if ($value != 20) {
drupal_set_message(t('You have selected to display @value galleries per page. The default is 20 - you may change the value by <a href="@view_link">editing the view</a>.', array(
'@value' => $value,
'@view_link' => url('admin/build/views/edit/node_gallery_gallery_summaries'),
)), 'warning');
}
break;
case 'node_images_page_number':
if ($value != 0) {
drupal_set_message(t('You have selected to display @value images per page. The default is 0 (unlimited) - you may change the value by <a href="@view_link">editing the view</a>.', array(
'@value' => $value,
'@view_link' => url('admin/build/views/edit/node_gallery_gallery_image_views'),
)), 'warning');
}
break;
}
variable_del($v);
}
}
function node_gallery_update_6100() {
$ret = array();
node_gallery_install_imagecache_presets();
node_gallery_set_imagecache_permissions();
return $ret;
}
function node_gallery_update_6101() {
$ret = array();
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
$t = drupal_unpack(db_fetch_object($result));
while ($t = drupal_unpack(db_fetch_object($result))) {
if (!empty($t)) {
$relationship = new gallery_config($t);
if (!$relationship->lightbox2) {
$relationship->lightbox2 = 'node-gallery-display';
}
if (!$relationship->view_original_text) {
$relationship->view_original_text = '';
}
if ($relationship->view_original == '1') {
$relationship->view_original = 'default';
}
unset($relationship->data);
$relationship
->save();
}
}
return $ret;
}
function node_gallery_update_6102() {
$ret = array();
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
$t = drupal_unpack(db_fetch_object($result));
while ($t = drupal_unpack(db_fetch_object($result))) {
if (!empty($t)) {
$relationship = new gallery_config($t);
if ($relationship->teaser['gallery_display_type'] == '0') {
$relationship->teaser['gallery_display_type'] = 'cover';
}
elseif ($relationship->teaser['gallery_display_type'] == '1') {
$relationship->teaser['gallery_display_type'] = 'thumbnails';
}
$relationship->gallery = array(
'gallery_display' => 'thumbnails',
'lightbox2_gallery_preset' => 'node-gallery-display',
);
unset($relationship->data);
$relationship
->save();
}
}
return $ret;
}
function node_gallery_update_6103() {
$ret = array();
$result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
$t = drupal_unpack(db_fetch_object($result));
while ($t = drupal_unpack(db_fetch_object($result))) {
if (!empty($t)) {
$relationship = new gallery_config($t);
$relationship->upload_settings = array(
'number_uploads' => '5',
);
unset($relationship->data);
$relationship
->save();
}
}
return $ret;
}
function node_gallery_update_6201() {
$ret = array();
db_drop_primary_key($ret, 'node_galleries');
db_add_primary_key($ret, 'node_galleries', array(
'nid',
));
return $ret;
}
function node_gallery_update_6202() {
$ret = array();
drupal_set_message(t('Node Gallery had to change some of our views code to <a href="http://drupal.org/node/547982">fix a bug relating to the "Gallery Operations" field</a>. If you used this field, you may be required to rebuild any views using that field. %broken.', array(
'%broken' => l(t('Read this information on how to fix any broken views'), 'http://drupal.org/node/547982', array(
'fragment' => 'comment-2199342',
)),
)), 'warning');
return $ret;
}
function node_gallery_update_6203() {
$ret = array();
drupal_set_message(t("Node Gallery Access has been removed from core, and migrated to it's own module - you may download the new version from !url.", array(
'url' => l('http://drupal.org/project/node_gallery_access', 'http://drupal.org/project/node_gallery_access'),
)));
$contribdir = drupal_get_path('module', 'node_gallery') . '/contrib/node_gallery_access';
if (is_dir($contribdir)) {
if (module_exists('node_gallery_access')) {
module_disable(array(
'node_gallery_access',
));
drupal_set_message(t('Node Gallery Access (contrib version) has been disabled, but your data is still there. Simply download the new version after removing the old one, and everything will upgrade automatically.'));
}
$ret['#abort'] = array(
'success' => FALSE,
'query' => 'Old contrib version of Node Gallery Access was found at ' . $contribdir . '. Please remove that directory and all of it\'s subfolders then rerun ' . l('update.php', 'update.php'),
);
}
return $ret;
}
function node_gallery_update_6300() {
$ret = array();
$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;
}
$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)) {
$ret['#abort'] = array(
'success' => FALSE,
'query' => 'Failed to create table $table.',
);
return $ret;
}
}
}
node_gallery_setup_content_types();
cache_clear_all();
if (db_table_exists('node_galleries')) {
$ret[] = update_sql('DELETE FROM {node_gallery_galleries}');
$ret[] = update_sql('DELETE FROM {node_gallery_images}');
$ret[] = update_sql('INSERT INTO {node_gallery_galleries} (SELECT DISTINCT gid, NULL FROM {node_galleries})');
$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');
$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();
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;
}
function node_gallery_update_6301() {
$ret = array();
node_gallery_delete_orphans();
return $ret;
}
function node_gallery_update_6302() {
$ret = array();
$defaults = node_gallery_relationship_settings_defaults();
foreach (node_gallery_get_all_relationships() as $rel) {
$rel['settings']['view_navigator_image_display'] = $defaults['view_navigator_image_display'];
$r = (object) $rel;
drupal_write_record('node_gallery_relationships', $r, 'rid');
}
cache_clear_all();
return $ret;
}
function node_gallery_update_6303() {
$ret = array();
$viewkey = unserialize(variable_get('node_gallery_galleries_summary_view', serialize(array(
'name' => 'node_gallery_gallery_summaries',
'display_id' => 'page_1',
))));
$view = views_get_view($viewkey['name']);
if ($view->type == t('Overridden')) {
$view->tag = 'node_gallery_galleries';
$view
->save();
watchdog('node_gallery', 'Added \'node_gallery_galleries\' tag for view %viewname', array(
'%viewname',
$view->name,
));
}
$view_names = array();
$view_settings = array(
'view_gallery_full_image_display',
'view_gallery_teaser_view_image_display',
'view_navigator_image_display',
);
foreach (node_gallery_get_all_relationships() as $rel) {
foreach ($view_settings as $view_setting) {
$viewkey = unserialize($rel['settings'][$view_setting]);
$view_names[] = $viewkey['name'];
}
}
$view_names = array_unique($view_names);
foreach ($view_names as $view_name) {
$view = views_get_view($view_name);
if ($view->type == t('Overridden')) {
$view->tag = 'node_gallery_images';
$view
->save();
watchdog('node_gallery', 'Added \'node_gallery_images\' tag for view %viewname', array(
'%viewname',
$view->name,
));
}
}
cache_clear_all('*', 'cache_views');
return $ret;
}
function node_gallery_update_6304() {
$ret = array();
$types = array();
$result = db_query('SELECT gallery_type FROM {node_gallery_relationships}');
while ($row = db_fetch_array($result)) {
$types[] = $row['gallery_type'];
}
$sql = 'SELECT nid as gid FROM {node} n LEFT JOIN {node_gallery_galleries} ng on ng.gid = n.nid WHERE n.type IN (' . db_placeholders($types, 'varchar') . ') AND ng.gid IS NULL';
$result = db_query($sql, $types);
$count = 0;
while ($gallery = db_fetch_object($result)) {
if (drupal_write_record('node_gallery_galleries', $gallery)) {
$count++;
}
}
if ($count > 0) {
$ret[] = array(
'success' => TRUE,
'query' => t('Added !count empty galleries into node_gallery_galleries table.', array(
'!count' => $count,
)),
);
}
return $ret;
}
function node_gallery_update_6305() {
$ret = array();
$fields = array(
'img_count' => array(
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Gallery images count.'),
),
'pub_img_count' => array(
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => t('Gallery published images count.'),
),
);
foreach ($fields as $field => $spec) {
db_add_field($ret, 'node_gallery_galleries', $field, $spec);
}
$indexes = array(
'img_count' => array(
'img_count',
),
'pub_img_count' => array(
'pub_img_count',
),
);
foreach ($indexes as $name => $index) {
db_add_index($ret, 'node_gallery_galleries', $name, $index);
}
$counts = array();
$res = db_query("SELECT ngi.gid AS gid, n.status AS status, COUNT(*) AS num\n FROM {node_gallery_images} ngi\n INNER JOIN {node} n ON ngi.nid = n.nid\n GROUP BY ngi.gid, n.status");
while ($row = db_fetch_array($res)) {
$row = array_map('intval', $row);
if (!isset($counts[$row['gid']])) {
$counts[$row['gid']] = array(
0 => 0,
1 => 0,
);
}
$counts[$row['gid']][$row['status']] = $row['num'];
}
foreach ($counts as $gid => $c) {
db_query("UPDATE {node_gallery_galleries} \n SET img_count = %d, pub_img_count = %d\n WHERE gid = %d", $c[0] + $c[1], $c[1], $gid);
}
$processed_num = count($counts);
$ret[] = array(
'success' => TRUE,
'query' => format_plural($processed_num, 'Created initial image count values for 1 gallery.', 'Created initial image count values for !count galleries.', array(
'!count' => $processed_num,
)),
);
drupal_flush_all_caches();
return $ret;
}