Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Cloud_CSS_Followup | |
0.00% |
0 / 8 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| init | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| run | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| schedule | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| unschedule | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Modules\Optimizations\Cloud_CSS; |
| 4 | |
| 5 | use Automattic\Jetpack_Boost\Lib\Critical_CSS\Critical_CSS_State; |
| 6 | |
| 7 | class Cloud_CSS_Followup { |
| 8 | |
| 9 | const SCHEDULER_HOOK = 'jetpack_boost_cloud_css_followup'; |
| 10 | |
| 11 | /** |
| 12 | * Initiate the scheduler |
| 13 | * |
| 14 | * Whenever Cloud CSS module is setup, it will call this method. |
| 15 | * |
| 16 | * @return void |
| 17 | */ |
| 18 | public static function init() { |
| 19 | /* |
| 20 | * Run the scheduled job |
| 21 | */ |
| 22 | add_action( self::SCHEDULER_HOOK, array( self::class, 'run' ) ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Run the cron job. |
| 27 | */ |
| 28 | public static function run() { |
| 29 | $state = new Critical_CSS_State(); |
| 30 | if ( $state->has_errors() ) { |
| 31 | $cloud_css = new Cloud_CSS(); |
| 32 | $cloud_css->regenerate_cloud_css( Cloud_CSS::REGENERATE_REASON_FOLLOWUP, $cloud_css->get_existing_sources() ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Add a cron-job to maintain cloud CSS |
| 38 | * |
| 39 | * @return void |
| 40 | */ |
| 41 | public static function schedule() { |
| 42 | // Remove any existing schedule |
| 43 | self::unschedule(); |
| 44 | wp_schedule_single_event( time() + HOUR_IN_SECONDS, self::SCHEDULER_HOOK ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Remove the cron-job |
| 49 | */ |
| 50 | public static function unschedule() { |
| 51 | wp_clear_scheduled_hook( self::SCHEDULER_HOOK ); |
| 52 | } |
| 53 | } |