<?php
//Get the id of the deleted documents
$docID = "115";
//Set the associated template variable ids that need to be deleted
$tvID1 = "26";
$tvID2 = "27";
//Get the filepath of the first tv (tvID1)
$result = $modx->db->query( 'SELECT id, value FROM `modx_site_tmplvar_contentvalues` WHERE contentid = \'' .$modx->db->escape($docID). '\' AND tmplvarid = \'' .$modx->db->escape($tvID1). '\' ORDER BY id ASC' );
while( $row = $modx->db->getRow( $result ) ) {
$output = $row['value'];
//check that the file is not open already and then delete it
$fh = fopen($output, 'w') or die("can't open file");
fclose($fh);
unlink($output);
}
echo "this file has been deleted: ".$output;
?>
//Set the associated template variable ids that need to be deleted
$tvID1 = "26";
$deletedids = $modx->event->params['ids'];
$countid = count($deletedids);
$i = 0;
while ($i <= $countid-1):
//Get the filepath of the tv1 (tvID1)
$result = $modx->db->query( 'SELECT id, value FROM `modx_site_tmplvar_contentvalues` WHERE contentid = \'' .$modx->db->escape($deletedids). '\' AND tmplvarid = \'' .$modx->db->escape($tvID1). '\' ORDER BY id ASC' );
while( $row = $modx->db->getRow( $result ) ) {
$output = $row['value'];
}
//check that the file is not open already and then delete it
$fh = fopen($output, 'w') or die("can't open file");
fclose($fh);
unlink($output);
}
$i++;
endwhile;
return;
if(!function_exists('delete_files')) {
function delete_files($filename) {
unlink($filename);
return true;
}
}
$modx->invokeEvent("OnEmptyTrash",
array(
"ids"=>$ids
));
global $modx;
$deletedids = $modx->event->params['ids'];
$countid = count($deletedids);
$i = 0;
while ($i <= $countid-1):
$table = $modx->getFullTableName("site_tmplvar_contentvalues");
$rows_affected = $modx->db->delete($table, "contentid = $deletedids[$i] AND tmplvarid = 26");
$dir = $modx->$deletedids[$i];
delete_files($dir);
$i++;
endwhile;
return;
$modx->invokeEvent("OnEmptyTrash",
array(
"ids"=>$ids
));
I’ve had a go, but can only get this to work in a snippet, and by adding an id manually to test - but at least it works:
then I tried doing it with a plugin set to OnDocFormDelete (also tried onEmptyTrash) - but can’t seem to get it to work - probably got this completely wrong so please feel free to give me a slap!..
//Set the associated template variable ids that need to be deleted $tvID1 = "26"; $deletedids = $modx->event->params['ids']; foreach ($deleteids 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). '\' ORDER BY id ASC' ); while( $row = $modx->db->getRow( $result ) ) { $output = $row['value']; } //check that the file is not open already and then delete it $fh = fopen($output, 'w') or die("can't open file"); fclose($fh); unlink($output); } return;