PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.4
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.4
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Hooks / Handlers / CleanupHandler.php

CleanupHandler.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.5.4, at app/Hooks/Handlers/CleanupHandler.php

93 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Hooks\Handlers;
4
5 use FluentSupport\App\Models\Activity;
6 use FluentSupport\App\Models\Attachment;
7 use FluentSupport\App\Models\Meta;
8 use FluentSupport\App\Services\EmailNotification\Settings;
9 use FluentSupport\App\Services\Helper;
10 use FluentSupport\App\Services\Includes\FileSystem;
11
12 class CleanupHandler
13 {
14 public function initHourlyTasks()
15 {
16 $this->cleanLiveActivities();
17 }
18
19 public function initDailyTasks()
20 {
21 $this->cleanActivityLogs();
22 }
23
24 protected function cleanLiveActivities()
25 {
26 // Delete All Live Activity older than 24 hours
27 $oldDateTime = date('Y-m-d H:i:s', strtotime(current_time('mysql')) - 86400);
28
29 Meta::where('key', '_live_activity')
30 ->where('object_type', 'ticket_meta')
31 ->where('updated_at', '<', $oldDateTime)
32 ->delete();
33 }
34
35 protected function cleanActivityLogs()
36 {
37 $settings = Helper::getOption('_activity_settings', []);
38
39 if (!$settings && empty($settings['delete_days'])) {
40 $settings['delete_days'] = 14;
41 }
42
43 $oldDateTime = date('Y-m-d H:i:s', strtotime(current_time('mysql')) - ($settings['delete_days'] * 86400));
44
45 Activity::where('created_at', '<', $oldDateTime)->delete();
46 }
47
48 public function maybeDeleteAttachmentsOnClose($ticket)
49 {
50 $settings = (new Settings())->globalBusinessSettings();
51 if ($settings['del_files_on_close'] == 'yes') {
52 $this->deleteTicketAttachments($ticket);
53 }
54 }
55
56 public function deleteTicketAttachments($ticket)
57 {
58 $uploadDir = wp_upload_dir();
59 $dir = $uploadDir['basedir'] . FLUENT_SUPPORT_UPLOAD_DIR;
60
61 $attachments = Attachment::where('ticket_id', $ticket->id)->get();
62
63 if (!$attachments->isEmpty()) {
64 $ticketDir = $dir . '/ticket_' . $ticket->id;
65 if (is_dir($ticketDir)) {
66 $this->deleteDir($ticketDir);
67 }
68
69 foreach ($attachments as $attachment) {
70 if ($attachment->driver != 'local') {
71 continue;
72 }
73 if (file_exists($attachment->file_path)) {
74 @unlink($attachment->file_path);
75 }
76 }
77
78 Attachment::where('ticket_id', $ticket->id)->delete();
79 }
80
81 }
82
83 private function deleteDir($dir)
84 {
85 if (!class_exists('\WP_Filesystem_Direct')) {
86 require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
87 require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
88 }
89 $fileSystemDirect = new \WP_Filesystem_Direct(false);
90 $fileSystemDirect->rmdir($dir, true);
91 }
92 }
93