[wp-trac] [WordPress Trac] #23275: WordPress Importer: line-ending mismatch corrupts serialized meta

WordPress Trac noreply at wordpress.org
Wed Jan 23 16:56:04 UTC 2013


#23275: WordPress Importer: line-ending mismatch corrupts serialized meta
-----------------------------+--------------------------
 Reporter:  WraithKenny      |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Import
  Version:                   |   Severity:  normal
 Keywords:                   |
-----------------------------+--------------------------
 A possible solution:
 {{{
 if ( $key ) {
         // export gets meta straight from the DB so could have a
 serialized string
         if ( ! $value )
                 $value = maybe_unserialize( $meta['value'] );
         // Occationally, line-endings break unserialize()
         if ( empty( $value ) ) // Try normalizing...
                 $value = maybe_unserialize( str_replace( array("\r\n",
 "\r", "\n"), "\r\n", $meta['value'] ) );
         if ( empty( $value ) ) // Adjust string length if needed
                 $value = maybe_unserialize(
                         preg_replace( // e flag deprecated in PHP 5.5.0 I
 think
                                 '!s:(\d+):"(.*?)";!se',
                                 "'s:'.strlen('$2').':\"$2\";'",
                                 $meta['value']
                         )
                 );

         add_post_meta( $post_id, $key, $value );
         do_action( 'import_post_meta', $post_id, $key, $value );

         // if the post has a featured image, take note of this in case of
 remap
         if ( '_thumbnail_id' == $key )
                 $this->featured_images[$post_id] = (int) $value;
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23275>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list