$GLOBALS['SQ_SYSTEM']->am->forgetAsset($bridge);
 } else {
     $asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($user_id, '', TRUE);
 }
 if (!is_null($asset)) {
     // print info the asset, as it exists
     printAssetName($asset);
     printUpdateStatus('OK');
     // conserve memory and move on to the next perm
     $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
     continue;
 }
 // the asset doesn't exist
 $dummy_asset->id = $user_id;
 $dummy_asset->name = 'Unknown Asset';
 printAssetName($dummy_asset);
 // open the transaction
 $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
 try {
     $sql = 'DELETE FROM sq_ast_role WHERE userid = :userid';
     $query = MatrixDAL::preparePdoQuery($sql);
     MatrixDAL::bindValueToPdo($query, 'userid', $user_id);
     MatrixDAL::execPdoQuery($query);
     // all good
     $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
     printUpdateStatus('FIXED');
 } catch (DALException $e) {
     // no good
     $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
     printUpdateStatus('FAILED');
 }
$ROOT_ASSETID = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : '1';
if ($ROOT_ASSETID == 1) {
    echo "\nWARNING: You are running this integrity checker on the whole system.\nThis is fine but:\n\tit may take a long time; and\n\tit will acquire locks on many of your assets (meaning you wont be able to edit content for a while)\n\n";
}
$root_user =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
// log in as root
if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
    echo "ERROR: Failed login in as root user\n";
    exit;
}
// go through each user in the system, lock it, set permissions, unlock it
$assets = $GLOBALS['SQ_SYSTEM']->am->getChildren($ROOT_ASSETID, 'user', false);
foreach ($assets as $assetid => $type_code_data) {
    $type_code = $type_code_data[0]['type_code'];
    $asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type_code);
    printAssetName($asset);
    // try to lock the asset
    if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($asset->id, 'permissions')) {
        printUpdateStatus('LOCK');
        $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
        continue;
    }
    // give the user read access to him/herself
    if (!$GLOBALS['SQ_SYSTEM']->am->setPermission($asset->id, $asset->id, SQ_PERMISSION_READ, 1)) {
        printUpdateStatus('FAILED');
        $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
        continue;
    }
    $links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2, 'asset', false, 'major', '', 1);
    foreach ($links as $link) {
        if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($link['minorid'], 'permissions')) {
            foreach ($tmp->_running_vars['cache_dirs'] as $dir) {
                if (substr($dir, 0, strlen($group)) == $group) {
                    // this directory contains cache entries for this particular asset
                    // now files the files in this cache dir that belong to this asset
                    $dh = opendir(SQ_CACHE_PATH . '/' . $dir);
                    while (false !== ($file = readdir($dh))) {
                        $abs_path = SQ_CACHE_PATH . '/' . $dir . '/' . $file;
                        if (is_dir($abs_path)) {
                            continue;
                        }
                        // if the file starts with the assetid_code for the asset
                        // then back up in the unlinking with the resurection
                        if (substr($file, 0, strlen($assetid_code)) == $assetid_code) {
                            unlink($abs_path);
                        }
                        printAssetName($parent_asset->name . ' (#' . $parent_asset->id . ')');
                        printUpdateStatus('CACHE CLEAR');
                    }
                    closedir($dh);
                }
            }
            //end foreach
        }
    }
    $GLOBALS['SQ_SYSTEM']->am->forgetAsset($wysiwyg);
}
//end foreach
/**
* Prints the name of the WYSIWYG as a padded string
*
* Padds to 30 columns
if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
    echo "ERROR: Failed login in as root user\n";
    exit;
}
$db =& $GLOBALS['SQ_SYSTEM']->db;
$GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
// go entire asset DB, lock it, validate it, unlock it
$sql = 'SELECT assetid, type_code FROM sq_ast WHERE NOT EXISTS (
			SELECT * FROM sq_ast_lnk WHERE link_type IN (' . SQ_LINK_TYPE_1 . ',' . SQ_LINK_TYPE_2 . ',' . SQ_LINK_TYPE_3 . ') AND minorid = assetid
		)';
$query = MatrixDAL::preparePdoQuery($sql);
$assets = MatrixDAL::executePdoAssoc($query);
foreach ($assets as $data) {
    $assetid = $data['assetid'];
    $type_code = $data['type_code'];
    printAssetName($assetid);
    $sql = 'SELECT
				linkid,
				majorid,
				link_type,
				sort_order
			FROM
				sq_ast_lnk
			WHERE
				minorid = :minorid
				AND
				link_type <> :link_type';
    $query = MatrixDAL::preparePdoQuery($sql);
    MatrixDAL::bindValueToPdo($query, 'minorid', $assetid);
    MatrixDAL::bindValueToPdo($query, 'link_type', SQ_LINK_NOTICE);
    $links = MatrixDAL::executePdoAssoc($query);