1
gstarrett
Need update query help
  • 2003/10/7 0:09

  • gstarrett

  • Friend of XOOPS

  • Posts: 174

  • Since: 2002/3/12


Hi all,

I've been working on getting some XoopsGallery bugs hammered out and I've got this one left: Renaming the album needs to update the xoopscomments and xoopsgallery_image table. I know what SQL I need to run, but I'm unfamiliar with the XOOPS datbase engine such that something that should be quick will likely take me all night. Can someone help?

Here's what I need to do:
if (fs_is_dir("$dir/$oldName")) {
    
$success fs_rename("$dir/$oldName""$dir/$newName");
    if (!
$success) {
        return 
0;
    }
    
// Update xoopsgallery_image.image_albumdir with new album name
    // UPDATE {xoopsprefix}_xoopsgallery_image
    //         SET image_albumdir = $newName
    //        WHERE image_albumdir = $oldName
    
    // Update xoopscomments.com_extraparams with new album name
    // UPDATE {xoopsprefix}_xoopscomments
    //        SET com_exparams = replace('albumName=$oldName&', 'albumName=$newName&', com_exparams)
    //        WHERE com_exparams LIKE '%albumName=$oldName&%'
    
}


[edit: The second query should really check that com_modid = the gallery moduleID too, just to be safe]

Thanks!

2
gstarrett
Re: Need update query help
  • 2003/10/7 5:31

  • gstarrett

  • Friend of XOOPS

  • Posts: 174

  • Since: 2002/3/12


Alright... since no one noticed my post who could answer, I figured it out myself. If there's anything that will cause trouble down the line, please advise, but this seems to work properly.

Note that I'm not checking the return values because they will return 0 when there are no photos / comments to update.

This is from xoopsgallery/classes/AlbumDB.php, Line 89:
if (fs_is_dir("$dir/$oldName")) {
    
$success fs_rename("$dir/$oldName""$dir/$newName");
    if (!
$success) {
        return 
0;
    }
    
$xoopsgalleryimage_handler =& xoops_getmodulehandler('image');

    
// Update xoopsgallery_image.image_albumdir with new album name
    
$sql sprintf("UPDATE %s SET image_albumdir='%s' WHERE image_albumdir='%s'"$xoopsgalleryimage_handler->db->prefix('xoopsgallery_image'), $newName$oldName);
    
$result $xoopsgalleryimage_handler->db->queryF($sql);
    
    
// Update xoopscomments.com_extraparams with new album name
    
$sql sprintf("UPDATE %s SET com_exparams=REPLACE(com_exparams, 'albumName=%s&', 'albumName=%s&') WHERE com_exparams LIKE '%%albumName=%s%%' AND com_modid=%d"$xoopsgalleryimage_handler->db->prefix('xoopscomments'), $oldName$newName$oldName$GLOBALS['xoopsModule']->getVar('mid'));
    
$result $xoopsgalleryimage_handler->db->queryF($sql);
}


3
Mithrandir
Re: Need update query help

wow - you gave us all of 5½ hours..

looks fine to me, a few points, though:

1) Instead of getting the db through the galleryimage_handler, just go $xoopsDB

2) If you are getting all your variables from POST, you don't need the queryF, but just normal query. If, on the other hand, you do have oldname and newname in GET statements (which I wouldn't recommend) queryF is the correct one to use

Good luck

4
gstarrett
Re: Need update query help
  • 2003/10/7 17:10

  • gstarrett

  • Friend of XOOPS

  • Posts: 174

  • Since: 2002/3/12


That's 5 1/2 hours Internet time... practically a lifetime!

Thanks for the tips, I'll try incorporating them into my XoopsGallery update.

Login

Who's Online

288 user(s) are online (183 user(s) are browsing Support Forums)


Members: 0


Guests: 288


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits