• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/internals/database/tree.php
  • Класс: BitrixTasksInternalsDataBaseis
  • Вызов: is::deleteLink
static function deleteLink($id, $parentId = false, array $behaviour = array('CHILDREN' => 'unlink'))
{
	static::applyDeleteRestrictions($id, $parentId);

	if(!is_array($behaviour))
	{
		$behaviour = array();
	}
	if(!isset($behaviour['CHILDREN']))
	{
		$behaviour['CHILDREN'] = 'unlink';
	}

	$parentColName = static::getPARENTIDColumnName();
	$idColName = static::getIDColumnName();
	$directColName = static::getDIRECTColumnName();

	$dbConnection = MainHttpApplication::getConnection();

	if($behaviour['CHILDREN'] == 'unlink')
	{
		// remove all links that connect all children of $id (including $id itself) and all parents of $parentId (including $parentId itself)

		// delete => select *
		$sql = "
			delete
			from 
					".static::getTableName()." 
				where 
					".$parentColName." in (
						".Helper::getTemporaryTableSubQuerySql("
							select 
								".$parentColName." 
							from 
								".static::getTableName()." 
							where 
								".$idColName.(
									$parentId !== false ?
									/*parent is known*/" = '".intval($parentId)."'" :
									/*detect parent*/" in (select ".$parentColName." from ".static::getTableName()." where ".$idColName." = '".intval($id)."' and ".$directColName." = '1')"
								)."
						", $parentColName)."
					)
					and
					".$idColName." in (
						".Helper::getTemporaryTableSubQuerySql("select ".$idColName." from ".static::getTableName()." where ".$parentColName." = '".intval($id)."'", $idColName)."
					)
		";

		$res = $dbConnection->query($sql);
		/*
		while($item = $res->fetch())
		{
			print_r('UNlink: '.$item[$parentColName].' => '.$item[$idColName].PHP_EOL);
		}
		*/
	}
	elseif($behaviour['CHILDREN'] == 'relocate')
	{
		throw new MainNotImplementedException();
	}
}