| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace YayMail\Models; |
| 3 | 3 | |
| 4 | 4 | use YayMail\Migrations\AbstractMigration; |
| 5 | +use YayMail\Utils\SafeUnserializer; | |
| 5 | 6 | use YayMail\Utils\SingletonTrait; |
| 6 | 7 | use YayMail\Utils\Logger; |
| 7 | 8 | use YayMail\Migrations\MainMigration; |
| 8 | 9 | use YayMail\Migrations\MigrationHelper; |
| @@ -22,33 +23,17 @@ | ||
| 22 | 23 | $this->logger = new Logger(); |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | /** |
| 26 | - * Safely unserialize values coming from backup/import data. | |
| 27 | + * Decode internal backup options for the listing UI (read-only). | |
| 27 | 28 | * |
| 28 | 29 | * @param mixed $value The value to unserialize. |
| 29 | 30 | * @return mixed |
| 30 | 31 | */ |
| 31 | 32 | private function safe_maybe_unserialize( $value ) { |
| 32 | - if ( ! is_string( $value ) ) { | |
| 33 | - return $value; | |
| 34 | - } | |
| 33 | + $decoded = SafeUnserializer::decode( $value ); | |
| 35 | 34 | |
| 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; | |
| 35 | + return is_object( $decoded ) ? $value : $decoded; | |
| 51 | 36 | } |
| 52 | 37 | |
| 53 | 38 | public function get_onload_data() { |
| 54 | 39 | return [ |
| @@ -170,9 +155,9 @@ | ||
| 170 | 155 | } |
| 171 | 156 | add_post_meta( |
| 172 | 157 | $inserted_post_id, |
| 173 | 158 | $postmeta->meta_key, |
| 174 | - $this->safe_maybe_unserialize( $postmeta->meta_value ) | |
| 159 | + SafeUnserializer::decode_strict( $postmeta->meta_value ) | |
| 175 | 160 | ); |
| 176 | 161 | } |
| 177 | 162 | } |
| 178 | 163 | }//end foreach |
| @@ -180,9 +165,9 @@ | ||
| 180 | 165 | // Restore backed-up options |
| 181 | 166 | foreach ( $backup['options'] as $option ) { |
| 182 | 167 | // Only restore options that belong to YayMail (same pattern as export) |
| 183 | 168 | if ( strpos( $option->option_name, 'yaymail' ) !== false ) { |
| 184 | - update_option( $option->option_name, $this->safe_maybe_unserialize( $option->option_value ) ); | |
| 169 | + update_option( $option->option_name, SafeUnserializer::decode_strict( $option->option_value ) ); | |
| 185 | 170 | } |
| 186 | 171 | } |
| 187 | 172 | |
| 188 | 173 | // Remove the succeeded migration log from db |