- Модуль: bizproc
- Путь к файлу: ~/bitrix/modules/bizproc/lib/script/manager.php
- Класс: BitrixBizprocScriptManager
- Вызов: Manager::updateScript
static function updateScript($id, array $scriptFields, array $templateFields, $userId): MainResult
{
$script = static::getById($id);
if (!$script)
{
$result = new MainResult();
$result->addError(new MainError('Script not found'));
return $result;
}
$wl = array_fill_keys(['NAME', 'DESCRIPTION'], true);
$scriptFields = array_intersect_key($scriptFields, $wl);
$scriptFields['MODIFIED_BY'] = $userId;
$scriptFields['MODIFIED_DATE'] = new MainTypeDateTime();
$scriptUpdateResult = EntityScriptTable::update($script['ID'], $scriptFields);
if (!$scriptUpdateResult->isSuccess())
{
return $scriptUpdateResult;
}
$documentType = [$script['MODULE_ID'], $script['ENTITY'], $script['DOCUMENT_TYPE']];
$template = null;
$tpl = WorkflowTemplateTable::getById($script['WORKFLOW_TEMPLATE_ID'])->fetchObject();
if ($tpl)
{
$template = BitrixBizprocAutomationEngineTemplate::createByTpl($tpl);
}
if (!$template)
{
$template = new BitrixBizprocAutomationEngineTemplate($documentType);
}
$template->setName($scriptFields['NAME'] ?? $script->getName());
$robots = isset($templateFields['ROBOTS']) && is_array($templateFields['ROBOTS']) ? $templateFields['ROBOTS'] : [];
$result = $template->save($robots, $userId);
if ($result->isSuccess())
{
self::saveTemplateConfigs($template->getId(), $templateFields);
}
return $result;
}