a function who only acept the parameter $modx like a global but for not use a gloval variable for security
this function delete all documents in site_content who hasent a parent.
is usefoul for mantain the database clear if for example in a snippet you delete a document this function delete to all documents belong to this
the code is
function cleanDatabase($modx){
$sql= ’SELECT id,parent
FROM ’.$modx->getFullTableName("site_content").’’;
$row= $modx->dbQuery($sql);
$allid= array ();
for ($i= 0; $i < $modx->db->getRecordCount($row); $i++) {
array_push($allid,$modx->db->getRow($row));
}
$sql2= ’SELECT id
FROM ’.$modx->getFullTableName("site_content").’’;
$row2= $modx->dbQuery($sql2);
while($row=mysql_fetch_array($row2)) {
$arrayid[] = $row[0];
}
for ($x=0;$x<count($allid);$x++){
if (in_array($allid[$x][’parent’],$arrayid)||$allid[$x][’parent’]==0){
}else{$modx->db->delete($modx->getFullTableName("site_content"), "id=’".$allid[$x][’id’]."’");}
}
}