|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The main plugin class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package LSX_WETU_Importer |
|
6
|
|
|
* @author LightSpeed |
|
7
|
|
|
* @license GPL-2.0+ |
|
8
|
|
|
* @link |
|
9
|
|
|
* @copyright 2016 LightSpeed |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace lsx\wetu_importer\classes; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The Main plugin class. |
|
16
|
|
|
*/ |
|
17
|
|
|
class Cron { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Holds class instance |
|
21
|
|
|
* |
|
22
|
|
|
* @since 1.0.0 |
|
23
|
|
|
* |
|
24
|
|
|
* @var object|Module_Template |
|
|
|
|
|
|
25
|
|
|
*/ |
|
26
|
|
|
protected static $instance = null; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Initialize the plugin by setting localization, filters, and administration functions. |
|
30
|
|
|
* |
|
31
|
|
|
* @since 1.0.0 |
|
32
|
|
|
* |
|
33
|
|
|
* @access private |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct() { |
|
|
|
|
|
|
36
|
|
|
add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 ); |
|
37
|
|
|
add_action( 'lsx_wetu_accommodation_images_cron', array( $this, 'process' ), 10, 1 ); |
|
38
|
|
|
} |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Return an instance of this class. |
|
42
|
|
|
* |
|
43
|
|
|
* @since 1.0.0 |
|
44
|
|
|
* |
|
45
|
|
|
* @return object Cron() A single instance of this class. |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function get_instance() { |
|
48
|
|
|
// If the single instance hasn't been set, set it now. |
|
49
|
|
|
if ( null === self::$instance ) { |
|
|
|
|
|
|
50
|
|
|
self::$instance = new self(); |
|
51
|
|
|
} |
|
|
|
|
|
|
52
|
|
|
return self::$instance; |
|
53
|
|
|
} |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Watches for changes in the button triggers. |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function watch_for_trigger() { |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) { |
|
|
|
|
|
|
63
|
|
|
$options = lsx_wetu_get_options(); |
|
64
|
|
|
|
|
65
|
|
|
// Check what state the option is in. |
|
66
|
|
|
$accommodation_cron = 'deactivate'; |
|
67
|
|
|
if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) { |
|
|
|
|
|
|
68
|
|
|
$accommodation_cron = 'activate'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Check what state the cron is in. |
|
72
|
|
|
$schedule = false; |
|
73
|
|
|
if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) { |
|
|
|
|
|
|
74
|
|
|
$schedule = true; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// If activate and its not running. |
|
78
|
|
|
if ( false === $schedule && 'activate' === $accommodation_cron ) { |
|
|
|
|
|
|
79
|
|
|
$schedule = 'daily'; |
|
80
|
|
|
$this->schedule( 'lsx_wetu_accommodation_images_cron', $schedule ); |
|
81
|
|
|
} elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) { |
|
|
|
|
|
|
82
|
|
|
$this->deactivate(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
|
|
|
|
|
88
|
|
|
* Remove our cron from the shedule. |
|
89
|
|
|
* |
|
90
|
|
|
* @return void |
|
91
|
|
|
*/ |
|
92
|
|
|
public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) { |
|
93
|
|
|
wp_clear_scheduled_hook( $task ); |
|
94
|
|
|
} |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* This function will schedule the cron event. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $task |
|
|
|
|
|
|
100
|
|
|
* @param string $schedule |
|
|
|
|
|
|
101
|
|
|
* @param string $time |
|
|
|
|
|
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
|
|
public function schedule( $task = 'lsx_wetu_accommodation_images_cron', $schedule = 'daily', $time = '' ) { |
|
105
|
|
|
if ( '' === $time ) { |
|
|
|
|
|
|
106
|
|
|
$time = time(); |
|
107
|
|
|
} |
|
|
|
|
|
|
108
|
|
|
wp_schedule_event( $time, $schedule, $task, array( $task ) ); |
|
|
|
|
|
|
109
|
|
|
} |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
/** |
|
|
|
|
|
|
112
|
|
|
* This is the function that will be triggered by the cron event. |
|
113
|
|
|
* |
|
114
|
|
|
* @return void |
|
115
|
|
|
*/ |
|
116
|
|
|
public function process( $task = '' ) { |
|
117
|
|
|
switch ( $task ) { |
|
|
|
|
|
|
118
|
|
|
case 'lsx_wetu_accommodation_images_cron': |
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
break; |
|
121
|
|
|
|
|
122
|
|
|
default: |
|
123
|
|
|
break; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* This is the function that will be triggered by the cron event. |
|
129
|
|
|
* |
|
130
|
|
|
* @return void |
|
131
|
|
|
*/ |
|
132
|
|
|
public function sync_accommodation_images() { |
|
133
|
|
|
switch ( $task ) { |
|
|
|
|
|
|
134
|
|
|
case 'lsx_wetu_accommodation_images_cron': |
|
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
break; |
|
137
|
|
|
|
|
138
|
|
|
default: |
|
139
|
|
|
break; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
Cron::get_instance(); |
|
144
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths