We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    Your {} tags are mismatched.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 10165
      • 129 Posts
      yeah thanks spotted that, seems as though the sql is still not giving any results / working when it’s in the plug in?

      thanks
        • 10165
        • 129 Posts
        just to get up to date here’s a straight comparison of the snippet and the plugin..
        //THIS IS THE SNIPPET..................
        
        //Set the associated template variable ids that need to be deleted
        $tvID1 = "26";
        $value = "109";
        
            //Get the filepath of the tv1 (tvID1)
            $result = $modx->db->query('SELECT id, value FROM `modx_site_tmplvar_contentvalues` WHERE contentid = \'' .$modx->db->escape($value). '\' AND tmplvarid = \'' .$modx->db->escape($tvID1). '\'');
            while($row = $modx->db->getRow($result)) {
        	$output = $row['value'];
        unlink($output);
        }
        return;
        
        
        
        //THIS IS THE PLUG IN....................
        
        //Set the associated template variable ids that need to be deleted
        $tvID1 = "26";
        global $modx;
        $deletedids = (array) $modx->event->params['ids'];
        foreach ($deletedids as $key=>$value) {
        
            //Get the filepath of the tv1 (tvID1)
            $result = $modx->db->query('SELECT id, value FROM `modx_site_tmplvar_contentvalues` WHERE contentid = \'' .$modx->db->escape($value). '\' AND tmplvarid = \'' .$modx->db->escape($tvID1). '\'');
            while($row = $modx->db->getRow($result)) {
        	$output = $row['value'];
        echo $output;
        die;
        unlink($output);
        }
        }
        return;
        
        

          • 10165
          • 129 Posts
          I just tried the snippet code (with a hard coded id) in the plug in and it didn’t work huh undecided :’(
            • 3749
            • 24,544 Posts
            Do you mean that there’s no echo?

            Change it to:

            echo "Output: " . $output;


            Then you’ll know if that line is even executing.

            You do know that the unlink() won’t execute with the "die;" there, right?

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 10165
              • 129 Posts
              that’s right, no echo is being output, also tried with the new echo but nothing, can’t understand why this would work in a snippet but not plugin?

              I guess there would be no benefit this being in an external inc file or call to a snippet..?

              thanks
                • 10165
                • 129 Posts
                It must be an issue with the array / for each, but as I can’t get any output or errors now I’m not sure what to try next
                  • 3749
                  • 24,544 Posts
                  Sorry, I should have mentioned this earlier, but I’d suggest switching from $modx->db->query() to $modx->db->select(). Query is mainly for internal use by MODx.

                  http://wiki.modxcms.com/index.php/API:DBAPI:select

                  Then use something like this after the select statement:

                  <?php // this is just to get code highlighting - don't paste it.
                  $count = $modx->db->getRecordCount($result);
                  if($count) {
                      die('Successful query: ' . $count . ' Records returned'); // delete this and add your processing code here after you're sure the select is working.
                     
                  } else {
                      die('Query failed');
                  }

                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 10165
                    • 129 Posts
                    this is the latest attempt, but the query is failing..
                    I wonder if the query is being made too late and maybe the resource is getting deleted before the query gets made? Or is that not possible?
                    thanks



                    $tvID1 = "26";
                    global $modx;
                    $deletedids = (array) $modx->event->params['ids'];
                    //$deletedids = $modx->event->params['ids'];
                    var_dump($deletedids);
                    foreach ($deletedids as $key=>$value) {
                    
                        $v = $modx->db->escape($value);
                        $t = $modx->db->escape($tvID1);
                        $res = $modx->db->select("value", $modx->getFullTableName('site_tmplvar_contentvalues'), 
                        "contentid=$v AND tmplvarid=$t");
                       if($modx->db->getRecordCount($res))
                      {
                        die('Successful query: ' . $count . ' Records returned'); 
                    // delete this and add your processing code here after you're sure the select is working.
                      } else {
                        die('Query failed');
                    exit;
                      }
                    }
                    return;
                    

                      • 3749
                      • 24,544 Posts
                      If you are hooked to OnBeforeEmptyTrash, the docs should still be there.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting