57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
set_time_limit(0);
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
|
header('Content-Type: application/json');
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
|
/**
|
|
* Агентства, по которым отправляются вебхуки
|
|
*/
|
|
$agencys = array();
|
|
$sql = "SELECT id, company_id, enable_webhooks FROM users WHERE enable_webhooks = 1";
|
|
|
|
$q = $pdo->query($sql);
|
|
while($r = $pdo->fetch_assoc($q)){
|
|
if($r['company_id'] > 0){
|
|
if(!in_array($r['company_id'], $agencys)){
|
|
$agencys[] = (int)$r['company_id'];
|
|
}
|
|
} else {
|
|
if(!in_array($r['id'], $agencys)){
|
|
$agencys[] = (int)$r['id'];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Поиск записей для отправки
|
|
*/
|
|
//$cr_ids = array();
|
|
if(!empty($agencys)){
|
|
$sql = "SELECT * FROM `webhook_logs` WHERE agency_id in (".implode(',', $agencys).") AND response_status <> 200 AND retry_count < 3 LIMIT 100";
|
|
$q = $pdo->query($sql);
|
|
while($r = $pdo->fetch_assoc($q)){
|
|
$cron_ids[] = (int)$r['id'];
|
|
if($r['agency_id'] > 0 && (int)$r['entity_id'] > 0){
|
|
$dataWhook = array('action'=>$r['event_type']);
|
|
$dataWhook['user_id'] = $r['initiator_user_id'];
|
|
$dataWhook['agency_id'] = $r['agency_id'];
|
|
$dataWhook['section'] = $r['entity_type'];
|
|
if($r['entity_type'] == 'object'){
|
|
$dataWhook['object_id'] = (int)$r['entity_id'];
|
|
} else if($r['entity_type'] == 'requisition'){
|
|
$dataWhook['req_id'] = (int)$r['entity_id'];
|
|
} else if($r['entity_type'] == 'client'){
|
|
$dataWhook['client_id'] = (int)$r['entity_id'];
|
|
}
|
|
$dataWhook['retry_id'] = (int)$r['id'];
|
|
|
|
$w_in = new WebHookIn(null, $r['agency_id']);
|
|
$w_in->check_send($dataWhook);
|
|
}
|
|
}
|
|
|
|
}
|