In my stupidity I managed to delete some of the gallery folders under /assets/galleries AND I don’t have access to any tools like phpMyAdmin to edit my database. How can I remove the deleted galleries from the database through mysql (In other words: What are the relevant tables named, and what mysql command would I have to enter to delete the relevant table / rows for, say, the gallery that was placed in /assets/galleries/59 )?
Tjalve
[move]Tjalve TEH STUPID![/move]
Help needed fairly quickly...
<?php
$gtable = "maxigallery";
$docid = "59";
$path_to_gal = "assets/galleries/".$docid."/";
$pics_tbl = $modx->db->config['dbase'].".".$modx->db->config['table_prefix'].$gtable;
$sql = "SELECT * FROM " . $pics_tbl . " WHERE gal_id='" . $docid . "'";
$rs1=$modx->db->query($sql);
while($deletepic=$modx->fetchRow($rs1)) {
if(file_exists($path_to_gal.$deletepic['filename']))
unlink($path_to_gal.$deletepic['filename']);
if(file_exists($path_to_gal."tn_".$deletepic['filename']))
unlink($path_to_gal."tn_".$deletepic['filename']);
if(file_exists($path_to_gal."big_".$deletepic['filename']))
unlink($path_to_gal."big_".$deletepic['filename']);
$rsx=$modx->db->query("DELETE FROM $pics_tbl WHERE id='" . $deletepic['id'] . "'");
}
?>
That will delete all pictures from database table and filesystem that are in gallery 59
"He can have a lollipop any time he wants to. That's what it means to be a programmer."
Could this be made in a plugin that when a document is deleted that the Galleries are also removed from the server and the database?
Dimmy
Sure, just attach that to the appropriate event and get the $docid from the event params
Edit: try this in OnDocFormDelete event:
<?php
$e = &$modx->Event;
if ($e->name == 'OnDocFormDelete')
{
$gtable = "maxigallery";
$docid = $modx->event->params['id'];
$path_to_gal = "assets/galleries/".$docid."/";
$pics_tbl = $modx->db->config['dbase'].".".$modx->db->config['table_prefix'].$gtable;
$sql = "SELECT * FROM " . $pics_tbl . " WHERE gal_id='" . $docid . "'";
$rs1=$modx->db->query($sql);
while($deletepic=$modx->fetchRow($rs1)) {
if(file_exists($path_to_gal.$deletepic['filename']))
unlink($path_to_gal.$deletepic['filename']);
if(file_exists($path_to_gal."tn_".$deletepic['filename']))
unlink($path_to_gal."tn_".$deletepic['filename']);
if(file_exists($path_to_gal."big_".$deletepic['filename']))
unlink($path_to_gal."big_".$deletepic['filename']);
$rsx=$modx->db->query("DELETE FROM $pics_tbl WHERE id='" . $deletepic['id'] . "'");
}
}
?>
"He can have a lollipop any time he wants to. That's what it means to be a programmer."