Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Regenerate | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| is_cloud_css | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| start | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
| get_state | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Lib\Critical_CSS; |
| 4 | |
| 5 | use Automattic\Jetpack_Boost\Admin\Regenerate_Admin_Notice; |
| 6 | use Automattic\Jetpack_Boost\Lib\Critical_CSS\Source_Providers\Source_Providers; |
| 7 | use Automattic\Jetpack_Boost\Modules\Modules_Setup; |
| 8 | use Automattic\Jetpack_Boost\Modules\Optimizations\Cloud_CSS\Cloud_CSS; |
| 9 | use Automattic\Jetpack_Boost\Modules\Optimizations\Cloud_CSS\Cloud_CSS_Followup; |
| 10 | |
| 11 | class Regenerate { |
| 12 | /** @var Critical_CSS_State */ |
| 13 | private $state; |
| 14 | |
| 15 | public function is_cloud_css() { |
| 16 | $optimizations = ( new Modules_Setup() )->get_status(); |
| 17 | return isset( $optimizations[ Cloud_CSS::get_slug() ] ) && $optimizations[ Cloud_CSS::get_slug() ]; |
| 18 | } |
| 19 | |
| 20 | public function start() { |
| 21 | // Get Critical CSS Source URLs |
| 22 | $source_providers = new Source_Providers(); |
| 23 | $providers = $source_providers->get_provider_sources(); |
| 24 | |
| 25 | // Store those URLs in the Critical CSS State |
| 26 | $this->state = new Critical_CSS_State(); |
| 27 | $this->state->prepare_request() |
| 28 | ->set_pending_providers( $providers ) |
| 29 | ->save(); |
| 30 | |
| 31 | // Get the data |
| 32 | $data = $this->state->get(); |
| 33 | |
| 34 | if ( $this->is_cloud_css() ) { |
| 35 | // If this is a cloud CSS request, we need to trigger the generation |
| 36 | // of the CSS and return the URL to the CSS file. |
| 37 | $cloud_css = new Cloud_CSS(); |
| 38 | $cloud_css->regenerate_cloud_css( Cloud_CSS::REGENERATE_REASON_USER_REQUEST, $cloud_css->get_all_providers() ); |
| 39 | Cloud_CSS_Followup::schedule(); |
| 40 | } |
| 41 | |
| 42 | // Clear previous Critical CSS From storage |
| 43 | $storage = new Critical_CSS_Storage(); |
| 44 | $storage->clear(); |
| 45 | |
| 46 | // Dismiss admin notices |
| 47 | Regenerate_Admin_Notice::dismiss(); |
| 48 | jetpack_boost_ds_delete( 'critical_css_suggest_regenerate' ); |
| 49 | |
| 50 | return $data; |
| 51 | } |
| 52 | |
| 53 | public function get_state() { |
| 54 | return $this->state; |
| 55 | } |
| 56 | } |