1 | <?php |
||
15 | class Object_Sync_Sf_Logging extends WP_Logging { |
||
16 | |||
17 | protected $wpdb; |
||
18 | protected $version; |
||
19 | protected $slug; |
||
20 | protected $option_prefix; |
||
21 | |||
22 | public $enabled; |
||
23 | public $statuses_to_log; |
||
24 | |||
25 | |||
26 | /** |
||
27 | * Constructor which sets content type and pruning for logs |
||
28 | * |
||
29 | * @param object $wpdb An instance of the wpdb class. |
||
30 | * @param string $version The version of this plugin. |
||
31 | * @param string $slug The plugin slug |
||
32 | * @param string $option_prefix The plugin's option prefix |
||
33 | * @throws \Exception |
||
34 | */ |
||
35 | public function __construct( $wpdb, $version, $slug = '', $option_prefix = '' ) { |
||
49 | |||
50 | /** |
||
51 | * Start. This creates a schedule for pruning logs, and also the custom content type |
||
52 | * |
||
53 | * @throws \Exception |
||
54 | */ |
||
55 | private function init() { |
||
74 | |||
75 | public function set_log_visibility( $log_args ) { |
||
98 | |||
99 | /** |
||
100 | * Add interval to wp schedules based on admin settings |
||
101 | * |
||
102 | * @param array $schedules An array of scheduled cron items. |
||
103 | * @return array $frequency |
||
104 | */ |
||
105 | public function add_prune_interval( $schedules ) { |
||
121 | |||
122 | /** |
||
123 | * Convert the schedule frequency from the admin settings into an array |
||
124 | * interval must be in seconds for the class to use it |
||
125 | * |
||
126 | * @param string $unit A unit of time. |
||
127 | * @param number $number The number of those units. |
||
128 | * @return array |
||
129 | */ |
||
130 | public function get_schedule_frequency( $unit, $number ) { |
||
154 | |||
155 | /** |
||
156 | * Set terms for Salesforce logs |
||
157 | * |
||
158 | * @param array $terms An array of string log types in the WP_Logging class. |
||
159 | * @return array $terms |
||
160 | */ |
||
161 | public function set_log_types( $terms ) { |
||
165 | |||
166 | /** |
||
167 | * Should logs be pruned at all? |
||
168 | * |
||
169 | * @param string $should_we_prune Whether to prune old log items. |
||
170 | * @return string $should_we_prune Whether to prune old log items. |
||
171 | */ |
||
172 | public function set_prune_option( $should_we_prune ) { |
||
179 | |||
180 | /** |
||
181 | * Set how often to prune the Salesforce logs |
||
182 | * |
||
183 | * @param string $how_old How old the oldest non-pruned log items should be allowed to be. |
||
184 | * @return string $how_old |
||
185 | */ |
||
186 | public function set_prune_age( $how_old ) { |
||
194 | |||
195 | /** |
||
196 | * Set arguments for only getting the Salesforce logs |
||
197 | * |
||
198 | * @param array $args Argument array for get_posts determining what posts are eligible for pruning. |
||
199 | * @return array $args |
||
200 | */ |
||
201 | public function set_prune_args( $args ) { |
||
205 | |||
206 | /** |
||
207 | * Setup new log entry |
||
208 | * |
||
209 | * Check and see if we should log anything, and if so, send it to add() |
||
210 | * |
||
211 | * @access public |
||
212 | * @since 1.0 |
||
213 | * |
||
214 | * @param string|array $title_or_params A log post title, or the full array of parameters |
||
215 | * @param string $message The log message. |
||
216 | * @param string|0 $trigger The type of log triggered. Usually one of: debug, notice, warning, error. |
||
217 | * @param int $parent The parent WordPress object. |
||
218 | * @param string $status The log status. |
||
219 | * |
||
220 | * @uses self::add() |
||
221 | * @see Object_Sync_Sf_Mapping::__construct() the location of the bitmasks that define the logging triggers. |
||
222 | * |
||
223 | * @return void |
||
224 | */ |
||
225 | public function setup( $title_or_params, $message = '', $trigger = 0, $parent = 0, $status = '' ) { |
||
247 | |||
248 | /** |
||
249 | * Create new log entry |
||
250 | * |
||
251 | * This is just a simple and fast way to log something. Use self::insert_log() |
||
252 | * if you need to store custom meta data |
||
253 | * |
||
254 | * @access public |
||
255 | * @since 1.0 |
||
256 | * |
||
257 | * @param string $title A log post title. |
||
258 | * |
||
259 | * @uses self::insert_log() |
||
260 | * @param string $message The log message. |
||
261 | * @param int $parent The parent WordPress object. |
||
262 | * @param string $type The type of log message; defaults to 'salesforce'. |
||
263 | * |
||
264 | * @return int The ID of the new log entry |
||
265 | */ |
||
266 | public static function add( $title = '', $message = '', $parent = 0, $type = 'salesforce' ) { |
||
278 | |||
279 | |||
280 | /** |
||
281 | * Easily retrieves log items for a particular object ID |
||
282 | * |
||
283 | * @access private |
||
284 | * @since 1.0 |
||
285 | * |
||
286 | * @param int $object_id A WordPress object ID. |
||
287 | * @param string $type The type of log item; defaults to 'salesforce' because that's the type of logs we create. |
||
288 | * @param int $paged Which page of results do we want? |
||
289 | * |
||
290 | * @uses self::get_connected_logs() |
||
291 | * |
||
292 | * @return array |
||
293 | */ |
||
294 | public static function get_logs( $object_id = 0, $type = 'salesforce', $paged = null ) { |
||
303 | |||
304 | |||
305 | /** |
||
306 | * Retrieve all connected logs |
||
307 | * |
||
308 | * Used for retrieving logs related to particular items, such as a specific purchase. |
||
309 | * |
||
310 | * @access private |
||
311 | * @since 1.0 |
||
312 | * |
||
313 | * @param Array $args An array of arguments for get_posts(). |
||
314 | * |
||
315 | * @uses wp_parse_args() |
||
316 | * @uses get_posts() |
||
317 | * @uses get_query_var() |
||
318 | * @uses self::valid_type() |
||
319 | * |
||
320 | * @return array / false |
||
321 | */ |
||
322 | public static function get_connected_logs( $args = array() ) { |
||
357 | |||
358 | |||
359 | /** |
||
360 | * Retrieves number of log entries connected to particular object ID |
||
361 | * |
||
362 | * @access private |
||
363 | * @since 1.0 |
||
364 | * |
||
365 | * @param int $object_id A WordPress object ID. |
||
366 | * @param string $type The type of log item; defaults to 'salesforce' because that's the type of logs we create. |
||
367 | * @param Array $meta_query A WordPress meta query, parseable by WP_Meta_Query. |
||
368 | * |
||
369 | * @uses WP_Query() |
||
370 | * @uses self::valid_type() |
||
371 | * |
||
372 | * @return int |
||
373 | */ |
||
374 | public static function get_log_count( $object_id = 0, $type = 'salesforce', $meta_query = null ) { |
||
404 | |||
405 | } |
||
406 |