PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / cron / job.php
vikappointments / site / helpers / libraries / cron Last commit date
overrides 5 days ago core.php 5 days ago dispatcher.php 5 days ago formbuilder.php 5 days ago formfield.php 5 days ago formfieldconstraints.php 5 days ago index.html 5 days ago job.php 5 days ago response.php 5 days ago
job.php
163 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * The class used to manage the procedure and the configuration of a CronJob.
16 *
17 * @since 1.5
18 * @since 1.7 Renamed from CronJob.
19 */
20 abstract class VAPCronJob
21 {
22 /**
23 * The unique identifier of the cron job.
24 *
25 * @var integer
26 */
27 private $id;
28
29 /**
30 * The list containing the settings of the cron job.
31 * The settings of the cron job cannot be directly accessed (@see get() method).
32 *
33 * @var array
34 */
35 private $args;
36
37 /**
38 * The construct of the cron job to initialize the required parameters of this object.
39 *
40 * @param integer $id The Cron Job ID.
41 * @param mixed $args The configuration array.
42 */
43 public function __construct($id, $args = array())
44 {
45 $this->id = $id;
46 $this->args = $args && is_string($args) ? json_decode($args, true) : (array) $args;
47 }
48
49 /**
50 * Sets the ID of the cron job.
51 *
52 * @param integer $id The record identifier.
53 *
54 * @return void
55 */
56 public function setID($id)
57 {
58 if (!$this->id)
59 {
60 // change ID only in case it was not set
61 $this->id = (int) $id;
62 }
63 }
64
65 /**
66 * Returns the ID of the cron job.
67 *
68 * @return integer The identifier of the cron job.
69 */
70 public function id()
71 {
72 return $this->id;
73 }
74
75 /**
76 * Returns the title of the cron job.
77 *
78 * @return string The title of the cron job.
79 */
80 public function title()
81 {
82 return '';
83 }
84
85 /**
86 * Returns the description of the cron job.
87 *
88 * @return string The description of the cron job.
89 *
90 * @since 1.7
91 */
92 public function description()
93 {
94 return '';
95 }
96
97 /**
98 * Returns the value of the setting specified. An empty value if the setting doesn't exist.
99 * The settings of the cronjob are not accessible from external classes.
100 *
101 * @param string $key The name of the setting.
102 * @param mixed $def The default value to get if the
103 * setting doesn't exist.
104 *
105 * @return string The value of the setting.
106 */
107 protected function get($key, $def = '')
108 {
109 if (array_key_exists($key, $this->args))
110 {
111 return $this->args[$key];
112 }
113
114 return $def;
115 }
116
117 /**
118 * Performs the work that the cron job should do.
119 *
120 * @return VAPCronJobResponse The response of the job.
121 */
122 public abstract function doJob();
123
124 /**
125 * Returns the fields of the configuration in an array.
126 *
127 * @return array The fields list used for the configuration.
128 */
129 public function getConfiguration()
130 {
131 return array();
132 }
133
134 /**
135 * This function is called only once during the installation of the cron job.
136 * Returns true on success, otherwise false.
137 *
138 * @return boolean The status of the installation.
139 */
140 public function install()
141 {
142 return true;
143 }
144
145 /**
146 * This function is called only once during the uninstallation of the cron job.
147 * Returns true on success, otherwise false.
148 *
149 * @return boolean The status of the uninstallation.
150 */
151 public function uninstall()
152 {
153 return true;
154 }
155 }
156
157 /**
158 * Register a class alias for backward compatibility.
159 *
160 * @deprecated 1.8
161 */
162 class_alias('VAPCronJob', 'CronJob');
163