• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/internals/database/structure/closuretree.php
  • Класс: BitrixTasksInternalsDataBaseStructureis
  • Вызов: is::detach
static function detach($id)
{
	$result = new UtilResult();

	if(!static::isNodeExist($id))
	{
		$result->addError('NODE_NOT_FOUND', Loc::getMessage('TASKS_CLOSURE_TREE_NODE_NOT_FOUND'));
	}
	else
	{
		$pCName = static::getParentNodeColumnName();
		$cName = static::getNodeColumnName();
		$tableName = static::getTableName();

		$connection = MainHttpApplication::getConnection();

		// detach node from its parent, if any...
		$sql = "
				delete
				from
					".$tableName."
				where
					/*nodes from path (above node)*/
					".$pCName." in (
						".Helper::getTemporaryTableSubQuerySql("
							select ".$pCName." from ".$tableName." where ".$cName." = '".intval($id)."' and ".$pCName." != ".$cName."
						", $pCName)."
					)
					and
					/*nodes from subtree (below node + node itself)*/
					".$cName." in (
						".Helper::getTemporaryTableSubQuerySql("
							select ".$cName." from ".$tableName." where ".$pCName." = '".intval($id)."'
						", $cName)."
					)
		";

		try
		{
			$connection->query($sql);
		}
		catch(DBSqlException $e)
		{
			$result->addException($e, 'Error detaching node');
		}

		if($result->isSuccess())
		{
			$removed = $connection->getAffectedRowsCount();
			if(!$removed)
			{
				$result->addWarning('NO_ROWS_AFFECTED', 'No rows were affected');
			}
		}
	}

	return $result;
}