We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    I am trying to make a plugin that deletes all images and references in the db from maxigallery for that page. (if you delete a doc that hold a gallry all entry’s are still in db and all files are still on the server)

    OnEmptyTrash event was introduced in 096 and I like to use that, but what information (variables) do I get to work with? found it in the TRAC $modx->event->params[’ids’]

    if I have selected multiple documents for deletion do I get the id’s in an array? and what is the array called? on witch I can build my queries to delete mysql entry’s and files?

    I really like plugins and the power that it gives me, but there is not so much documentation on what options you get to use. like is there a $fields for all events?

    Ok Plugin is made and works pleas test if you like.


      follow me on twitter: @dimmy01
      • 7455
      • 2,204 Posts
      ok I made this plugin and it works nice.

      I do like if someone could see if I forgot things like checks etc.
      I am a Rookie coder so please flame away.

      // Remove Galleries Plugin v0.1
      // By Dimitri Hiverda
      //
      // This plugin removes the Galleries made by the MaxiGallery snippet when you empty your trash
      // Use the OnEmptyTrash event (Only works from modX 0.9.6 and up)
      //
      
      
      global $modx;
      function delete_directory($dirname) {
      if (is_dir($dirname))
      $dir_handle = opendir($dirname);
      if (!$dir_handle)
      return false;
      while($file = readdir($dir_handle)) {
      if ($file != "." && $file != "..") {
      if (!is_dir($dirname."/".$file))
      unlink($dirname."/".$file);
      else
      delete_directory($dirname.'/'.$file);
      }
      }
      closedir($dir_handle);
      rmdir($dirname);
      return true;
      }
      $deletedids = $modx->event->params['ids'];
      $countid = count($deletedids);
      $i = 0;
      while ($i <= $countid-1):
      
      $table = $modx->getFullTableName("maxigallery");
      $rows_affected = $modx->db->delete($table, "gal_id = $deletedids[$i]");
      
      $dir = $modx->config['base_path']."/assets/galleries/".$deletedids[$i];
      delete_directory($dir);
      $i++;
      endwhile;
      return;
      


      Dimmy
        follow me on twitter: @dimmy01
        • 25373
        • 13 Posts
        Do I need to set a system event to make this work?

        thanks
        Alex
          • 7231
          • 4,205 Posts
          As it says in the notes above.. grin
          // Use the OnEmptyTrash event (Only works from modX 0.9.6 and up)
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 25260
            • 156 Posts
            sorry for digging this, but I think that this is not working if using &gtable parameter.

            $table = $modx->getFullTableName("maxigallery");


            Is there a clean way to get the table used by the call in the document that is being purged?
              • 7455
              • 2,204 Posts
              Quote from: Roberto at Feb 17, 2010, 05:25 AM

              sorry for digging this, but I think that this is not working if using &gtable parameter.

              $table = $modx->getFullTableName("maxigallery");


              Is there a clean way to get the table used by the call in the document that is being purged?

              I think thats not that easy because then I would need to look at the content and look for that &gtable parameter and then use that...
              its posible I think... are there mor people that like this in here? then I could have a look at it.

              Dimmy
                follow me on twitter: @dimmy01
                • 25260
                • 156 Posts
                It isn’t said that the Maxigallery call is in the content, for example I have all my Maxigallery calls in the template (I use it as a sort of "image manager").

                I’ll investigate a little.
                  • 25260
                  • 156 Posts
                  $deletedids = $modx->event->params['ids'];
                  $countid = count($deletedids);
                  $i = 0;
                  
                  while($i <= $countid-1){
                      $doc = $modx->getDocument($deletedids[$i]);
                      $templateid = $doc['template'];
                      //here switching $templateid and selecting correct table name
                      $rows_affected = $modx->db->delete($table, "gal_id = $deletedids[$i]");
                      $dir = $modx->config['base_path']."/assets/galleries/".$deletedids[$i];
                      delete_directory($dir);
                      $i++;
                  }


                  this will work only for snippet calls placed in templates, and you have to personalize the code depending on your template id.

                  I was looking for something to partially parse the template, because I’ve got snippet calls placed in chunks, so if I directly read the &gtable parameter from templates, I can’t find anything.

                  Also, this is not working for snippet calls placed in content (but I guess it won’t be so difficult to get this).

                  Note that if you use different tables depending from the template, when you switch the template in the document, some data remains in the table and it will not deleted when you purge the document.

                  I know, I’m a pain in the ass :-P

                  Cheers,

                  Roberto
                    • 26931
                    • 2,314 Posts
                    hi Dimmy,
                    It isn’t said that the Maxigallery call is in the content, for example I have all my Maxigallery calls in the template (I use it as a sort of "image manager").
                    is your plugin code is updated?, because when i purge a ressource the gallery folder + the db reference will be deleted ( like Roberto tried to achieve )... no matter if the call is in the template, or in the content field.

                    j
                      • 7455
                      • 2,204 Posts
                      What Roberto tried was to delete galleries that have custom table cells

                      normaly the plugin wil work all the time asuming that the default db fields are used
                        follow me on twitter: @dimmy01