59 lines
2.5 KiB
PHP
Executable File
59 lines
2.5 KiB
PHP
Executable File
<?php
|
||
/*********************************************************************************
|
||
* API-интерфейс для изменения любой записи
|
||
* All Rights Reserved.
|
||
* Contributor(s): Илья Руденко itsaturn@yandex.ru
|
||
********************************************************************************/
|
||
|
||
include_once 'include/Webservices/Query.php';
|
||
include_once 'modules/Users/Users.php';
|
||
require_once('include/Webservices/Utils.php');
|
||
require_once 'include/Webservices/Revise.php';
|
||
require_once 'includes/Loader.php';
|
||
vimport ('includes.runtime.Globals');
|
||
vimport ('includes.runtime.BaseModel');
|
||
vimport ('includes.runtime.LanguageHandler');
|
||
|
||
function vtws_updateentity($crmid, $element, $user = false) {
|
||
$logstring = date("Y-m-d H:i:s").' '.$crmid.'; '.$element;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
|
||
if(empty($crmid) or empty($element)){
|
||
$logstring = date("Y-m-d H:i:s").' Не указано одно из обязательных полей: ID изменяеммой записи или массив полей';
|
||
file_put_contents('logs/UpdateEntity.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Не заполнены обязательные поля");
|
||
}
|
||
|
||
global $adb, $current_user;
|
||
|
||
$query = "select w.id
|
||
from vtiger_crmentity e
|
||
left join vtiger_ws_entity w on w.name = e.setype
|
||
where e.deleted = 0 and e.crmid = ?";
|
||
$result = $adb->pquery($query, array($crmid));
|
||
|
||
if ($adb->num_rows($result) == 0) {
|
||
$output = 'Запись с id = '.$crmid.' не найдена';
|
||
$logstring = date("Y-m-d H:i:s").' '.$output;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, $output);
|
||
}
|
||
|
||
$prefix = $adb->query_result($result, 0, 'id');
|
||
$element = json_decode($element, true);
|
||
$element['id'] = $prefix.'x'.$crmid;
|
||
|
||
try {
|
||
$entity = vtws_revise($element, $current_user);
|
||
$logstring = date('Y-m-d H:i:s').' Запись обновлена'.PHP_EOL;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring, FILE_APPEND);
|
||
$output = 'YES';
|
||
} catch (WebServiceException $ex) {
|
||
$output = $ex->getMessage();
|
||
$logstring = date('Y-m-d H:i:s').' '.$output.PHP_EOL;
|
||
file_put_contents('logs/UpdateEntity.log', $logstring, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, 'Ошибка при сохранении изменений в базе - см. журнал ошибок');
|
||
}
|
||
|
||
return $output;
|
||
} |