Ticket #4421: import-memory-reduction-r6606.patch

File import-memory-reduction-r6606.patch, 2.1 kB (added by tellyworth, 1 year ago)
  • wp-admin/import/wordpress.php

    old new  
    6969 
    7070        function get_entries() { 
    7171                set_magic_quotes_runtime(0); 
    72                 $importdata = array_map('rtrim', file($this->file)); // Read the file into an array 
    7372 
    7473                $this->posts = array(); 
    7574                $this->categories = array(); 
    7675                $num = 0; 
    7776                $doing_entry = false; 
    78                 foreach ($importdata as $importline) { 
    79                         if ( false !== strpos($importline, '<wp:category>') ) { 
    80                                 preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category); 
    81                                 $this->categories[] = $category[1]; 
    82                                 continue; 
     77 
     78                $fp = fopen($this->file, 'r'); 
     79                if ($fp) { 
     80                        while ( !feof($fp) ) { 
     81                                $importline = rtrim(fgets($fp)); 
     82 
     83                                if ( false !== strpos($importline, '<wp:category>') ) { 
     84                                        preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category); 
     85                                        $this->categories[] = $category[1]; 
     86                                        continue; 
     87                                } 
     88                                if ( false !== strpos($importline, '<item>') ) { 
     89                                        $this->posts[$num] = ''; 
     90                                        $doing_entry = true; 
     91                                        continue;        
     92                                } 
     93                                if ( false !== strpos($importline, '</item>') ) { 
     94                                        $num++; 
     95                                        $doing_entry = false; 
     96                                        continue;        
     97                                } 
     98                                if ( $doing_entry ) { 
     99                                        $this->posts[$num] .= $importline . "\n"; 
     100                                } 
    83101                        } 
    84                         if ( false !== strpos($importline, '<item>') ) { 
    85                                 $this->posts[$num] = ''; 
    86                                 $doing_entry = true; 
    87                                 continue;        
     102 
     103                        foreach ($this->posts as $post) { 
     104                                $post_ID = (int) $this->get_tag( $post, 'wp:post_id' ); 
     105                                if ($post_ID) { 
     106                                        $this->posts_processed[$post_ID][0] = &$post; 
     107                                        $this->posts_processed[$post_ID][1] = 0; 
     108                                } 
    88109                        } 
    89                         if ( false !== strpos($importline, '</item>') ) { 
    90                                 $num++; 
    91                                 $doing_entry = false; 
    92                                 continue;        
    93                         } 
    94                         if ( $doing_entry ) { 
    95                                 $this->posts[$num] .= $importline . "\n"; 
    96                         } 
    97                 } 
    98110 
    99                 foreach ($this->posts as $post) { 
    100                         $post_ID = (int) $this->get_tag( $post, 'wp:post_id' ); 
    101                         if ($post_ID) { 
    102                                 $this->posts_processed[$post_ID][0] = &$post; 
    103                                 $this->posts_processed[$post_ID][1] = 0; 
    104                         } 
     111                        fclose($fp); 
    105112                } 
    106113        } 
    107114