简体   繁体   English

代理通过cron工作时如何修复1C Bitrix引擎中的隐藏错误

[英]How to fix hidden errors in engine of 1C Bitrix when agents work via cron

Sometimes when you make agents in 1C Bitrix that will change some data linked with users, you can catch some nasty errors. 有时,当您在1C Bitrix中制作代理来更改与用户链接的某些数据时,可能会遇到一些讨厌的错误。

These errors (just crashes without error messages) will occur only with cron . 仅使用cron会发生这些错误 (只是崩溃而没有错误消息)。

For example it happens when you work with orders in module "sale". 例如,当您使用模块“销售”中的订单时,就会发生这种情况。

It can be even worse, that it will happens not everytime. 更糟糕的是,这种情况并非每次都会发生。

Reason of this in most of the time is empty current User (object). 在大多数情况下,此原因是当前用户 (对象)为 It will happens when you try update or add new data. 当您尝试更新或添加新数据时,它将发生。 Selecting is always normal. 选择总是正常的。

So you need to check and create current User if there is no any. 因此,您需要检查并创建当前用户(如果没有)。 That's the code I use: 那是我使用的代码:

global $USER;
if (empty($USER)) {
    $USER = new CUser;
}
if (!$USER->IsAuthorized()) {
    // authorize as super admin
    $USER->Authorize(1);
} else {
    // alredy authorized, nothing need to do anymore
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM