| Server IP : 89.39.208.18 / Your IP : 216.73.217.74 Web Server : LiteSpeed System : User : ( ) PHP Version : 7.4.33 Disable Function : eval,./,ln,passthru,dl,system,exec,popen,shell_exec,posix_getpwuid,posix_uname,ftp_exec,posix_uname,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,get_current_user,getmyuid,getmygid,listen,chgrp,apache_note,apache_setenv,apache_child_terminate,closelog,debugger_off,debugge_on,ini_restore,netscript,escapeshellarg,cmd,backtick,virtual,show_sourc,show_source,pclose,pcntl_exec,datasec,old_offset,ctrl_dir,ini_alter,leak,listen,chgrp,apache_setenv,define_syslog_variables,root,diskfreespace,disk_free_space,disk_total_space,posix_kill,getmyuid,getmygid,apache_child_terminate,php_ini_scanned_files,ls,ps_aux,chown,getrusage,posixc,posame,chgrp,posix_setuid,posix_setsid,posix_setgid,apache_note,apache_setenv,x_getuid,e_ini_file,nfo,SQL,mysql_li,t_dbs,filegroup,highlight_file,ilegetcontents,get_dir,popen,popens,pfsockopen,dos_conv,apache_get_modules,crack_check,crack_closedict,rar_open,bzopen,bzread,bzwrite,shellcode,posix_isatty,posix_getservbyname,escapeshellarg,hypot,pg_host,pos,posix_access,inurl,posix_times,posix_mknod,pclose,ps_fill,symlink,id,escapeshellcmd,php_uname,phpinfo MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home3/mahyarcake/www/wp-content/plugins/wp-rocket/inc/Engine/HealthCheck/ |
Upload File : |
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\HealthCheck;
use ActionScheduler_Versions;
use ActionScheduler;
use ActionScheduler_StoreSchema;
use ActionScheduler_LoggerSchema;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\Engine\Activation\ActivationInterface;
class ActionSchedulerCheck implements Subscriber_Interface, ActivationInterface {
/**
* Array of events this subscriber listens to.
*
* @return array
*/
public static function get_subscribed_events(): array {
$slug = rocket_get_constant( 'WP_ROCKET_SLUG', 'wp_rocket_settings' );
return [
'update_option_' . $slug => [ 'check_on_update_options', 10, 2 ],
'wp_rocket_update' => 'maybe_recreate_as_tables',
];
}
/**
* Actions to perform on plugin activation
*
* @return void
*/
public function activate() {
add_action( 'rocket_activation', [ $this, 'maybe_recreate_as_tables' ] );
}
/**
* Maybe recreate Action Scheduler tables if they are missing
*
* @return bool
*/
public function maybe_recreate_as_tables(): bool {
if ( ! $this->is_valid_action_scheduler_version() ) {
return false;
}
if ( $this->is_valid_as_tables() ) {
return false;
}
$store_schema = new ActionScheduler_StoreSchema();
$logger_schema = new ActionScheduler_LoggerSchema();
$store_schema->register_tables( true );
$logger_schema->register_tables( true );
return true;
}
/**
* Maybe recreate tables on preload or RUCSS activation
*
* @param mixed $old_value The old option value.
* @param mixed $value The new option value.
*
* @return bool
*/
public function check_on_update_options( $old_value, $value ): bool {
if ( ! isset( $old_value['remove_unused_css'], $value['remove_unused_css'], $old_value['manual_preload'], $value['manual_preload'] ) ) {
return false;
}
if (
$old_value['remove_unused_css'] === $value['remove_unused_css']
&&
$old_value['manual_preload'] === $value['manual_preload']
) {
return false;
}
if (
0 === (int) $value['remove_unused_css']
&&
0 === (int) $value['manual_preload']
) {
return false;
}
if (
(
$old_value['remove_unused_css'] !== $value['remove_unused_css']
&&
1 !== (int) $value['remove_unused_css']
)
||
(
$old_value['manual_preload'] !== $value['manual_preload']
&&
1 !== (int) $value['manual_preload']
)
) {
return false;
}
return $this->maybe_recreate_as_tables();
}
/**
* Check if Action Scheduler tables exists
*
* @return bool
*/
private function is_valid_as_tables(): bool {
$cached_count = get_transient( 'rocket_rucss_as_tables_count' );
if (
false !== $cached_count
&&
! is_admin()
) { // Stop caching in admin UI.
return 4 === (int) $cached_count;
}
global $wpdb;
$exp = "'^" . $wpdb->prefix . "actionscheduler_(logs|actions|groups|claims)$'";
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$found_as_tables = $wpdb->get_col(
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$wpdb->prepare( 'SHOW TABLES FROM `' . DB_NAME . '` WHERE `Tables_in_' . DB_NAME . '` LIKE %s AND `Tables_in_' . DB_NAME . '` REGEXP ' . $exp, '%actionscheduler%' )
);
set_transient( 'rocket_rucss_as_tables_count', count( $found_as_tables ), rocket_get_constant( 'DAY_IN_SECONDS', 24 * 60 * 60 ) );
return 4 === count( $found_as_tables );
}
/**
* Validate if the currenlt loaded action scheduler's version is more than 3.0.0.
* Note: Latest_version method in ActionScheduler_Versions class will return false with first activation
* in case we don't have any other active plugin which loads Action Scheduler.
* Because with activation, our Action Scheduler still not initialized yet.
*
* @return bool
*/
private function is_valid_action_scheduler_version() {
if ( ! class_exists( 'ActionScheduler_Versions' ) || ! class_exists( 'ActionScheduler' ) ) {
return false;
}
$version = ActionScheduler_Versions::instance()->latest_version();
return ! $version || version_compare( $version, '3.0.0', '>=' );
}
}