100128_cleanAuthrisationsInDB.php 1.71 KB
<?
require_once("../../../include/config.php");
$_LOSPDIR = $_LOSP_PATH_TO_ROOT = '../../../';
$_LOSP_DEV = false;
require_once("../../../include/System/php/RequireClass.inc.php");

$DB = StorableFactory::create($_LOSP_STORABLE_KINDOF, $_LOSP_STORABLE_DATA);


echo "\nrepair mensch.coop DB\n";

{
	echo "* delete the losp_BasisElement_writeauthorisation entrys, where the ListID has not a losp_BasisElement entry \n  ";

	$stmt = $DB->PDO_query('select ListID, ProfileID, AuthWriteListID  from losp_BasisElement_writeauthorisation  left join losp_BasisElement on ListID=AuthWriteListID  where ID is NULL');
	if($stmt){
		foreach($DB->PDO_fetchAll($stmt) as $row) {
			$stmt = $DB->PDO_query('DELETE FROM losp_BasisElement_writeauthorisation WHERE ListID=:ListID and ProfileID=:ProfileID', array(':ListID' => $row['ListID'], ':ProfileID' => $row['ProfileID']));
			$result = $DB->PDO_getResultRow($stmt);
			echo '#'.$row['ListID'].'-'.$row['ProfileID'].'-'.$row['AuthWriteListID'].' ';
		}
	}
	echo "\n  => finish \n\n";
}

{
	echo "* delete the losp_BasisElement_readauthorisation entrys, where the ListID has not a losp_BasisElement entry \n  ";

	$stmt = $DB->PDO_query('select ListID, ProfileID, AuthReadListID   from losp_BasisElement_readauthorisation  left join losp_BasisElement on ListID=AuthReadListID   where ID is NULL');
	if($stmt){
		foreach($DB->PDO_fetchAll($stmt) as $row) {
			$stmt = $DB->PDO_query('DELETE FROM losp_BasisElement_readauthorisation WHERE ListID=:ListID and ProfileID=:ProfileID', array(':ListID' => $row['ListID'], ':ProfileID' => $row['ProfileID']));
			$result = $DB->PDO_getResultRow($stmt);
			echo '#'.$row['ListID'].'-'.$row['ProfileID'].'-'.$row['AuthReadListID'].' ';
		}
	}
	echo "\n  => finish \n\n";
}

?>