function gallery_assist_update in Gallery Assist 6
Implementation of hook_update().
2 calls to gallery_assist_update()
- gallery_assist_nodeapi in ./
gallery_assist.module - Implementation of hook_nodeapi().
- gallery_assist_ui_node_settings_submit in modules/
gallery_assist_ui/ gallery_assist_ui.module
File
- ./
gallery_assist.module, line 2662 - Drupal content type with gallery functionality.
Code
function gallery_assist_update($node) {
if (arg(2) == 'revisions' && (arg(4) == 'revert' || arg(4) == 'delete')) {
return;
}
$ui = variable_get('gallery_assist_ui_settings', array());
if (isset($ui[$node->type]) && $ui[$node->type] == 1 && arg(3) != 'ga_settings') {
return;
}
$cq = "DELETE FROM {cache_gallery_assist_data} WHERE cid = '%s'";
db_query($cq, $node->nid);
// Get data from principal gallery (the origen node from the translation)
$q = db_query("SELECT gid, gref, lang FROM {gallery_assist} WHERE ref = %d", $node->ref);
// Save the settings to origen and translated galleries
if (!empty($node->in_profile)) {
$my_in_profile = 1;
}
else {
$my_in_profile = 0;
}
if (!empty($node->show_title)) {
$my_show_title = 1;
}
else {
$my_show_title = 0;
}
if (!empty($node->gallery_items_shadow)) {
$shadow = 1;
}
else {
$shadow = 0;
}
// Update data.
$d_settings = variable_get('gallery_assist_' . $node->type . '_data', FALSE);
$settings = array();
if ($d_settings['common_settings_allowed']) {
if ($d_settings['gallery_public_status_allowed']) {
$settings['ga_public_status'] = $node->ga_public_status;
}
else {
$settings['ga_public_status'] = $d_settings['ga_public_status'];
}
if ($d_settings['container_format_allowed']) {
$settings['show_layout'] = $node->show_layout;
}
else {
$settings['show_layout'] = $d_settings['show_layout'];
}
if ($d_settings['gallery_container_weight_allowed']) {
$settings['gallery_container_weight'] = $node->gallery_container_weight;
}
else {
$settings['gallery_container_weight'] = $d_settings['gallery_container_weight'];
}
if ($d_settings['show_in_homepage_block_allowed']) {
$settings['show_in_homepage_block'] = $node->show_in_homepage_block;
}
else {
$settings['show_in_homepage_block'] = $d_settings['show_in_homepage_block'];
}
if ($d_settings['gallery_public_status_allowed']) {
$settings['gallery_public_status'] = $node->gallery_public_status;
}
else {
$node->gallery_public_status = $d_settings['show_in_homepage_block'];
}
if ($d_settings['show_titles_allowed']) {
$settings['show_titles'] = $node->show_titles;
$settings['ga_item_title_type'] = $node->ga_item_title_type;
}
else {
$settings['show_titles'] = $d_settings['show_titles'];
$settings['ga_item_title_type'] = $d_settings['ga_item_title_type'];
}
if ($d_settings['show_in_userprofile_allowed']) {
$settings['show_in_userprofile'] = $node->show_in_userprofile;
}
else {
$settings['show_in_userprofile'] = $d_settings['show_in_userprofile'];
}
if ($d_settings['gallery_items_shadow_allowed']) {
$settings['gallery_items_shadow'] = $node->gallery_items_shadow;
}
else {
$settings['gallery_items_shadow'] = $d_settings['gallery_items_shadow'];
}
}
if ($d_settings['extra_layout_settings_allowed'] == 1) {
$settings['ga_align'] = $node->ga_align;
$settings['gap_align'] = $node->gap_align;
$settings['t_ga_float'] = $node->t_ga_float;
$settings['p_ga_float'] = $node->p_ga_float;
$settings['t_thm_link_format'] = $node->t_thm_link_format;
if ($d_settings['hide_teaser_container_allowed']) {
$settings['hide_in_teaser'] = $node->hide_in_teaser;
}
else {
$settings['hide_in_teaser'] = $d_settings['hide_teaser_container_allowed'];
}
if ($d_settings['show_download_link_allowed']) {
$settings['show_download_link'] = $node->show_download_link;
}
else {
$settings['show_download_link'] = $d_settings['show_download_link'];
}
}
$settings['ga_db_order_field'] = $node->ga_db_order_field;
$settings['ga_db_order'] = $node->ga_db_order;
if (module_exists('i18n')) {
$settings['translation_behavior'] = $node->translation_behavior;
}
if (!empty($node->path)) {
$settings['old_path'] = $node->path;
}
if (function_exists('pathauto_menu')) {
$settings['ga_rebuild_items_alias'] = $node->ga_rebuild_items_alias;
}
if ($settings['show_layout'] == 'list') {
$settings['show_title'] = FALSE;
$settings['gallery_items_shadow'] = FALSE;
}
$new_data = serialize($settings);
// If the owner is changed.
// Realize all nedded operations to assiggn all files and all galleries informations to the new owner.
// Last fix to "Deleted folders after change of author" thanks suffering_drupal.
if (!empty($node->current_owner) && is_numeric($node->current_owner) && $node->uid != $node->current_owner) {
$the_new_user = user_load($node->uid);
$new_user_gallery_directory = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $node->uid;
$old_user_gallery_directory = variable_get('gallery_assist_directory', file_directory_path() . '/gallery_assist') . '/' . $node->current_owner;
if (!is_dir($new_user_gallery_directory)) {
if (!file_check_directory($new_user_gallery_directory, 1)) {
drupal_set_message('Konte new_user_gallery_directory nicht erstellen.');
}
}
if (is_dir($new_user_gallery_directory)) {
gallery_assist_makedirs($node);
if (count($node->gallery_items) > 0) {
$old_path = "gallery_assist/{$node->current_owner}/";
$new_path = "gallery_assist/{$node->uid}/";
// Get the reference gid and change all paths in the item table.
$gref = db_result(db_query("SELECT gref FROM {gallery_assist} WHERE ref = %d", $node->ref));
$q_change = "UPDATE {gallery_assist_item} SET opath = replace( opath , '%s', '%s' ),\n ppath = replace( ppath , '%s', '%s' ),\n tpath = replace( tpath , '%s', '%s' ),\n uid = %d WHERE gref = %d";
if (!db_query($q_change, db_escape_string($old_path), db_escape_string($new_path), db_escape_string($old_path), db_escape_string($new_path), db_escape_string($old_path), db_escape_string($new_path), $node->uid, $gref)) {
drupal_set_message(t('A error is ocurred by Gallery Assist owner change'), 'error');
}
// Scan for moving proccess.
$get_old_path = $old_user_gallery_directory . '/gallery_assist' . $node->nid;
$move_to_path = $new_user_gallery_directory . '/gallery_assist' . $node->nid;
$scann = file_scan_directory($get_old_path, '.', array(), 0, TRUE);
// Move the files to the new destination.
foreach ($scann as $v) {
$new_place = preg_replace("/\\/{$v->basename}/", '', $v->filename);
$new_place = preg_replace("/\\/{$node->current_owner}\\//", "/{$node->uid}/", $new_place);
file_move($v->filename, $new_place, $replace = FILE_EXISTS_REPLACE);
}
// Update the paths in the files table.
foreach ($node->gallery_items as $item) {
$q_f_change = "UPDATE {files} SET filepath = replace( filepath , '%s', '%s' ), uid = %d WHERE uid = %d AND fid = %d";
db_query($q_f_change, db_escape_string($old_path), db_escape_string($new_path), $node->uid, $node->current_owner, $item['fid']);
}
}
// Delete the old gallery folder.
if (gallery_assist_delete_directory(file_directory_path() . '/gallery_assist/' . $node->current_owner . '/gallery_assist' . $node->nid)) {
drupal_set_message(t('<b>The new owner of this gallery is user: @uname</b>', array(
'@uname' => $node->name,
)));
}
}
if ($node->uid > 1) {
if (!user_access('create gallery_assist content', $the_new_user) || !user_access('create gallery_assist ' . $node->type . ' content', $the_new_user)) {
$bla = user_access('create gallery_assist_' . $node->type . ' content', $the_new_user);
$ble = user_access('create gallery_assist content', $the_new_user);
$s = $bla + $ble;
if ($s == 0) {
drupal_set_message(t("<strong>A T T E N T I O N !</strong><br /> The user @uname haven't the needed permissions to create or edit this node type.", array(
'@uname' => $node->name,
)), 'warning');
}
}
}
}
// The owner is changed END.
// Update settings on original and on each translation node.
while ($res = db_fetch_object($q)) {
$update_data = array(
'gid' => $res->gid,
'uid' => $node->uid,
'in_profile' => $my_in_profile,
'ga_public_status' => $node->ga_public_status,
'show_title' => $my_show_title,
'gallery_assist_weight' => $node->gallery_assist_weight,
'show_in_homepage_block' => $node->show_in_homepage_block,
'data' => $new_data,
'items' => db_result(db_query("SELECT COUNT(*) FROM {gallery_assist_item} WHERE gref = %d", $node->gref)),
);
drupal_write_record('gallery_assist', $update_data, 'gid');
}
if ($node->show_download_link != $node->show_download_link_old) {
$update_p_data = array(
'ref' => $node->ref,
'sid' => $node->show_download_link,
);
drupal_write_record('gallery_assist_item', $update_p_data, 'ref');
}
// If just translated, update all.
if ($node->language != db_result(db_query("SELECT lang FROM {gallery_assist} WHERE nid = %d", $node->nid))) {
$update_t_data = array(
'nid' => $node->nid,
'uid' => $node->uid,
'lang' => $node->language,
);
drupal_write_record('gallery_assist', $update_t_data, 'nid');
$update_translated_data = array(
'nid' => $node->nid,
'uid' => $node->uid,
'lang' => $node->language,
);
drupal_write_record('gallery_assist_translated', $update_translated_data, 'nid');
}
// Save the settings data from modules that are working with Gallery Assist.
foreach (module_implements('gallery_assist_api') as $name) {
$function = $name . '_gallery_assist_api';
$get_data = $node->{$name};
$gam_data = serialize($get_data);
$key_name = 'gam_' . $name;
$gam = $node->{$key_name};
if (isset($gam) && $gam > 0) {
$record = array(
'gam' => $gam,
'nid' => $node->nid,
'ref' => $node->ref,
'gid' => $node->gid,
'gref' => $node->gref,
'module' => $name,
'data' => $gam_data,
);
drupal_write_record('gallery_assist_modules_settings', $record, 'gam');
}
else {
$q = db_query("insert into {gallery_assist_modules_settings} (nid, ref, gid, gref, module, data)\n VALUES (%d, %d, %d, %d, '%s', '%s')", $node->nid, $node->ref, $node->gid, $node->gref, $name, $gam_data);
}
}
// if (count($node->gallery_items) > 0 && empty($node->has_cover)) {
// drupal_set_message('Currently, this gallery has no cover. Please choose one.', 'warning');
// }
}