We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30128
    • 78 Posts
    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...
      • 7923
      • 4,213 Posts
      <?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."
        • 7455
        • 2,204 Posts
        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
          follow me on twitter: @dimmy01
          • 7923
          • 4,213 Posts
          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."
            • 30128
            • 78 Posts
            Thx a ton! I didn’t get the script working (complained about line 7 so probably the query in line 6 didn’t go through for some reason). But I managed to install phpMyAdmin after all, and from the script I could then deduce which rows to delete - now it works like a charm again smiley

            Tjalve
              • 7455
              • 2,204 Posts
              Thanks doze wil try this
                follow me on twitter: @dimmy01