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 ) { |
||
34 | |||
35 | /** |
||
36 | * Start the tracking a backup process. |
||
37 | * |
||
38 | * This creates a backup running file and issues a file lock. This prevents duplicate |
||
39 | * instances of this backup process running concurrently and allows us to detect if |
||
40 | * the PHP thread running the process is killed as that will clear the lock. |
||
41 | * |
||
42 | * @param string $backup_filename The filename for the backup file that we're tracking |
||
43 | * @param string $status_message The initial status for the backup process |
||
44 | * |
||
45 | * @return boolean Whether the backup process was success marked as started |
||
46 | */ |
||
47 | public function start( $backup_filename, $status_message ) { |
||
58 | |||
59 | /** |
||
60 | * Mark a backup process as finished. |
||
61 | * |
||
62 | * This removes the file lock and deletes the running file. |
||
63 | */ |
||
64 | public function finish() { |
||
77 | |||
78 | /** |
||
79 | * Check if the backup has been started by checking if the runnign file |
||
80 | * exists. |
||
81 | * |
||
82 | * @return boolean Whether the backup process has been started |
||
83 | */ |
||
84 | public function is_started() { |
||
87 | |||
88 | public function is_running() { |
||
103 | |||
104 | /** |
||
105 | * If the running file exists but isn't locked then the thread that |
||
106 | * the backup process is running in must have been killed. |
||
107 | * |
||
108 | * You should only be running this command from a separate thread |
||
109 | * |
||
110 | * @return boolean Whether the backup process has crashed or not |
||
111 | */ |
||
112 | public function has_crashed() { |
||
115 | |||
116 | /** |
||
117 | * Get the filepath for the backup file we're tracking |
||
118 | * |
||
119 | * @return string The path to the backup file |
||
120 | */ |
||
121 | public function get_backup_filename() { |
||
133 | |||
134 | /** |
||
135 | * Get the status of the running backup. |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | public function get_status() { |
||
154 | |||
155 | /** |
||
156 | * Set the status of the running backup |
||
157 | * |
||
158 | * @param string $message |
||
159 | * |
||
160 | * @return null |
||
161 | */ |
||
162 | public function set_status( $message ) { |
||
182 | |||
183 | /** |
||
184 | * Get the time that the current running backup was started |
||
185 | * |
||
186 | * @return int $timestamp |
||
187 | */ |
||
188 | public function get_start_time() { |
||
203 | |||
204 | /** |
||
205 | * Get the path to the backup running file that stores the running backup status |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | public function get_status_filepath() { |
||
212 | |||
213 | public function set_status_callback( $callback ) { |
||
216 | } |
||
217 |
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: