Completed
Push — master ( 5f46f6...9c1aa8 )
by Mike
09:11 queued 21s
created

WC_Background_Updater::task()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
eloc 12
nc 4
nop 1
dl 0
loc 19
rs 9.4285
c 2
b 0
f 1
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 24 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * background updater.
4
 *
5
 * Uses https://github.com/A5hleyRich/wp-background-processing to handle DB
6
 * updates in the background.
7
 *
8
 * @author   WooThemes
9
 * @category Admin
10
 * @package  WooCommerce/Classes
11
 * @version  2.6.0
12
 */
13
14
if ( ! defined( 'ABSPATH' ) ) {
15
	exit;
16
}
17
18
include_once( 'libraries/wp-async-request.php' );
19
include_once( 'libraries/wp-background-process.php' );
20
21
/**
22
 * WC_Background_Updater Class.
23
 */
24
class WC_Background_Updater extends WP_Background_Process {
25
26
	/**
27
	 * @var string
28
	 */
29
	protected $action = 'wc_updater';
30
31
	/**
32
	 * Dispatch
33
	 */
34
	public function dispatch() {
35
		WC_Admin_Notices::add_notice( 'updating' );
36
		parent::dispatch();
37
	}
38
39
	/**
40
	 * Task
41
	 *
42
	 * Override this method to perform any actions required on each
43
	 * queue item. Return the modified item for further processing
44
	 * in the next pass through. Or, return false to remove the
45
	 * item from the queue.
46
	 *
47
	 * @param string $callback Update callback function
48
	 * @return mixed
49
	 */
50
	protected function task( $callback ) {
51
		if ( ! defined( 'WC_UPDATING' ) ) {
52
			define( 'WC_UPDATING', true );
53
		}
54
55
		$logger = new WC_Logger();
56
57
		include_once( 'wc-update-functions.php' );
58
59
		if ( is_callable( $callback ) ) {
60
			$logger->add( 'wc_db_updates', sprintf( 'Running %s callback', $callback ) );
61
			call_user_func( $callback );
62
			$logger->add( 'wc_db_updates', sprintf( 'Finished %s callback', $callback ) );
63
		} else {
64
			$logger->add( 'wc_db_updates', sprintf( 'Could not find %s callback', $callback ) );
65
		}
66
67
		return false;
68
	}
69
70
	/**
71
	 * Complete
72
	 *
73
	 * Override if applicable, but ensure that the below actions are
74
	 * performed, or, call parent::complete().
75
	 */
76
	protected function complete() {
77
		$logger = new WC_Logger();
78
79
		$logger->add( 'wc_db_updates', 'Data update complete' );
80
		WC_Install::update_db_version();
81
		parent::complete();
82
	}
83
}
84