• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/internals/database/mesh.php
  • Класс: BitrixTasksInternalsDataBasedeprecated
  • Вызов: deprecated::createLink
static function createLink($id, $parentId, $behaviour = array('LINK_DATA' => array()))
{
	static::applyCreateRestrictions($id, $parentId);

	if(!is_array($behaviour))
	{
		$behaviour = array();
	}

	if(!is_array($behaviour['LINK_DATA']))
	{
		$behaviour['LINK_DATA'] = array();
	}

	// check if parent exists. if not - add it
	if(!static::insertEdge($parentId, $parentId, false, 0, array('INCREMENT_MP_WHEN_EXISTS' => false)))
	{
		static::throwExceptionCantAddEdge($parentId, $parentId, false);
	}

	// check if link to itself exists. if not - add it
	if(!static::insertEdge($id, $id, false, 0, array('INCREMENT_MP_WHEN_EXISTS' => false)))
	{
		static::throwExceptionCantAddEdge($id, $id, false);
	}

	$fromPart = 	static::getParents($parentId);
	$toPart = 		static::getChildren($id);

	/*
	print_r('Parent: ('.$parentId.')'.PHP_EOL);
	print_r($fromPart);
	print_r('Child: ('.$id.')'.PHP_EOL);
	print_r($toPart);
	*/

	// link each child (including $id) to each parent (including $parentId)
	foreach($fromPart as $parent)
	{
		foreach($toPart as $child)
		{
			$increment = 0;
			$behaviourEdge = array();

			if($parent['ID'] == $parentId && $child['ID'] == $id) // special, direct linking to parent
			{
				$direct = true;
				$behaviourEdge = $behaviour;
			}
			else
			{
				$direct = false;

				if(intval($parent['MPCITY']) > 1)
				{
					$increment += intval($parent['MPCITY']);
				}
				if(intval($child['MPCITY']) > 1)
				{
					$increment += intval($child['MPCITY']);
				}
				$behaviourEdge['INCREMENT_MP_WHEN_EXISTS'] = true;
			}

			//print_r('Make '.$parent['ID'].' => '.$child['ID'].' with MPCITY = '.$increment.' DIRECT = '.$direct.PHP_EOL);

			if(!static::insertEdge($parent['ID'], $child['ID'], $direct, $increment, $behaviourEdge))
			{
				static::throwExceptionCantAddEdge($parent['ID'], $child['ID'], true);
			}
		}
	}

	return new AddResult();
}