Dotclear


Ignore:
Timestamp:
10/23/13 15:49:16 (12 years ago)
Author:
Dsls
Branch:
2.6
Message:
  • Clear logs when importing full flat file
  • Unlink unzipped file before deleting it
  • Be more precise when raising an exception (errored line is now displayed)

Fixes #1808

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/importExport/inc/class.dc.import.flat.php

    r1559 r2485  
    1515{ 
    1616     protected $status = false; 
    17       
     17 
    1818     public function setInfo() 
    1919     { 
     
    2222          $this->description = __('Imports a blog or a full Dotclear installation from flat file.'); 
    2323     } 
    24       
     24 
    2525     public function process($do) 
    2626     { 
     
    2929               return; 
    3030          } 
    31            
     31 
    3232          $to_unlink = false; 
    33            
     33 
    3434          # Single blog import 
    3535          $files = $this->getPublicFiles(); 
     
    4040               $single_upl = true; 
    4141          } 
    42            
     42 
    4343          if ($single_upl !== null) 
    4444          { 
     
    5353                    $file = $_POST['public_single_file']; 
    5454               } 
    55                 
     55 
    5656               try { 
    5757                    # Try to unzip file 
     
    6464                         $bk = new flatImport($this->core,$file); 
    6565                    } 
    66                      
     66 
    6767                    $bk->importSingle(); 
    6868               } catch (Exception $e) { 
     
    7979               http::redirect($this->getURL().'&do=single'); 
    8080          } 
    81            
     81 
    8282          # Full import 
    8383          $full_upl = null; 
     
    8787               $full_upl = true; 
    8888          } 
    89            
     89 
    9090          if ($full_upl !== null && $this->core->auth->isSuperAdmin()) 
    9191          { 
     
    9393                    throw new Exception(__('Password verification failed')); 
    9494               } 
    95                 
     95 
    9696               if ($full_upl) { 
    9797                    files::uploadStatus($_FILES['up_full_file']); 
     
    104104                    $file = $_POST['public_full_file']; 
    105105               } 
    106                 
     106 
    107107               try { 
    108108                    # Try to unzip file 
     
    115115                         $bk = new flatImport($this->core,$file); 
    116116                    } 
    117                      
     117 
    118118                    $bk->importFull(); 
    119119               } catch (Exception $e) { 
     
    130130               http::redirect($this->getURL().'&do=full'); 
    131131          } 
    132            
     132 
    133133          header('content-type:text/plain'); 
    134134          var_dump($_POST); 
    135135          exit; 
    136            
     136 
    137137          $this->status = true; 
    138138     } 
    139       
     139 
    140140     public function gui() 
    141141     { 
     
    150150               return; 
    151151          } 
    152            
     152 
    153153          $public_files = array_merge(array('-' => ''),$this->getPublicFiles()); 
    154154          $has_files = (boolean) (count($public_files) - 1); 
    155            
     155 
    156156          echo 
    157157          '<script type="text/javascript">'."\n". 
     
    178178          "//]]>\n". 
    179179          "</script>\n"; 
    180            
     180 
    181181          echo 
    182182          '<form action="'.$this->getURL(true).'" method="post" enctype="multipart/form-data" class="fieldset">'. 
    183183          '<h3>'.__('Single blog').'</h3>'. 
    184184          '<p>'.sprintf(__('This will import a single blog backup as new content in the current blog: <strong>%s</strong>.'),html::escapeHTML($this->core->blog->name)).'</p>'. 
    185            
     185 
    186186          '<p><label for="up_single_file">'.__('Upload a backup file'). 
    187187          ' ('.sprintf(__('maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).')'.' </label>'. 
    188188          ' <input type="file" id="up_single_file" name="up_single_file" size="20" />'. 
    189189          '</p>'; 
    190            
     190 
    191191          if ($has_files) { 
    192                echo  
     192               echo 
    193193               '<p><label for="public_single_file" class="">'.__('or pick up a local file in your public directory').' </label> '. 
    194194               form::combo('public_single_file',$public_files). 
    195195               '</p>'; 
    196196          } 
    197            
    198           echo  
     197 
     198          echo 
    199199          '<p>'. 
    200200          $this->core->formNonce(). 
     
    202202          form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 
    203203          '<input type="submit" value="'.__('Import').'" /></p>'. 
    204            
     204 
    205205          '</form>'; 
    206            
     206 
    207207          if ($this->core->auth->isSuperAdmin()) 
    208208          { 
     
    211211               '<h3>'.__('Multiple blogs').'</h3>'. 
    212212               '<p class="warning">'.__('This will reset all the content of your database, except users.').'</p>'. 
    213                 
     213 
    214214               '<p><label for="up_full_file">'.__('Upload a backup file').' '. 
    215215               ' ('.sprintf(__('maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).')'.' </label>'. 
    216216               '<input type="file" id="up_full_file" name="up_full_file" size="20" />'. 
    217217               '</p>'; 
    218                 
     218 
    219219               if ($has_files) { 
    220                     echo  
     220                    echo 
    221221                    '<p><label for="public_full_file">'.__('or pick up a local file in your public directory').' </label>'. 
    222222                    form::combo('public_full_file',$public_files). 
    223223                    '</p>'; 
    224224               } 
    225                 
     225 
    226226               echo 
    227227               '<p><label for="your_pwd" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label>'. 
    228228               form::password('your_pwd',20,255).'</p>'. 
    229                 
     229 
    230230               '<p>'. 
    231231               $this->core->formNonce(). 
     
    233233               form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 
    234234               '<input type="submit" value="'.__('Import').'" /></p>'. 
    235                 
     235 
    236236               '</form>'; 
    237237          } 
    238238     } 
    239       
     239 
    240240     protected function getPublicFiles() 
    241241     { 
     
    246246               while (($entry = $dir->read()) !== false) { 
    247247                    $entry_path = $dir->path.'/'.$entry; 
    248                      
     248 
    249249                    if (is_file($entry_path) && is_readable($entry_path)) 
    250250                    { 
     
    261261          return $public_files; 
    262262     } 
    263       
     263 
    264264     protected static function checkFileContent($entry_path) 
    265265     { 
    266266          $ret = false; 
    267            
     267 
    268268          $fp = fopen($entry_path,'rb'); 
    269269          $ret = strpos(fgets($fp),'///DOTCLEAR|') === 0; 
    270270          fclose($fp); 
    271            
     271 
    272272          return $ret; 
    273273     } 
    274       
     274 
    275275     private function unzip($file) 
    276276     { 
    277277          $zip = new fileUnzip($file); 
    278            
     278 
    279279          if ($zip->isEmpty()) { 
    280280               $zip->close(); 
    281281               return false;//throw new Exception(__('File is empty or not a compressed file.')); 
    282282          } 
    283            
     283 
    284284          foreach($zip->getFilesList() as $zip_file) 
    285285          { 
     
    288288                    continue; 
    289289               } 
    290                 
     290 
    291291               # Check zipped file contents 
    292292               $content = $zip->unzip($zip_file); 
     
    295295                    continue; 
    296296               } 
    297                 
     297 
    298298               $target = path::fullFromRoot($zip_file,dirname($file)); 
    299                 
     299 
    300300               # Check existing files with same name 
    301301               if (file_exists($target)) { 
     
    304304                    throw new Exception(__('Another file with same name exists.')); 
    305305               } 
    306                 
     306 
    307307               # Extract backup content 
    308308               if (file_put_contents($target,$content) === false) { 
     
    311311                    throw new Exception(__('Failed to extract backup file.')); 
    312312               } 
    313                 
     313 
    314314               $zip->close(); 
    315315               unset($content); 
    316                 
     316 
    317317               # Return extracted file name 
    318318               return $target; 
    319319          } 
    320            
     320 
    321321          $zip->close(); 
    322322          throw new Exception(__('No backup in compressed file.')); 
    323323     } 
    324324} 
    325 ?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map