PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.15
VikBooking Hotel Booking Engine & PMS v1.8.15
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / widgets / background_tasks.php

background_tasks.php in VikBooking Hotel Booking Engine & PMS 1.8.15, at admin/helpers/widgets/background_tasks.php

112 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - E4J srl
6 * @copyright Copyright (C) 2024 E4J srl. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 /**
14 * Class handler for admin widget "Background tasks".
15 *
16 * @since 1.17 (J) - 1.7 (WP)
17 */
18 class VikBookingAdminWidgetBackgroundTasks extends VikBookingAdminWidget
19 {
20 /** @var VBOCrontabSimulator */
21 private $crontab;
22
23 /**
24 * @inheritDOc
25 */
26 public function __construct()
27 {
28 // call parent constructor
29 parent::__construct();
30
31 $this->widgetName = 'Background Tasks';
32 $this->widgetDescr = 'Displays all the scheduled background tasks.';
33 $this->widgetId = basename(__FILE__, '.php');
34
35 $this->widgetIcon = '<i class="' . VikBookingIcons::i('server') . '"></i>';
36 $this->widgetStyleName = 'red';
37
38 try {
39 $this->crontab = VBOFactory::getCrontabSimulator();
40 } catch (Throwable $e) {
41 $this->crontab = [];
42 }
43 }
44
45 /**
46 * @inheritDoc
47 */
48 public function getPriority()
49 {
50 // always display as last widget
51 return 1;
52 }
53
54 /**
55 * @inheritDoc
56 */
57 public function preflight()
58 {
59 // can be used only if we have at least a scheduled task
60 return (bool) count($this->crontab);
61 }
62
63 /**
64 * @inheritDoc
65 */
66 public function render(?VBOMultitaskData $data = null)
67 {
68 $schedules = [];
69
70 foreach ($this->crontab as $runner) {
71 $lastExecution = $this->crontab->getSemaphore()->getLastExecution($runner);
72 $nextExecution = $runner->getNextExecution($lastExecution);
73
74 $schedules[] = [
75 'name' => ucwords(str_replace('_', ' ', $runner->getID())),
76 'last_execution' => JHtml::fetch('date', $lastExecution, 'Y-m-d H:i:s'),
77 'next_execution' => JHtml::fetch('date', $nextExecution, 'Y-m-d H:i:s'),
78 ];
79 }
80
81 $log = '';
82
83 try {
84 // assume we are using a file logger
85 $path = $this->crontab->getLogger()->getPath();
86
87 if (!JFile::exists($path)) {
88 throw new Exception('Log file not found', 404);
89 }
90
91 $fp = fopen($path, 'r');
92
93 while (!feof($fp)) {
94 $log .= fread($fp, 8192);
95 }
96
97 fclose($fp);
98 } catch (Throwable $error) {
99 // ignore log buffer
100 }
101
102 // display by using a specific layout provided by VCM
103 echo JLayoutHelper::render(
104 'sidepanel.widgets.crontab',
105 [
106 'schedules' => $schedules,
107 'log' => htmlentities($log),
108 ]
109 );
110 }
111 }
112