Template::fullDelete

  1. Bitrix24 API (v. 23.675.0)
  2. tasks
  3. Template
  4. fullDelete
  • Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/control/template.php
  • Класс: BitrixTasksControlTemplate
  • Вызов: Template::fullDelete
private function fullDelete(): bool
{
	$template = $this->getTemplateData();

	// delete syslog records
	SystemLog::deleteByEntity($this->templateId, 1);

	// delete files
	if ($template["FILES"])
	{
		$files = unserialize($template["FILES"], ['allowed_classes' => false]);
		if (is_array($files))
		{
			$filesToDelete = array();
			foreach ($files as $file)
			{
				$rsFile = CTaskFiles::GetList([], ["FILE_ID" => $file]);
				if (!$arFile = $rsFile->Fetch())
				{
					$filesToDelete[] = $file;
				}
			}
			foreach ($filesToDelete as $file)
			{
				CFile::Delete($file);
			}
		}
	}

	// delete checklist
	TemplateCheckListFacade::deleteByEntityIdOnLowLevel($this->templateId);

	// delete access rights
	BitrixTasksItemAccessTaskTemplate::revokeAll($this->templateId, ['CHECK_RIGHTS' => false]);

	TemplateMemberTable::deleteList([
		'=TEMPLATE_ID' => $this->templateId,
	]);

	TemplateTagTable::deleteList([
		'=TEMPLATE_ID' => $this->templateId,
	]);

	TemplateDependenceTable::deleteList([
		'=TEMPLATE_ID' => $this->templateId,
	]);

	ScenarioTable::delete($this->templateId);

	// delete sub templates
	if ($this->deleteSubTemplates)
	{
		$subTemplatesBdResult = DependenceTable::getSubTree($this->templateId, ['select' => ['ID' => 'TEMPLATE_ID']], ['INCLUDE_SELF' => false]);
		while ($subTemplateItem = $subTemplatesBdResult->fetch())
		{
			$manager = new self($this->userId);
			if ($this->unsafeDelete)
			{
				$manager->withUnsafeDelete();
			}
			if ($this->deleteSubTemplates)
			{
				$manager->withDeleteSubTemplates();
			}
			$manager->delete((int)$subTemplateItem['ID']);
		}

		try
		{
			DependenceTable::deleteSubtree($this->templateId);
		}
		catch (TargetNodeNotFoundException $e)
		{
			// had no children, actually don't care
		}
	}

	// delete user fields
	$this->ufManager->Delete("TASKS_TASK_TEMPLATE", $this->templateId);

	$res = TemplateTable::delete($this->templateId);

	return $res->isSuccess();
}

Добавить комментарий