Download & Extend

Doesn't update {comments}.pid after move images to new album

Project:album photos
Version:6.x-2.5-beta3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

It may cause comment's display error. When I move some images from album A to B, for example, these images' comments will be still displayed under album A, but not B.

Comments

#1

Yes this is a problem, is there a fix for it? I've tried looking myself but can't work out where it gets set nor how I might set it!

#2

Sorry for my late. Here is my modify below:

<?php
bash
-3.1$ svn diff photos.page.inc
Index
: photos.page.inc
===================================================================
---
photos.page.inc     (photos-6.x-2.5-beta3)
+++
photos.page.inc     (working copy)
@@ -
730,6 +730,7 @@
                       
'#required' => TRUE,
                  );
                       
$form['photos'][$fid]['uid'] = array('#type' => 'hidden','#default_value' => $img->uid,);
+                      
$form['photos'][$fid]['pid0'] = array('#type' => 'hidden','#default_value' => $img->pid,);
                };
        }
       
$form['allck'] = array('#value' =>'<a class="allck" href="javascript:void(0)">'.t('Select All').'</a> | <a class="allnone" href="javascript:void(0)">' .t('Deselect'). '</a>');
@@ -
747,8 +748,12 @@
                if (!empty(
$key['del'])) {
                       
_photos_file_del($fid);
                       
db_query('DELETE FROM {x_image} WHERE fid = %d',$fid);
+                      
db_query('DELETE FROM {comments} WHERE cid IN (SELECT cid FROM {x_vote} WHERE fid = %d)', $fid);
                }else{
                       
db_query("UPDATE {x_image} SET pid = %d, des = '%s', wid = %d WHERE fid = %d", $key['pid'],$key['des'], $key['wid'], $fid);
+                       if (
$key['pid'] != $key['pid0']) {
+                              
db_query('UPDATE {comments} SET nid = %d WHERE cid IN (SELECT cid FROM {x_vote} WHERE fid = %d)', $key['pid'], $fid);
+                       }
                }
        }
}
?>

#3

Status:active» needs review

thanks smzz. Code can be used, but also need to re-calculate the number of comments.

<?php
Index
: photos.page.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/photos/photos.page.inc,v
retrieving revision 1.1.2.23
diff
-u -r1.1.2.23 photos.page.inc
--- photos.page.inc   8 Oct 2008 16:22:36 -0000   1.1.2.23
+++ photos.page.inc   30 Nov 2008 10:00:55 -0000
@@ -729,7 +729,8 @@
         
'#default_value' => $img->pid,
         
'#required' => TRUE,
         );
-        
$form['photos'][$fid]['uid'] = array('#type' => 'hidden','#default_value' => $img->uid,);
+        
$form['photos'][$fid]['uid'] = array('#type' => 'hidden', '#default_value' => $img->uid,);
+     
$form['photos'][$fid]['oldpid'] = array('#type' => 'value', '#value' => $img->pid,);
       };
    }
   
$form['allck'] = array('#value' =>'<a class="allck" href="javascript:void(0)">'.t('Select All').'</a> | <a class="allnone" href="javascript:void(0)">' .t('Deselect'). '</a>');
@@ -
746,9 +747,17 @@
    foreach(
$form_state['values']['photos'] as $fid => $key) {
       if (!empty(
$key['del'])) {
         
_photos_file_del($fid);
-        
db_query('DELETE FROM {x_image} WHERE fid = %d',$fid);
+        
db_query('DELETE FROM {x_image} WHERE fid = %d', $fid);
+     
db_query('DELETE FROM {x_vote} WHERE fid = %d', $fid);
+     
db_query('DELETE FROM {comments} WHERE cid IN (SELECT cid FROM {x_vote} WHERE fid = %d)', $fid);
+     
_comment_update_node_statistics($key['pid']);
       }else{
         
db_query("UPDATE {x_image} SET pid = %d, des = '%s', wid = %d WHERE fid = %d", $key['pid'],$key['des'], $key['wid'], $fid);
+      if (
$key['pid'] != $key['oldpid']) {
+       
db_query('UPDATE {comments} SET nid = %d WHERE cid IN (SELECT cid FROM {x_vote} WHERE fid = %d)', $key['pid'], $fid);
+       
_comment_update_node_statistics($key['pid']);
+       
_comment_update_node_statistics($key['oldpid']);
+      }
       }
    }
}
@@ -
797,8 +806,8 @@
   
$output = '';
    if(
$con){
      
$output = $t;
-   }else{
-   if (
user_access('access comments')) {
+   }elseif(
module_exists('comment')) {
+   if(
user_access('access comments')) {
      
$node->type = 'photos';
      
$mode = _comment_get_display_setting('mode', $node);
      
$order = _comment_get_display_setting('sort', $node);
?>
AttachmentSize
photos.page_.inc_.txt 45.63 KB

#4

I've implemented the changes you have suggested and it works fine, thank you very much firstly smzz and then eastcn.

nobody click here