Dotclear


Ignore:
Timestamp:
07/09/12 16:53:05 (13 years ago)
Author:
JcDenis
Branch:
default
Message:

Flat import errors are now more verbose, fixes #888

File:
1 edited

Legend:

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

    r840 r841  
    1717     private $line_cols = array(); 
    1818     private $line_name; 
     19     private $line_num; 
    1920      
    2021     private $replacement = array( 
     
    2930          if (file_exists($file) && is_readable($file)) { 
    3031               $this->fp = fopen($file,'rb'); 
     32               $this->line_num = 1; 
    3133          } else { 
    3234               throw new Exception(__('No file to read.')); 
     
    4345     public function getLine() 
    4446     { 
    45           if (feof($this->fp)) { 
     47          if (($line = $this->nextLine()) === false) { 
    4648               return false; 
    4749          } 
    48            
    49           $line = trim(fgets($this->fp)); 
    5050           
    5151          if (substr($line,0,1) == '[') 
     
    6464                
    6565               if (count($this->line_cols) != count($line)) { 
    66                     throw new Exception('Invalid row count'); 
     66                    throw new Exception(sprintf('Invalid row count at line %s',$this->line_num)); 
    6767               } 
    6868                
     
    7474               } 
    7575                
    76                return new flatBackupItem($this->line_name,$res); 
     76               return new flatBackupItem($this->line_name,$res,$this->line_num); 
    7777          } 
    7878          else 
     
    8181          } 
    8282     } 
     83      
     84     private function nextLine() 
     85     { 
     86          if (feof($this->fp)) { 
     87               return false; 
     88          } 
     89          $this->line_num++; 
     90           
     91          $line = fgets($this->fp); 
     92          $line = trim($line); 
     93           
     94          return empty($line) ? $this->nextLine() : $line; 
     95     } 
    8396} 
    8497 
     
    8699{ 
    87100     public $__name; 
     101     public $__line; 
    88102     private $__data = array(); 
    89103      
    90      public function __construct($name,$data) 
     104     public function __construct($name,$data,$line) 
    91105     { 
    92106          $this->__name = $name; 
    93107          $this->__data = $data; 
     108          $this->__line = $line; 
    94109     } 
    95110      
Note: See TracChangeset for help on using the changeset viewer.

Sites map