Skip to content

Instantly share code, notes, and snippets.

@Feiron
Last active June 9, 2021 11:20
Show Gist options
  • Save Feiron/d644a14a239fc26afbfaabda29b9f7ee to your computer and use it in GitHub Desktop.
Save Feiron/d644a14a239fc26afbfaabda29b9f7ee to your computer and use it in GitHub Desktop.
[Testing BP создаем / выводим лог, оптционально удаляем все] #bitrix #bp
<?
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php");
$APPLICATION->SetTitle("Тестирование");
CModule::IncludeModule('gpw.testing');
CModule::IncludeModule('im');
CModule::IncludeModule('bizproc');
$iTemplateID = XXX;
$ID = 15949;
$arDocumentID = [
"crm",
"CCrmDocumentDeal",
"DEAL_" . $ID
];
$arFields = [
//'RATE' => 6,
//'UF_CRM_EMAIL' => ['n0' => 'web@gpw.eu']
];
try {
GPW\Testing\Tests\Bitrix\BP::Run($iTemplateID, $arDocumentID, $arFields, ['STORE' => false]);
} catch (\Exception $e) {
ShowError($e->getMessage());
if(method_exists($e, 'getParameter')){
echo '<pre>'; var_dump($e->getParameter()); echo '</pre>';
}
}
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php");
?>
<?php
$this->WriteToTrackingService($strAddInfo);
$this->SetVariable("BB_ADDINFO", $strAddInfo);
$this->GetVariable("BB_ADDINFO");
$RootActivity = $this->GetRootActivity();
$iUserID = $RootActivity->RESPONSIBLE;
<?php
/**
* User: Feiron
* Date: 04.06.2018
* Time: 15:37
*
* @var array $arParams
* @var array $arResult
* @global CMain $APPLICATION
*
*
*/
namespace GPW\Testing\Tests\Bitrix;
use Bitrix\Main\ArgumentException;
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
class BP
{
/**
* @param $iTemplateID
* @param $arDocumentID
* @param $arFields
* @param [] $arParams SILENT = Нет вывода трейса, STORE - Оставить результат
*
* @throws \Exception
*/
public static function Run($iTemplateID, $arDocumentID, $arFields, $arParams)
{
try {
$wid = self::Start($iTemplateID, $arDocumentID, $arFields);
$strLog = self::GetTrackingByWID($wid);
if (!$arParams['SILENT']) {
echo $strLog;
}
if (!$arParams['STORE']) {
self::Delete($wid);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* @param $WID
* @param bool $bTerminate Останавливает, если нельзя дает ошибку
* @param null $arDocumentID Необязательно
*/
public static function Delete($WID, $bTerminate = false, $arDocumentID = null)
{
\CBPDocument::killWorkflow($WID, $bTerminate, $arDocumentID);
}
/**
* @param $iTemplateID
* @param $arDocumentID ["crm", "CCrmDocumentDeal", "DEAL_11"]
* @param $arFields
*
* @return string
* @throws \Exception
*/
public static function Start($iTemplateID, $arDocumentID, $arFields = [])
{
$dbWorkflowTemplate = \CBPWorkflowTemplateLoader::GetList(
array(),
array(
"ID" => $iTemplateID,
),
false,
false,
array("ID", "NAME", "DESCRIPTION", "MODIFIED", "USER_ID", "PARAMETERS")
);
if ($dbWorkflowTemplate->SelectedRowsCount() < 0) {
throw new \Exception('TEMPLATE_NOT_FOUND');
}
$arWorkflowTemplate = $dbWorkflowTemplate->Fetch();
$arWorkflowParameters = \CBPWorkflowTemplateLoader::CheckWorkflowParameters(
$arWorkflowTemplate["PARAMETERS"],
$arFields,
$arDocumentID,
$arErrors
);
if (empty($arErrors)) {
$wid = \CBPDocument::StartWorkflow(
$iTemplateID,
$arDocumentID,
$arWorkflowParameters,
$arErrors
);
if (empty($arErrors)) {
return $wid;
}
throw new \Exception('INVALID_PARAMETERS', $arErrors);
}
throw new ArgumentException('INVALID_PARAMETERS', $arErrors);
}
/**
* @param $WID
*
* @return string
* @throws \Exception
*/
public static function GetTrackingByWID($WID)
{
$dbTrack = \CBPTrackingService::GetList(
array("ID" => "desc"),
array(
"WORKFLOW_ID" => $WID,
)
);
if ($dbTrack->SelectedRowsCount()) {
$arTask = \CBPStateService::GetWorkflowState($WID);
ob_start();
?>
<div><?= $arTask['ID'] ?></div>
<div><?= $arTask['STARTED'] ?></div>
<div><?= $arTask['TEMPLATE_DESCRIPTION'] ?></div>
<div><?= $arTask['STATE_NAME'] ?><br><?= $arTask['STATE_TITLE'] ?></div>
<table style="width: 700px;">
<thead>
<tr>
<th>Тип</th>
<th>Дата</th>
<th>Имя</th>
<th>Статус</th>
<th>Текст</th>
</tr>
</thead>
<tbody>
<?
while ($arTrack = $dbTrack->Fetch()) {
?>
<tr>
<td><?= $arTrack['TYPE'] ?></td>
<td><?= $arTrack['MODIFIED'] ?></td>
<td><?= $arTrack['ACTION_NAME'] ?><br><?= $arTrack['ACTION_TITLE'] ?></td>
<td><?= $arTrack['EXECUTION_STATUS'] ?></td>
<td>
<textarea readonly="" name="ACTION_NOTE" id="" cols="60" rows="4"><?= $arTrack['ACTION_NOTE'] ?></textarea>
</td>
</tr>
<?
}
?>
</tbody>
</table>
<?
return (string)ob_get_clean();
} else {
throw new \Exception('CANT_GET_TRACE: ' . $WID);
}
}
}
@Feiron
Copy link
Author

Feiron commented Mar 5, 2019

$iTemplateID   = YYY;
$ID            = XXX;
$arDocumentID = array(
	"crm",
	"CCrmDocumentDeal",
	"DEAL_" . $ID
);
try {
	GPW\Testing\Tests\Bitrix\BP::Run($iTemplateID, $arDocumentID, [], ['STORE' => true]);

} catch (\Exception $e) {
	ShowError($e->getMessage());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment