- Модуль: learning
- Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnlesson.php
- Класс: CLearnLesson
- Вызов: CLearnLesson::DeleteRecursiveLikeHardlinks
static function DeleteRecursiveLikeHardlinks ($in_data)
{
list ($root_lesson_id, $simulate, $check_permissions, $user_id) =
self::_funcDelete_ParseOptions($in_data);
// list of lessons, which are candidates to be removed
$arCandidatesToRemove = array();
// Build list of all descendants (excluded duplicated)
$oTree = self::GetTree($root_lesson_id);
$arDescendantsList = $oTree->GetLessonsIdListInTree();
// Transform list: add list of immediate parents to every candidate
foreach ($arDescendantsList as $lesson_id)
{
$arParents = array();
$arEdges = self::ListImmediateParents($lesson_id);
foreach ($arEdges as $arEdgeData)
$arParents[] = (int) $arEdgeData['PARENT_LESSON'];
$arCandidatesToRemove[(int) $lesson_id] = $arParents;
}
// Now, move out parents of root lesson, because they mustn't be checked below.
$arCandidatesToRemove[$root_lesson_id] = array();
// Withdraw lessons, which has ancestors not among candidates to be removed
do
{
$lessonsWithdrawn = 0; // count of withdrawn lessons
foreach ($arCandidatesToRemove as $lesson_id => $arParents)
{
// Check that all parents are from candidates to be removed;
// otherwise $lesson_id must be withdrew from candidates
foreach ($arParents as $parent_lesson_id)
{
if ( ! array_key_exists((int) $parent_lesson_id, $arCandidatesToRemove) )
{
unset($arCandidatesToRemove[(int) $lesson_id]);
$lessonsWithdrawn++;
break; // we don't need to check other parents for this lesson anymore
}
}
}
}
while ($lessonsWithdrawn > 0);
// Now, broke edges and remove lessons.
// Broke edges to lessons in $arCandidatesToRemove list only.
foreach ($arCandidatesToRemove as $lesson_id => $arParents)
{
try
{
self::Delete(
array(
'lesson_id' => $lesson_id,
'simulate' => $simulate,
'check_permissions' => $check_permissions,
'user_id' => $user_id
)
);
}
catch (LearnException $e)
{
if ($e->GetCode() === LearnException::EXC_ERR_LL_UNREMOVABLE_CL)
; // course cannot be removed - ignore this error
elseif ($e->GetCode() === LearnException::EXC_ERR_ALL_ACCESS_DENIED)
{
// if lesson not exists - ignore error (lesson to be deleted is already removed)
$rsLesson = self::GetListUni(
array(),
array('LESSON_ID' => $lesson_id, 'CHECK_PERMISSIONS' => 'N'),
array('LESSON_ID'),
self::GET_LIST_ALL
);
if ( ! $rsLesson->fetch() )
{
; // ignore this situation, it's OK
}
else
{
// bubble exception
throw new LearnException ($e->GetMessage(), $e->GetCode());
}
}
else
{
// bubble exception
throw new LearnException ($e->GetMessage(), $e->GetCode());
}
}
}
}