← All changes
|
app/modules/import-export/processes/revert.php
+16
-28
4.2.3
→
3.10.0-dev1
View file →
| @@ -8,9 +8,8 @@ | ||
| 8 | 8 | use Elementor\App\Modules\ImportExport\Runners\Revert\Site_Settings; |
| 9 | 9 | use Elementor\App\Modules\ImportExport\Runners\Revert\Taxonomies; |
| 10 | 10 | use Elementor\App\Modules\ImportExport\Runners\Revert\Templates; |
| 11 | 11 | use Elementor\App\Modules\ImportExport\Runners\Revert\Wp_Content; |
| 12 | -use Elementor\App\Modules\ImportExport\Utils; | |
| 13 | 12 | |
| 14 | 13 | class Revert { |
| 15 | 14 | |
| 16 | 15 | /** |
| @@ -21,11 +20,14 @@ | ||
| 21 | 20 | private $import_sessions; |
| 22 | 21 | |
| 23 | 22 | private $revert_sessions; |
| 24 | 23 | |
| 24 | + /** | |
| 25 | + * @throws \Exception | |
| 26 | + */ | |
| 25 | 27 | public function __construct() { |
| 26 | - $this->import_sessions = self::get_import_sessions(); | |
| 27 | - $this->revert_sessions = self::get_revert_sessions(); | |
| 28 | + $this->import_sessions = $this->get_import_sessions(); | |
| 29 | + $this->revert_sessions = $this->get_revert_sessions(); | |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | 32 | /** |
| 31 | 33 | * Register a runner. |
| @@ -44,55 +46,43 @@ | ||
| 44 | 46 | $this->register( new Elementor_Content() ); |
| 45 | 47 | $this->register( new Wp_Content() ); |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - /** | |
| 49 | - * Execute the revert process. | |
| 50 | - * | |
| 51 | - * @throws \Exception If no revert runners have been specified. | |
| 52 | - */ | |
| 53 | 50 | public function run() { |
| 54 | 51 | if ( empty( $this->runners ) ) { |
| 55 | - throw new \Exception( 'Couldn’t execute the revert process because no revert runners have been specified. Try again by specifying revert runners.' ); | |
| 52 | + throw new \Exception( 'Please specify revert runners.' ); | |
| 56 | 53 | } |
| 57 | 54 | |
| 58 | - $import_session = $this->get_last_import_session(); | |
| 55 | + $data = $this->get_last_import_session(); | |
| 59 | 56 | |
| 60 | - if ( empty( $import_session ) ) { | |
| 61 | - throw new \Exception( 'Couldn’t execute the revert process because there are no import sessions to revert.' ); | |
| 57 | + if ( empty( $data ) ) { | |
| 58 | + throw new \Exception( 'Could not find any import sessions to revert.' ); | |
| 62 | 59 | } |
| 63 | 60 | |
| 64 | - // fallback if the import session failed and doesn't have the runners metadata | |
| 65 | - if ( ! isset( $import_session['runners'] ) && isset( $import_session['instance_data'] ) ) { | |
| 66 | - $import_session['runners'] = $import_session['instance_data']['runners_import_metadata'] ?? []; | |
| 67 | - } | |
| 68 | - | |
| 69 | 61 | foreach ( $this->runners as $runner ) { |
| 70 | - if ( $runner->should_revert( $import_session ) ) { | |
| 71 | - $runner->revert( $import_session ); | |
| 62 | + if ( $runner->should_revert( $data ) ) { | |
| 63 | + $runner->revert( $data ); | |
| 72 | 64 | } |
| 73 | 65 | } |
| 74 | 66 | |
| 75 | - $this->revert_attachments( $import_session ); | |
| 67 | + $this->revert_attachments( $data ); | |
| 76 | 68 | |
| 77 | 69 | $this->delete_last_import_data(); |
| 78 | 70 | } |
| 79 | 71 | |
| 80 | - public static function get_import_sessions() { | |
| 81 | - $import_sessions = Utils::get_import_sessions(); | |
| 72 | + public function get_import_sessions() { | |
| 73 | + $import_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS ); | |
| 82 | 74 | |
| 83 | 75 | if ( ! $import_sessions ) { |
| 84 | 76 | return []; |
| 85 | 77 | } |
| 86 | 78 | |
| 87 | - usort( $import_sessions, function( $a, $b ) { | |
| 88 | - return strcmp( $a['start_timestamp'], $b['start_timestamp'] ); | |
| 89 | - } ); | |
| 79 | + ksort( $import_sessions, SORT_NUMERIC ); | |
| 90 | 80 | |
| 91 | 81 | return $import_sessions; |
| 92 | 82 | } |
| 93 | 83 | |
| 94 | - public static function get_revert_sessions() { | |
| 84 | + public function get_revert_sessions() { | |
| 95 | 85 | $revert_sessions = get_option( Module::OPTION_KEY_ELEMENTOR_REVERT_SESSIONS ); |
| 96 | 86 | |
| 97 | 87 | if ( ! $revert_sessions ) { |
| 98 | 88 | return []; |
| @@ -137,11 +127,9 @@ | ||
| 137 | 127 | $reverted_session = array_pop( $import_sessions ); |
| 138 | 128 | |
| 139 | 129 | $revert_sessions[] = [ |
| 140 | 130 | 'session_id' => $reverted_session['session_id'], |
| 141 | - 'kit_title' => $reverted_session['kit_title'], | |
| 142 | 131 | 'kit_name' => $reverted_session['kit_name'], |
| 143 | - 'kit_thumbnail' => $reverted_session['kit_thumbnail'], | |
| 144 | 132 | 'source' => $reverted_session['kit_source'], |
| 145 | 133 | 'user_id' => get_current_user_id(), |
| 146 | 134 | 'import_timestamp' => $reverted_session['start_timestamp'], |
| 147 | 135 | 'revert_timestamp' => current_time( 'timestamp' ), |