PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.2
YayMail – WooCommerce Email Customizer v4.3.2
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
← All changes | src/Models/MigrationModel.php +5 -46 trunk4.3.2 View file →
@@ -21,36 +21,8 @@
21 21 private function __construct() {
22 22 $this->logger = new Logger();
23 23 }
24 24
25 - /**
26 - * Safely unserialize values coming from backup/import data.
27 - *
28 - * @param mixed $value The value to unserialize.
29 - * @return mixed
30 - */
31 - private function safe_maybe_unserialize( $value ) {
32 - if ( ! is_string( $value ) ) {
33 - return $value;
34 - }
35 -
36 - if ( ! function_exists( 'is_serialized' ) || ! is_serialized( $value ) ) {
37 - return $value;
38 - }
39 -
40 - $unserialized = @unserialize( $value, [ 'allowed_classes' => false ] );
41 -
42 - if ( false === $unserialized && 'b:0;' !== $value ) {
43 - return $value;
44 - }
45 -
46 - if ( is_object( $unserialized ) ) {
47 - return $value;
48 - }
49 -
50 - return $unserialized;
51 - }
52 -
53 25 public function get_onload_data() {
54 26 return [
55 27 'required_migrations' => $this->get_required_migration_names(),
56 28 'backups' => $this->get_backups(),
@@ -123,11 +95,8 @@
123 95 // Restore the backed-up posts
124 96 $backed_up_posts = $backup['posts'];
125 97 $backed_up_postmeta = $backup['postmeta'];
126 98 foreach ( $backed_up_posts as $post ) {
127 - if ( ! isset( $post->post_type ) || 'yaymail_template' !== $post->post_type ) {
128 - continue;
129 - }
130 99 $wpdb->insert(
131 100 $wpdb->posts,
132 101 [
133 102 'post_author' => $post->post_author,
@@ -164,16 +133,9 @@
164 133 }
165 134 );
166 135 if ( ! empty( $postmetas_for_current_post ) ) {
167 136 foreach ( $postmetas_for_current_post as $postmeta ) {
168 - if ( ! isset( $postmeta->meta_key ) || strpos( (string) $postmeta->meta_key, 'yaymail' ) === false ) {
169 - continue;
170 - }
171 - add_post_meta(
172 - $inserted_post_id,
173 - $postmeta->meta_key,
174 - $this->safe_maybe_unserialize( $postmeta->meta_value )
175 - );
137 + add_post_meta( $inserted_post_id, $postmeta->meta_key, maybe_unserialize( $postmeta->meta_value ) );
176 138 }
177 139 }
178 140 }//end foreach
179 141
@@ -178,12 +140,9 @@
178 140 }//end foreach
179 141
180 142 // Restore backed-up options
181 143 foreach ( $backup['options'] as $option ) {
182 - // Only restore options that belong to YayMail (same pattern as export)
183 - if ( strpos( $option->option_name, 'yaymail' ) !== false ) {
184 - update_option( $option->option_name, $this->safe_maybe_unserialize( $option->option_value ) );
185 - }
144 + update_option( $option->option_name, maybe_unserialize( $option->option_value ) );
186 145 }
187 146
188 147 // Remove the succeeded migration log from db
189 148 $successful_migrations = get_option( AbstractMigration::SUCCESSFUL_MIGRATIONS, null );
@@ -254,9 +213,9 @@
254 213 }
255 214
256 215 private function get_required_migration_names() {
257 216 $old_version = MigrationHelper::format_version_number( get_option( 'yaymail_version' ) );
258 - $new_version = MigrationHelper::format_version_number( yaymail_version() );
217 + $new_version = MigrationHelper::format_version_number( YAYMAIL_VERSION );
259 218 $successful_migrations = get_option( AbstractMigration::SUCCESSFUL_MIGRATIONS, [] );
260 219
261 220 // If freshly installed or already on latest version with no migrations needed
262 221 if ( ( version_compare( $old_version, $new_version, '>=' ) && empty( $successful_migrations ) ) ) {
@@ -277,9 +236,9 @@
277 236 }
278 237
279 238 // Check if any migrations have already been run up to current version
280 239 foreach ( $successful_migrations as $migration ) {
281 - if ( empty( $migration['addon_namespace'] ) && version_compare( $migration['to_version'], yaymail_version(), '>=' ) ) {
240 + if ( empty( $migration['addon_namespace'] ) && version_compare( $migration['to_version'], YAYMAIL_VERSION, '>=' ) ) {
282 241 return apply_filters( 'yaymail_required_migration_names', [] );
283 242 }
284 243 }
285 244
@@ -304,9 +263,9 @@
304 263 $backups_result = $wpdb->get_results( $backup_options_query );// phpcs:ignore
305 264
306 265 $backups = [];
307 266 foreach ( $backups_result as $backup ) {
308 - $data = $this->safe_maybe_unserialize( $backup->option_value );
267 + $data = maybe_unserialize( $backup->option_value );
309 268 $backups[] = [
310 269 'created_date' => $data['created_date'] ?? 'created_date not found',
311 270 'name' => $backup->option_name ?? 'backup name not found',
312 271 ];