Skip to content

Commit 3e2bef8

Browse files
committed
Support debug for custom abandoned and dropped rules
1 parent 585049e commit 3e2bef8

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

lhc_web/design/defaulttheme/tpl/lhchat/modifychat.tpl.php

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,61 @@
155155
$debugString = ' ('.$chat->lsync .'[lsync] > (' . $chat->pnd_time . '[pnd_time] + ' . $chat->wait_time . '[wait_time]) && ' . $chat->has_unread_op_messages.'[has_unread_op_messages] == 1 && ' . $chat->user_id. '[user_id] > 0 )';
156156
$patterns['drpd'] = '{debug.drpd} = ' . ($chat->lsync > ($chat->pnd_time + $chat->wait_time) && $chat->has_unread_op_messages == 1 && $chat->user_id > 0 ? 1 : 0) . $debugString . ' Visitor was online while chat was accepted, but left before operator replied';
157157

158+
$dropped_sql = (string)erLhcoreClassModelChatConfig::fetch('dropped_sql')->current_value;
159+
$dropped_sql_result = null;
160+
$dropped_sql_debug = '';
161+
if (!empty($dropped_sql)) {
162+
$chatState = $chat->getState();
163+
$dropped_sql_debug = preg_replace_callback('/`([a-z_]+)`/', function($matches) use ($chatState) {
164+
$val = isset($chatState[$matches[1]]) ? $chatState[$matches[1]] : 0;
165+
return $val . '[' . $matches[1] . ']';
166+
}, $dropped_sql);
167+
$evalSql = preg_replace_callback('/`([a-z_]+)`/', function($matches) use ($chatState) {
168+
return isset($chatState[$matches[1]]) ? (int)$chatState[$matches[1]] : 0;
169+
}, $dropped_sql);
170+
$evalSql = preg_replace('/\bAND\b/i', '&&', $evalSql);
171+
$evalSql = preg_replace('/\bOR\b/i', '||', $evalSql);
172+
$evalSql = preg_replace('/(?<![><!])=(?!=)/', '==', $evalSql);
173+
try {
174+
$dropped_sql_result = eval('return (int)(bool)(' . $evalSql . ');');
175+
} catch (\Throwable $e) {
176+
$dropped_sql_result = 'error: ' . $e->getMessage();
177+
}
178+
}
179+
180+
$abandoned_sql = (string)erLhcoreClassModelChatConfig::fetch('abandoned_sql')->current_value;
181+
$abandoned_sql_result = null;
182+
$abandoned_sql_debug = '';
183+
if (!empty($abandoned_sql)) {
184+
$chatState = $chat->getState();
185+
$abandoned_sql_debug = preg_replace_callback('/`([a-z_]+)`/', function($matches) use ($chatState) {
186+
$val = isset($chatState[$matches[1]]) ? $chatState[$matches[1]] : 0;
187+
return $val . '[' . $matches[1] . ']';
188+
}, $abandoned_sql);
189+
$evalSql = preg_replace_callback('/`([a-z_]+)`/', function($matches) use ($chatState) {
190+
return isset($chatState[$matches[1]]) ? (int)$chatState[$matches[1]] : 0;
191+
}, $abandoned_sql);
192+
$evalSql = preg_replace('/\bAND\b/i', '&&', $evalSql);
193+
$evalSql = preg_replace('/\bOR\b/i', '||', $evalSql);
194+
$evalSql = preg_replace('/(?<![><!])=(?!=)/', '==', $evalSql);
195+
try {
196+
$abandoned_sql_result = eval('return (int)(bool)(' . $evalSql . ');');
197+
} catch (\Throwable $e) {
198+
$abandoned_sql_result = 'error: ' . $e->getMessage();
199+
}
200+
}
201+
158202
?>
159203

160204
<ul class="fs11">
161-
<li><?php echo htmlspecialchars($patterns['abnd'])?></li>
162-
<li><?php echo htmlspecialchars($patterns['drpd'])?></li>
205+
<li><?php echo htmlspecialchars($patterns['abnd'])?> <br><b>((`lsync` < (`pnd_time` + `wait_time`) AND `wait_time` > 1) OR (`lsync` > (`pnd_time` + `wait_time`) AND `wait_time` > 1 AND `user_id` = 0))</b></li>
206+
<?php if (!empty($abandoned_sql)) : ?>
207+
<li>{debug.abnd_custom} = <?php echo $abandoned_sql_result; ?> (<?php echo htmlspecialchars($abandoned_sql_debug); ?>)<br><b><?php echo htmlspecialchars($abandoned_sql);?></b></li>
208+
<?php endif;?>
209+
<li><?php echo htmlspecialchars($patterns['drpd'])?> <br><b>(`lsync` > (`pnd_time` + `wait_time`) AND `has_unread_op_messages` = 1 AND `user_id` > 0)</b></li>
210+
<?php if (!empty($dropped_sql)) : ?>
211+
<li>{debug.drpd_custom} = <?php echo $dropped_sql_result; ?> (<?php echo htmlspecialchars($dropped_sql_debug); ?>)<br><b><?php echo htmlspecialchars($dropped_sql);?></b></li>
212+
<?php endif;?>
163213
</ul>
164214

165215
<h6><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/modifychat','Duration calculation log');?></h6>

0 commit comments

Comments
 (0)