Commit inicial powerservice

This commit is contained in:
Gabriel
2026-10-19 12:45:45 -06:00
commit ad85486fe2
10158 changed files with 2736804 additions and 0 deletions
@@ -0,0 +1,135 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\Preload\Activation;
use WP_Rocket\Engine\Activation\ActivationInterface;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Preload\Controller\{PreloadUrl, Queue};
use WP_Rocket\Engine\Preload\Database\Queries\Cache;
class Activation implements ActivationInterface {
/**
* Preload controller
*
* @var PreloadUrl
*/
private $preload_url;
/**
* Preload queue.
*
* @var Queue
*/
protected $queue;
/**
* DB query.
*
* @var Cache
*/
protected $query;
/**
* Options.
*
* @var Options_Data
*/
protected $options;
/**
* Instantiate class.
*
* @param PreloadUrl $preload_url PreloadUrl instance.
* @param Queue $queue Preload queue.
* @param Cache $query DB query.
* @param Options_Data $options Options.
*/
public function __construct( PreloadUrl $preload_url, Queue $queue, Cache $query, Options_Data $options ) {
$this->preload_url = $preload_url;
$this->queue = $queue;
$this->query = $query;
$this->options = $options;
}
/**
* Launch preload on activation.
*/
public function activate() {
add_action( 'rocket_activation', [ $this, 'preload_activation' ], 15 );
add_action( 'rocket_after_activation', [ $this, 'preload_homepage' ] );
}
/**
* Run actions on activation.
*
* @return void
*/
public function preload_activation() {
if ( ! $this->options->get( 'manual_preload', true ) ) {
return;
}
/**
* Action that fires before the preload does.
*/
do_action( 'rocket_preload_activation' );
$this->queue->add_job_preload_job_load_initial_sitemap_async();
}
/**
* Preloads the homepage on activation
*
* @return void
*/
public function preload_homepage() {
$this->preload_url->preload_url( home_url() );
}
/**
* Disable cron and jobs on update.
*
* @param string $new_version new version from the plugin.
* @param string $old_version old version from the plugin.
* @return void
*/
public function clean_on_update( $new_version, $old_version ) {
if ( version_compare( $old_version, '3.12.0', '>=' ) ) {
return;
}
$this->query->remove_all();
$this->queue->cancel_pending_jobs();
if ( ! wp_next_scheduled( 'rocket_preload_process_pending' ) ) {
return;
}
wp_clear_scheduled_hook( 'rocket_preload_process_pending' );
}
/**
* Reload sitemap on update.
*
* @param string $new_version new version from the plugin.
* @param string $old_version old version from the plugin.
* @return void
*/
public function refresh_on_update( $new_version, $old_version ) {
if ( version_compare( $old_version, '3.12.0.2', '>' ) ) {
return;
}
$this->queue->add_job_preload_job_load_initial_sitemap_async();
}
/**
* Clear preload on deactivation.
*/
public function deactivation() {
wp_clear_scheduled_hook( 'rocket_preload_clean_rows_time_event' );
wp_clear_scheduled_hook( 'rocket_preload_process_pending' );
wp_clear_scheduled_hook( 'rocket_preload_revert_old_failed_rows' );
}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\Preload\Activation;
use WP_Filesystem_Direct;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Engine\Preload\Controller\{PreloadUrl, Queue};
use WP_Rocket\Engine\Preload\Database\Queries\Cache as CacheQuery;
use WP_Rocket\Engine\Preload\Database\Tables\Cache as CacheTable;
use WP_Rocket\Logger\Logger;
class ServiceProvider extends AbstractServiceProvider {
/**
* The provides array is a way to let the container
* know that a service is provided by this service
* provider. Every service that is registered via
* this service provider must have an alias added
* to this array or it will be ignored.
*
* @var array
*/
protected $provides = [
'preload_cache_table',
'preload_caches_query',
'preload_url_controller',
'preload_queue',
'preload_activation',
];
/**
* Registers the subscribers in the container
*
* @since 3.3
*
* @return void
*/
public function register() {
$options = $this->getContainer()->get( 'options' );
$this->getContainer()->add( 'preload_cache_table', CacheTable::class );
$this->getContainer()->get( 'preload_cache_table' );
$this->getContainer()->add( 'wp_direct_filesystem', WP_Filesystem_Direct::class )
->addArgument( [] );
$this->getContainer()->add( 'preload_cache_query', CacheQuery::class )
->addArgument( new Logger() );
$this->getContainer()->add( 'preload_queue', Queue::class );
$cache_query = $this->getContainer()->get( 'preload_cache_query' );
$queue = $this->getContainer()->get( 'preload_queue' );
$this->getContainer()->add( 'preload_url_controller', PreloadUrl::class )
->addArgument( $options )
->addArgument( $queue )
->addArgument( $cache_query )
->addArgument( $this->getContainer()->get( 'wp_direct_filesystem' ) );
$this->getContainer()->add( 'preload_activation', Activation::class )
->addArgument( $this->getContainer()->get( 'preload_url_controller' ) )
->addArgument( $queue )
->addArgument( $cache_query )
->addArgument( $options );
}
}