BaseTarget :: setTriggers: Bitrix method

      
<?php 
//  Bitrix\Bizproc\Automation\Target\BaseTarget :: setTriggers()
//  /dist/bitrix/modules/bizproc/lib/automation/target/basetarget.php:82

    
public function setTriggers(array $triggers)
    {
        
$updatedTriggers = [];
        foreach (
$triggers as $trigger)
        {
            
$triggerId = isset($trigger['ID']) ? (int)$trigger['ID'] : 0;

            if (isset(
$trigger['DELETED']) && $trigger['DELETED'] === 'Y')
            {
                if (
$triggerId 0)
                {
                    
//TODO: check document type
                    
TriggerTable::delete($triggerId);
                }
                continue;
            }

            if (
$triggerId 0)
            {
                
TriggerTable::update($triggerId, array(
                    
'NAME' => $trigger['NAME'],
                    
'DOCUMENT_STATUS' => $trigger['DOCUMENT_STATUS'],
                    
'APPLY_RULES' => is_array($trigger['APPLY_RULES']) ? $trigger['APPLY_RULES'] : null
                
));
            }
            elseif (isset(
$trigger['CODE']) && isset($trigger['DOCUMENT_STATUS']))
            {
                
$documentType $this->getDocumentType();
                
$addResult TriggerTable::add(array(
                    
'NAME' => $trigger['NAME'],
                    
'MODULE_ID' => $documentType[0],
                    
'ENTITY' => $documentType[1],
                    
'DOCUMENT_TYPE' => $documentType[2],
                    
'DOCUMENT_STATUS' => $trigger['DOCUMENT_STATUS'],
                    
'CODE' => $trigger['CODE'],
                    
'APPLY_RULES' => is_array($trigger['APPLY_RULES']) ? $trigger['APPLY_RULES'] : null
                
));

                if (
$addResult->isSuccess())
                {
                    
$trigger['ID'] = $addResult->getId();
                }
            }
            
$updatedTriggers[] = $trigger;
        }

        return 
$updatedTriggers;
    }