1 | <?php |
||
10 | class Backup_Status { |
||
11 | |||
12 | /** |
||
13 | * The filename for the backup file we are the tracking status of |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | private $filename = ''; |
||
18 | |||
19 | /** |
||
20 | * [$lock_handler description] |
||
21 | * |
||
22 | * @var LockHandler |
||
23 | */ |
||
24 | private $lock_handler = ''; |
||
25 | |||
26 | private $callback; |
||
27 | |||
28 | /** |
||
29 | * @param string $id The unique id for the backup job |
||
30 | */ |
||
31 | public function __construct( $id ) { |
||
35 | |||
36 | /** |
||
37 | * Start the tracking a backup process. |
||
38 | * |
||
39 | * This creates a backup running file and issues a file lock. This prevents duplicate |
||
40 | * instances of this backup process running concurrently and allows us to detect if |
||
41 | * the PHP thread running the process is killed as that will clear the lock. |
||
42 | * |
||
43 | * @param string $backup_filename The filename for the backup file that we're tracking |
||
44 | * @param string $status_message The initial status for the backup process |
||
45 | * |
||
46 | * @return boolean Whether the backup process was success marked as started |
||
47 | */ |
||
48 | public function start( $backup_filename, $status_message ) { |
||
59 | |||
60 | /** |
||
61 | * Mark a backup process as finished. |
||
62 | * |
||
63 | * This removes the file lock and deletes the running file. |
||
64 | */ |
||
65 | public function finish() { |
||
78 | |||
79 | /** |
||
80 | * Check if the backup has been started by checking if the runnign file |
||
81 | * exists. |
||
82 | * |
||
83 | * @return boolean Whether the backup process has been started |
||
84 | */ |
||
85 | public function is_started() { |
||
88 | |||
89 | public function is_running() { |
||
104 | |||
105 | /** |
||
106 | * If the running file exists but isn't locked then the thread that |
||
107 | * the backup process is running in must have been killed. |
||
108 | * |
||
109 | * You should only be running this command from a separate thread |
||
110 | * |
||
111 | * @return boolean Whether the backup process has crashed or not |
||
112 | */ |
||
113 | public function has_crashed() { |
||
116 | |||
117 | /** |
||
118 | * Handle a process that's previouly crashed |
||
119 | * |
||
120 | * If the partially created backup exists then delete it. |
||
121 | * |
||
122 | * @return bool Whether the crash was handled or not |
||
123 | */ |
||
124 | public function cleanup_after_crash() { |
||
142 | |||
143 | /** |
||
144 | * Get the filepath for the backup file we're tracking |
||
145 | * |
||
146 | * @return string The path to the backup file |
||
147 | */ |
||
148 | public function get_backup_filename() { |
||
160 | |||
161 | /** |
||
162 | * Get the status of the running backup. |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | public function get_status() { |
||
181 | |||
182 | /** |
||
183 | * Set the status of the running backup |
||
184 | * |
||
185 | * @param string $message |
||
186 | * |
||
187 | * @return null |
||
188 | */ |
||
189 | public function set_status( $message ) { |
||
209 | |||
210 | /** |
||
211 | * Get the time that the current running backup was started |
||
212 | * |
||
213 | * @return int $timestamp |
||
214 | */ |
||
215 | public function get_start_time() { |
||
230 | |||
231 | /** |
||
232 | * Get the path to the backup running file that stores the running backup status |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | public function get_status_filepath() { |
||
239 | |||
240 | public function set_status_callback( $callback ) { |
||
243 | } |
||
244 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: