Skip to content

Commit

Permalink
Updates regarding canned messages statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Aug 25, 2021
1 parent 7b3f473 commit 7bd5eb7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 74 deletions.
2 changes: 1 addition & 1 deletion lhc_web/cli/lib/install.php
Expand Up @@ -259,7 +259,7 @@ function step3() {
KEY `department_id` (`department_id`)) ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");

$db->query("CREATE TABLE `lh_chat_event_track` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `data` longtext NOT NULL, `department_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `department_id` (`department_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
$db->query("CREATE TABLE `lh_canned_msg_use` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `canned_id` int(11) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `ctime` (`ctime`), KEY `canned_id` (`canned_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
$db->query("CREATE TABLE `lh_canned_msg_use` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `canned_id` int(11) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `chat_id` (`chat_id`), KEY `ctime` (`ctime`), KEY `canned_id` (`canned_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");

$db->query("CREATE TABLE IF NOT EXISTS `lh_chat_archive_range` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand Down
2 changes: 1 addition & 1 deletion lhc_web/doc/update_db/structure.json
Expand Up @@ -9926,6 +9926,6 @@
"lh_chat_incoming" : "CREATE TABLE `lh_chat_incoming` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `chat_id` bigint(20) NOT NULL, `utime` bigint(20) NOT NULL, `incoming_id` int(11) NOT NULL, `payload` longtext NOT NULL, `chat_external_id` varchar(50) NOT NULL, PRIMARY KEY (`id`), KEY `chat_id` (`chat_id`), KEY `incoming_ext_id` (`incoming_id`,`chat_external_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lh_canned_msg_dep" : "CREATE TABLE `lh_canned_msg_dep` (`id` bigint(20) NOT NULL AUTO_INCREMENT,`canned_id` int(11) NOT NULL,`dep_id` int(11) NOT NULL,PRIMARY KEY (`id`), KEY `canned_id` (`canned_id`),KEY `dep_id` (`dep_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lh_canned_msg_subject" : "CREATE TABLE `lh_canned_msg_subject` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `canned_id` int(11) NOT NULL,\n `subject_id` int(11) NOT NULL,\n PRIMARY KEY (`id`),\n KEY `canned_id` (`canned_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"lh_canned_msg_use" : "CREATE TABLE `lh_canned_msg_use` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `canned_id` int(11) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `ctime` (`ctime`), KEY `canned_id` (`canned_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
"lh_canned_msg_use" : "CREATE TABLE `lh_canned_msg_use` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `canned_id` int(11) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `chat_id` (`chat_id`), KEY `ctime` (`ctime`), KEY `canned_id` (`canned_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
}
}
2 changes: 1 addition & 1 deletion lhc_web/doc/update_db/update_253.sql
@@ -1 +1 @@
CREATE TABLE `lh_canned_msg_use` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `canned_id` int(11) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `ctime` (`ctime`), KEY `canned_id` (`canned_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `lh_canned_msg_use` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `canned_id` int(11) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `ctime` (`ctime`), KEY `chat_id` (`chat_id`), KEY `canned_id` (`canned_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
96 changes: 26 additions & 70 deletions lhc_web/lib/models/lhchat/erlhcoreclassmodelchat.php
Expand Up @@ -128,56 +128,23 @@ public function getState()
public function beforeRemove()
{
$q = ezcDbInstance::get()->createDeleteQuery();

// Messages
$q->deleteFrom( 'lh_msg' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Transfered chats
$q->deleteFrom( 'lh_transfer' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Delete user footprint
$q->deleteFrom( 'lh_chat_online_user_footprint' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Delete screen sharing
$q->deleteFrom( 'lh_cobrowse' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Delete speech settings
$q->deleteFrom( 'lh_speech_chat_language' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Survey
$q->deleteFrom( 'lh_abstract_survey_item' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Paid chats
$q->deleteFrom( 'lh_chat_paid' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Subjects
$q->deleteFrom( 'lh_abstract_subject_chat' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Voice calls
$q->deleteFrom( 'lh_chat_voice_video' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Incoming chats
$q->deleteFrom( 'lh_chat_incoming' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

foreach ([
'lh_msg',
'lh_transfer',
'lh_chat_online_user_footprint',
'lh_cobrowse',
'lh_speech_chat_language',
'lh_abstract_survey_item',
'lh_chat_paid',
'lh_abstract_subject_chat',
'lh_chat_voice_video',
'lh_chat_incoming',
'lh_canned_msg_use'] as $table){
$q->deleteFrom($table)->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();
}

$this->removePendingEvents();

Expand All @@ -188,26 +155,15 @@ public function beforeRemove()

public function removePendingEvents() {
$q = ezcDbInstance::get()->createDeleteQuery();

// Auto responder chats
$q->deleteFrom( 'lh_abstract_auto_responder_chat' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Repeat counter remove
$q->deleteFrom( 'lh_generic_bot_repeat_restrict' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Bot chat event remove
$q->deleteFrom( 'lh_generic_bot_chat_event' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();

// Bot chat event remove
$q->deleteFrom( 'lh_generic_bot_pending_event' )->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();
foreach ([
'lh_abstract_auto_responder_chat',
'lh_generic_bot_repeat_restrict',
'lh_generic_bot_chat_event',
'lh_generic_bot_pending_event'] as $table){
$q->deleteFrom($table)->where( $q->expr->eq( 'chat_id', $this->id ) );
$stmt = $q->prepare();
$stmt->execute();
}
}

public function afterRemove()
Expand Down
2 changes: 1 addition & 1 deletion lhc_web/modules/lhinstall/install.php
Expand Up @@ -2033,7 +2033,7 @@

$db->query("CREATE TABLE `lh_abstract_chat_column` (`id` int(11) NOT NULL AUTO_INCREMENT,`column_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,`variable` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `position` int(11) NOT NULL, `enabled` tinyint(1) NOT NULL, `online_enabled` tinyint(1) NOT NULL, `chat_enabled` tinyint(1) NOT NULL, `conditions` text COLLATE utf8mb4_unicode_ci NOT NULL,`column_icon` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `column_identifier` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `enabled` (`enabled`), KEY `online_enabled` (`online_enabled`), KEY `chat_enabled` (`chat_enabled`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
$db->query("CREATE TABLE `lh_abstract_chat_priority` (`id` int(11) NOT NULL AUTO_INCREMENT,`value` text COLLATE utf8mb4_unicode_ci NOT NULL,`dep_id` int(11) NOT NULL, `dest_dep_id` int(11) NOT NULL DEFAULT 0, `sort_priority` int(11) NOT NULL DEFAULT 0,`priority` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `dep_id` (`dep_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
$db->query("CREATE TABLE `lh_canned_msg_use` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `canned_id` int(11) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `ctime` (`ctime`), KEY `canned_id` (`canned_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
$db->query("CREATE TABLE `lh_canned_msg_use` (`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `canned_id` int(11) unsigned NOT NULL, `chat_id` bigint(20) unsigned NOT NULL, `ctime` bigint(20) unsigned NOT NULL, `user_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `ctime` (`ctime`), KEY `chat_id` (`chat_id`), KEY `canned_id` (`canned_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");


// Session
Expand Down
4 changes: 4 additions & 0 deletions lhc_web/modules/lhstatistic/statistic.php
Expand Up @@ -454,6 +454,10 @@
$statisticOptions->value = serialize($configuration);
$statisticOptions->saveThis();

// Need to clear cache because messages might start to collect canned messages usage statistic
$CacheManager = erConfigClassLhCacheConfig::getInstance();
$CacheManager->expireCache();

$tpl->set('updated', true);
}

Expand Down

0 comments on commit 7bd5eb7

Please sign in to comment.