| Server IP : 172.67.133.75 / Your IP : 162.159.115.10 Web Server : nginx/1.26.1 System : Linux HE9229 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/jl3_ph_com/wp-content/plugins/elementor/app/modules/import-export/processes/ |
Upload File : |
<?php
namespace Elementor\App\Modules\ImportExport\Processes;
use Elementor\App\Modules\ImportExport\Module;
use Elementor\App\Modules\ImportExport\Runners\Revert\Elementor_Content;
use Elementor\App\Modules\ImportExport\Runners\Revert\Revert_Runner_Base;
use Elementor\App\Modules\ImportExport\Runners\Revert\Plugins;
use Elementor\App\Modules\ImportExport\Runners\Revert\Site_Settings;
use Elementor\App\Modules\ImportExport\Runners\Revert\Taxonomies;
use Elementor\App\Modules\ImportExport\Runners\Revert\Templates;
use Elementor\App\Modules\ImportExport\Runners\Revert\Wp_Content;
use Elementor\App\Modules\ImportExport\Utils;
class Revert {
/**
* @var Revert_Runner_Base[]
*/
protected $runners = [];
private $import_sessions;
private $revert_sessions;
public function __construct() {
$this->import_sessions = self::get_import_sessions();
$this->revert_sessions = self::get_revert_sessions();
}
/**
* Register a runner.
*
* @param Revert_Runner_Base $runner_instance
*/
public function register( Revert_Runner_Base $runner_instance ) {
$this->runners[ $runner_instance::get_name() ] = $runner_instance;
}
public function register_default_runners() {
$this->register( new Site_Settings() );
$this->register( new Plugins() );
$this->register( new Templates() );
$this->register( new Taxonomies() );
$this->register( new Elementor_Content() );
$this->register( new Wp_Content() );
}
/**
* Execute the revert process.
*
* @throws \Exception If no revert runners have been specified.
*/
public function run() {
if ( empty( $this->runners ) ) {
throw new \Exception( 'Couldn’t execute the revert process because no revert runners have been specified. Try again by specifying revert runners.' );
}
$import_session = $this->get_last_import_session();
if ( empty( $import_session ) ) {
throw new \Exception( 'Couldn’t execute the revert process because there are no import sessions to revert.' );
}
// fallback if the import session failed and doesn't have the runners metadata
if ( ! isset( $import_session['runners'] ) && isset( $import_session['instance_data'] ) ) {
$import_session['runners'] = $import_session['instance_data']['runners_import_metadata'] ?? [];
}
foreach ( $this->runners as $runner ) {
if ( $runner->should_revert( $import_session ) ) {
$runner->revert( $import_session );
}
}
$this->revert_attachments( $import_session );
$this->delete_last_import_data();
}
public static function get_import_sessions() {
$import_sessions = Utils::get_import_sessions();
if ( ! $import_sessions ) {
return [];
}
usort( $import_sessions, function( $a, $b ) {
return strcmp( $a['start_timestamp'], $b['start_timestamp'] );
} );
return $import_sessions;
}
public static function get_revert_sessions() {
$revert_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_REVERT_SESSIONS );
if ( ! $revert_sessions ) {
return [];
}
return $revert_sessions;
}
public function get_last_import_session() {
$import_sessions = $this->import_sessions;
if ( empty( $import_sessions ) ) {
return [];
}
return end( $import_sessions );
}
public function get_penultimate_import_session() {
$sessions_data = $this->import_sessions;
$penultimate_element_value = [];
if ( empty( $sessions_data ) ) {
return [];
}
end( $sessions_data );
prev( $sessions_data );
if ( ! is_null( key( $sessions_data ) ) ) {
$penultimate_element_value = current( $sessions_data );
}
return $penultimate_element_value;
}
private function delete_last_import_data() {
$import_sessions = $this->import_sessions;
$revert_sessions = $this->revert_sessions;
$reverted_session = array_pop( $import_sessions );
$revert_sessions[] = [
'session_id' => $reverted_session['session_id'],
'kit_title' => $reverted_session['kit_title'],
'kit_name' => $reverted_session['kit_name'],
'kit_thumbnail' => $reverted_session['kit_thumbnail'],
'source' => $reverted_session['kit_source'],
'user_id' => get_current_user_id(),
'import_timestamp' => $reverted_session['start_timestamp'],
'revert_timestamp' => current_time( 'timestamp' ),
];
update_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS, $import_sessions, false );
update_option( Module::OPTION_KEY_ELEMENTOR_REVERT_SESSIONS, $revert_sessions, false );
$this->import_sessions = $import_sessions;
$this->revert_sessions = $revert_sessions;
}
private function revert_attachments( $data ) {
$query_args = [
'post_type' => 'attachment',
'post_status' => 'any',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => Module::META_KEY_ELEMENTOR_IMPORT_SESSION_ID,
'value' => $data['session_id'],
],
],
];
$query = new \WP_Query( $query_args );
foreach ( $query->posts as $post ) {
wp_delete_attachment( $post->ID, true );
}
}
}