Last active
June 9, 2021 11:20
-
-
Save Feiron/d644a14a239fc26afbfaabda29b9f7ee to your computer and use it in GitHub Desktop.
[Testing BP создаем / выводим лог, оптционально удаляем все] #bitrix #bp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
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"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$this->WriteToTrackingService($strAddInfo); | |
$this->SetVariable("BB_ADDINFO", $strAddInfo); | |
$this->GetVariable("BB_ADDINFO"); | |
$RootActivity = $this->GetRootActivity(); | |
$iUserID = $RootActivity->RESPONSIBLE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
} |
Author
Feiron
commented
Mar 5, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment