Dotclear

Changeset 2485:ad130cb12ae6


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

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • locales/_pot/plugins.pot

    r2417 r2485  
    88"Project-Id-Version: Dotclear 2\n" 
    99"Report-Msgid-Bugs-To: \n" 
    10 "POT-Creation-Date: 2013-10-17 09:38+0200\n" 
     10"POT-Creation-Date: 2013-10-23 13:44+0000\n" 
    1111"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 
    1212"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 
     
    15351535msgstr "" 
    15361536 
    1537 #: plugins/importExport/inc/flat/class.flat.import.php:222 
     1537#: plugins/importExport/inc/flat/class.flat.import.php:218 
     1538#: plugins/importExport/inc/flat/class.flat.import.php:301 
     1539#, php-format 
     1540msgid "Error raised at line %s" 
     1541msgstr "" 
     1542 
     1543#: plugins/importExport/inc/flat/class.flat.import.php:227 
    15381544msgid "File is not a full export." 
    15391545msgstr "" 
    15401546 
    1541 #: plugins/importExport/inc/flat/class.flat.import.php:704 
     1547#: plugins/importExport/inc/flat/class.flat.import.php:711 
    15421548#, php-format 
    15431549msgid "ID of \"%3$s\" does not match on record \"%1$s\" at line %2$s of backup file." 
     
    15611567msgstr "" 
    15621568 
    1563 #: plugins/importExport/index.php:105 
     1569#: plugins/importExport/index.php:104 
    15641570#, php-format 
    15651571msgid "Export functions are in the page %s." 
    1566 msgstr "" 
    1567  
    1568 #: plugins/importExport/index.php:106 plugins/maintenance/_admin.php:16 
    1569 #: plugins/maintenance/_admin.php:83 plugins/maintenance/_admin.php:179 
    1570 #: plugins/maintenance/_admin.php:201 plugins/maintenance/index.php:113 
    1571 #: plugins/maintenance/index.php:137 plugins/maintenance/index.php:153 
    1572 #: plugins/maintenance/index.php:186 
    1573 msgid "Maintenance" 
    15741572msgstr "" 
    15751573 
  • locales/fr/plugins.po

    r2418 r2485  
    1111"Project-Id-Version: Dotclear\n" 
    1212"Report-Msgid-Bugs-To: \n" 
    13 "POT-Creation-Date: 2013-10-17 09:38+0200\n" 
     13"POT-Creation-Date: 2013-10-23 13:44+0000\n" 
    1414"PO-Revision-Date: 2012-11-06 10:04+0100\n" 
    1515"Last-Translator: Franck Paul <carnet.franck.paul@gmail.com>\n" 
     
    10681068msgstr "Ce fichier n'est pas une exportation d'un blog." 
    10691069 
     1070#, php-format 
     1071msgid "Error raised at line %s" 
     1072msgstr "Erreur détectée ligne %s" 
     1073 
    10701074msgid "File is not a full export." 
    10711075msgstr "Ce fichier n'est pas un fichier de sauvegarde complet." 
  • 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 ?> 
  • plugins/importExport/inc/flat/class.flat.import.php

    r1743 r2485  
    1717     private $con; 
    1818     private $prefix; 
    19       
     19 
    2020     private $dc_version; 
    2121     private $dc_major; 
    2222     private $mode; 
    23       
     23 
    2424     private $blog_url; 
    2525     private $blog_name; 
    2626     private $blog_desc; 
    27       
     27 
    2828     private $users = array(); 
    29       
     29 
    3030     public $old_ids = array( 
    3131          'category' => array(), 
     
    3333          'media' => array() 
    3434     ); 
    35       
     35 
    3636     public $stack = array( 
    3737          'categories'=>null, 
     
    4141          'media_id'=>1, 
    4242          'comment_id'=>1, 
    43           'link_id'=>1 
     43          'link_id'=>1, 
     44          'log_id' => 1 
    4445     ); 
    45       
     46 
    4647     public $has_categories = false; 
    47       
     48 
    4849     public function __construct($core,$file) 
    4950     { 
    5051          parent::__construct($file); 
    51            
     52 
    5253          $first_line = fgets($this->fp); 
    5354          if (strpos($first_line,'///DOTCLEAR|') !== 0) { 
    5455               throw new Exception(__('File is not a DotClear backup.')); 
    5556          } 
    56            
     57 
    5758          @set_time_limit(300); 
    58            
     59 
    5960          $l = explode('|',$first_line); 
    60            
     61 
    6162          if (isset($l[1])) { 
    6263               $this->dc_version = $l[1]; 
    6364          } 
    64            
     65 
    6566          $this->mode = isset($l[2]) ? strtolower(trim($l[2])) : 'single'; 
    6667          if ($this->mode != 'full' && $this->mode != 'single') { 
    6768               $this->mode = 'single'; 
    6869          } 
    69            
     70 
    7071          if (version_compare('1.2',$this->dc_version,'<=') && 
    7172          version_compare('1.3',$this->dc_version,'>')) { 
     
    7475               $this->dc_major_version = '2.0'; 
    7576          } 
    76            
     77 
    7778          $this->core =& $core; 
    7879          $this->con =& $core->con; 
    7980          $this->prefix = $core->prefix; 
    80            
     81 
    8182          $this->cur_blog        = $this->con->openCursor($this->prefix.'blog'); 
    8283          $this->cur_category    = $this->con->openCursor($this->prefix.'category'); 
     
    9596          $this->cur_spamrule    = $this->con->openCursor($this->prefix.'spamrule'); 
    9697          $this->cur_version     = $this->con->openCursor($this->prefix.'version'); 
    97            
     98 
    9899          # --BEHAVIOR-- importInit 
    99100          $this->core->callBehavior('importInit',$this,$this->core); 
    100101     } 
    101       
     102 
    102103     public function importSingle() 
    103104     { 
     
    105106               throw new Exception(__('File is not a single blog export.')); 
    106107          } 
    107            
     108 
    108109          if (!$this->core->auth->check('admin',$this->core->blog->id)) { 
    109110               throw new Exception(__('Permission denied.')); 
    110111          } 
    111            
     112 
    112113          $this->blog_id = $this->core->blog->id; 
    113            
     114 
    114115          $this->stack['categories'] = $this->con->select( 
    115116               'SELECT cat_id, cat_title, cat_url '. 
     
    117118               "WHERE blog_id = '".$this->con->escape($this->blog_id)."' " 
    118119          ); 
    119            
     120 
    120121          $rs = $this->con->select('SELECT MAX(cat_id) FROM '.$this->prefix.'category'); 
    121122          $this->stack['cat_id'] = ((integer) $rs->f(0))+1; 
    122            
     123 
    123124          $rs = $this->con->select('SELECT MAX(link_id) FROM '.$this->prefix.'link'); 
    124125          $this->stack['link_id'] = ((integer) $rs->f(0))+1; 
    125            
     126 
    126127          $rs = $this->con->select('SELECT MAX(post_id) FROM '.$this->prefix.'post'); 
    127128          $this->stack['post_id'] = ((integer) $rs->f(0))+1; 
    128            
     129 
    129130          $rs = $this->con->select('SELECT MAX(media_id) FROM '.$this->prefix.'media'); 
    130131          $this->stack['media_id'] = ((integer) $rs->f(0))+1; 
    131            
     132 
    132133          $rs = $this->con->select('SELECT MAX(comment_id) FROM '.$this->prefix.'comment'); 
    133134          $this->stack['comment_id'] = ((integer) $rs->f(0))+1; 
    134            
     135 
     136          $rs = $this->con->select('SELECT MAX(log_id) FROM '.$this->prefix.'log'); 
     137          $this->stack['log_id'] = ((integer) $rs->f(0))+1; 
     138 
    135139          $rs = $this->con->select( 
    136140               'SELECT MAX(cat_rgt) AS cat_rgt FROM '.$this->prefix.'category '. 
    137141               "WHERE blog_id = '".$this->con->escape($this->core->blog->id)."'" 
    138142          ); 
    139            
     143 
    140144          if ((integer) $rs->cat_rgt > 0) { 
    141145               $this->has_categories = true; 
    142146               $this->stack['cat_lft'][$this->core->blog->id] = (integer) $rs->cat_rgt + 1; 
    143147          } 
    144            
     148 
    145149          $this->con->begin(); 
    146            
     150 
    147151          try 
    148152          { 
    149153               $last_line_name = ''; 
    150154               $constrained = array('post', 'meta', 'post_media', 'ping', 'comment'); 
    151                 
     155 
    152156               while (($line = $this->getLine()) !== false) 
    153157               { 
     
    156160                         $this->prepareDC12line($line); 
    157161                    } 
    158                      
     162 
    159163                    if ($last_line_name != $line->__name) { 
    160164                         if (in_array($last_line_name,$constrained)) { 
     
    163167                              if ($this->con->driver() == 'pgsql') $this->con->execute('SET CONSTRAINTS ALL DEFERRED'); 
    164168                         } 
    165                           
     169 
    166170                         if (in_array($line->__name,$constrained)) { 
    167171                              # DEFER 
     
    169173                              if ($this->con->driver() == 'pgsql') $this->con->execute('SET CONSTRAINTS ALL IMMEDIATE'); 
    170174                         } 
    171                           
     175 
    172176                         $last_line_name = $line->__name; 
    173177                    } 
    174                      
     178 
    175179                    switch ($line->__name) 
    176180                    { 
     
    200204                              break; 
    201205                    } 
    202                      
     206 
    203207                    # --BEHAVIOR-- importSingle 
    204208                    $this->core->callBehavior('importSingle',$line,$this,$this->core); 
    205209               } 
    206                 
     210 
    207211               if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli') $this->con->execute('SET foreign_key_checks = 1'); 
    208212               if ($this->con->driver() == 'pgsql') $this->con->execute('SET CONSTRAINTS ALL DEFERRED'); 
     
    210214          catch (Exception $e) 
    211215          { 
     216               @fclose($this->fp); 
    212217               $this->con->rollback(); 
    213                throw $e; 
    214           } 
    215            
     218               throw new Exception($e->getMessage().' - '.sprintf(__('Error raised at line %s'),$line->__line)); 
     219          } 
     220          @fclose($this->fp); 
    216221          $this->con->commit(); 
    217222     } 
    218       
     223 
    219224     public function importFull() 
    220225     { 
     
    222227               throw new Exception(__('File is not a full export.')); 
    223228          } 
    224            
     229 
    225230          if (!$this->core->auth->isSuperAdmin()) { 
    226231               throw new Exception(__('Permission denied.')); 
    227232          } 
    228            
     233 
    229234          $this->con->begin(); 
    230235          $this->con->execute('DELETE FROM '.$this->prefix.'blog'); 
     
    232237          $this->con->execute('DELETE FROM '.$this->prefix.'spamrule'); 
    233238          $this->con->execute('DELETE FROM '.$this->prefix.'setting'); 
    234            
     239          $this->con->execute('DELETE FROM '.$this->prefix.'log'); 
     240 
    235241          try 
    236242          { 
     
    291297          catch (Exception $e) 
    292298          { 
     299               @fclose($this->fp); 
    293300               $this->con->rollback(); 
    294                throw $e; 
    295           } 
    296            
     301               throw new Exception($e->getMessage().' - '.sprintf(__('Error raised at line %s'),$line->__line)); 
     302          } 
     303          @fclose($this->fp); 
    297304          $this->con->commit(); 
    298305     } 
    299       
     306 
    300307     private function insertBlog($blog) 
    301308     { 
    302309          $this->cur_blog->clean(); 
    303            
     310 
    304311          $this->cur_blog->blog_id     = (string) $blog->blog_id; 
    305312          $this->cur_blog->blog_uid    = (string) $blog->blog_uid; 
     
    309316          $this->cur_blog->blog_name   = (string) $blog->blog_name; 
    310317          $this->cur_blog->blog_desc   = (string) $blog->blog_desc; 
    311            
     318 
    312319          $this->cur_blog->blog_status = $blog->exists('blog_status') ? (integer) $blog->blog_status : 1; 
    313            
     320 
    314321          $this->cur_blog->insert(); 
    315322     } 
    316       
     323 
    317324     private function insertCategory($category) 
    318325     { 
    319326          $this->cur_category->clean(); 
    320            
     327 
    321328          $this->cur_category->cat_id       = (string) $category->cat_id; 
    322329          $this->cur_category->blog_id      = (string) $category->blog_id; 
     
    324331          $this->cur_category->cat_url      = (string) $category->cat_url; 
    325332          $this->cur_category->cat_desc     = (string) $category->cat_desc; 
    326            
     333 
    327334          if (!$this->has_categories && $category->exists('cat_lft') && $category->exists('cat_rgt')) { 
    328335               $this->cur_category->cat_lft = (integer) $category->cat_lft; 
     
    335342               $this->cur_category->cat_rgt = $this->stack['cat_lft'][$category->blog_id]++; 
    336343          } 
    337            
     344 
    338345          $this->cur_category->insert(); 
    339346     } 
    340       
     347 
    341348     private function insertLink($link) 
    342349     { 
    343350          $this->cur_link->clean(); 
    344            
     351 
    345352          $this->cur_link->link_id       = (integer) $link->link_id; 
    346353          $this->cur_link->blog_id       = (string) $link->blog_id; 
     
    351358          $this->cur_link->link_xfn      = (string) $link->link_xfn; 
    352359          $this->cur_link->link_position = (integer) $link->link_position; 
    353            
     360 
    354361          $this->cur_link->insert(); 
    355362     } 
    356       
     363 
    357364     private function insertSetting($setting) 
    358365     { 
    359366          $this->cur_setting->clean(); 
    360            
     367 
    361368          $this->cur_setting->setting_id    = (string) $setting->setting_id; 
    362369          $this->cur_setting->blog_id       = !$setting->blog_id ? null : (string) $setting->blog_id; 
     
    365372          $this->cur_setting->setting_type  = (string) $setting->setting_type; 
    366373          $this->cur_setting->setting_label = (string) $setting->setting_label; 
    367            
     374 
    368375          $this->cur_setting->insert(); 
    369376     } 
    370       
     377 
    371378     private function insertPref($pref) 
    372379     { 
     
    374381               return; 
    375382          } 
    376            
     383 
    377384          $this->cur_pref->clean(); 
    378            
     385 
    379386          $this->cur_pref->pref_id    = (string) $pref->pref_id; 
    380387          $this->cur_pref->user_id    = !$pref->user_id ? null : (string) $pref->user_id; 
     
    383390          $this->cur_pref->pref_type  = (string) $pref->pref_type; 
    384391          $this->cur_pref->pref_label = (string) $pref->pref_label; 
    385            
     392 
    386393          $this->cur_pref->insert(); 
    387394     } 
    388       
     395 
    389396     private function insertUser($user) 
    390397     { 
     
    392399               return; 
    393400          } 
    394            
     401 
    395402          $this->cur_user->clean(); 
    396            
     403 
    397404          $this->cur_user->user_id           = (string) $user->user_id; 
    398405          $this->cur_user->user_super        = (integer) $user->user_super; 
     
    410417          $this->cur_user->user_creadt       = (string) $user->user_creadt; 
    411418          $this->cur_user->user_upddt        = (string) $user->user_upddt; 
    412            
     419 
    413420          $this->cur_user->user_desc = $user->exists('user_desc') ? (string) $user->user_desc : null; 
    414421          $this->cur_user->user_options = $user->exists('user_options') ? (string) $user->user_options : null; 
    415422          $this->cur_user->user_status = $user->exists('user_status') ? (integer) $user->user_status : 1; 
    416            
     423 
    417424          $this->cur_user->insert(); 
    418            
     425 
    419426          $this->stack['users'][$user->user_id] = true; 
    420427     } 
    421       
     428 
    422429     private function insertPermissions($permissions) 
    423430     { 
    424431          $this->cur_permissions->clean(); 
    425            
     432 
    426433          $this->cur_permissions->user_id     = (string) $permissions->user_id; 
    427434          $this->cur_permissions->blog_id     = (string) $permissions->blog_id; 
    428435          $this->cur_permissions->permissions = (string) $permissions->permissions; 
    429            
     436 
    430437          $this->cur_permissions->insert(); 
    431438     } 
    432       
     439 
    433440     private function insertPost($post) 
    434441     { 
    435442          $this->cur_post->clean(); 
    436            
     443 
    437444          $cat_id = (integer) $post->cat_id; 
    438445          if (!$cat_id) { 
    439446               $cat_id = null; 
    440447          } 
    441            
     448 
    442449          $post_password = $post->post_password ? (string) $post->post_password : null; 
    443            
     450 
    444451          $this->cur_post->post_id            = (integer) $post->post_id; 
    445452          $this->cur_post->blog_id            = (string) $post->blog_id; 
     
    468475          $this->cur_post->nb_comment         = (integer) $post->nb_comment; 
    469476          $this->cur_post->nb_trackback       = (integer) $post->nb_trackback; 
    470            
     477 
    471478          $this->cur_post->post_tz = $post->exists('post_tz') ? (string) $post->post_tz : 'UTC'; 
    472            
     479 
    473480          $this->cur_post->insert(); 
    474481     } 
    475       
     482 
    476483     private function insertMeta($meta) 
    477484     { 
    478485          $this->cur_meta->clean(); 
    479            
     486 
    480487          $this->cur_meta->meta_id   = (string) $meta->meta_id; 
    481488          $this->cur_meta->meta_type = (string) $meta->meta_type; 
    482489          $this->cur_meta->post_id   = (integer) $meta->post_id; 
    483            
     490 
    484491          $this->cur_meta->insert(); 
    485492     } 
    486       
     493 
    487494     private function insertMedia($media) 
    488495     { 
    489496          $this->cur_media->clean(); 
    490            
     497 
    491498          $this->cur_media->media_id      = (integer) $media->media_id; 
    492499          $this->cur_media->user_id       = (string) $media->user_id; 
     
    499506          $this->cur_media->media_upddt   = (string) $media->media_upddt; 
    500507          $this->cur_media->media_private = (integer) $media->media_private; 
    501            
     508 
    502509          $this->cur_media->media_dir = $media->exists('media_dir') ? (string) $media->media_dir : dirname($media->media_file); 
    503            
     510 
    504511          if (!$this->mediaExists()) { 
    505512               $this->cur_media->insert(); 
    506513          } 
    507514     } 
    508       
     515 
    509516     private function insertPostMedia($post_media) 
    510517     { 
    511518          $this->cur_post_media->clean(); 
    512            
     519 
    513520          $this->cur_post_media->media_id = (integer) $post_media->media_id; 
    514521          $this->cur_post_media->post_id  = (integer) $post_media->post_id; 
    515            
     522 
    516523          $this->cur_post_media->insert(); 
    517524     } 
    518       
     525 
    519526     private function insertLog($log) 
    520527     { 
    521528          $this->cur_log->clean(); 
    522            
     529 
    523530          $this->cur_log->log_id    = (integer) $log->log_id; 
    524531          $this->cur_log->user_id   = (string) $log->user_id; 
     
    527534          $this->cur_log->log_ip    = (string) $log->log_ip; 
    528535          $this->cur_log->log_msg   = (string) $log->log_msg; 
    529            
     536 
    530537          $this->cur_log->insert(); 
    531538     } 
    532       
     539 
    533540     private function insertPing($ping) 
    534541     { 
    535542          $this->cur_ping->clean(); 
    536            
     543 
    537544          $this->cur_ping->post_id  = (integer) $ping->post_id; 
    538545          $this->cur_ping->ping_url = (string) $ping->ping_url; 
    539546          $this->cur_ping->ping_dt  = (string) $ping->ping_dt; 
    540            
     547 
    541548          $this->cur_ping->insert(); 
    542549     } 
    543       
     550 
    544551     private function insertComment($comment) 
    545552     { 
    546553          $this->cur_comment->clean(); 
    547            
     554 
    548555          $this->cur_comment->comment_id          = (integer) $comment->comment_id; 
    549556          $this->cur_comment->post_id             = (integer) $comment->post_id; 
     
    559566          $this->cur_comment->comment_spam_status = (integer) $comment->comment_spam_status; 
    560567          $this->cur_comment->comment_trackback   = (integer) $comment->comment_trackback; 
    561            
     568 
    562569          $this->cur_comment->comment_tz = $comment->exists('comment_tz') ? (string) $comment->comment_tz : 'UTC'; 
    563570          $this->cur_comment->comment_spam_filter = $comment->exists('comment_spam_filter') ? (integer) $comment->comment_spam_filter : null; 
    564            
     571 
    565572          $this->cur_comment->insert(); 
    566573     } 
    567       
     574 
    568575     private function insertSpamRule($spamrule) 
    569576     { 
    570577          $this->cur_spamrule->clean(); 
    571            
     578 
    572579          $this->cur_spamrule->rule_id      = (integer) $spamrule->rule_id; 
    573580          $this->cur_spamrule->blog_id      = !$spamrule->blog_id ? null : (string) $spamrule->blog_id; 
    574581          $this->cur_spamrule->rule_type    = (string) $spamrule->rule_type; 
    575582          $this->cur_spamrule->rule_content = (string) $spamrule->rule_content; 
    576            
     583 
    577584          $this->cur_spamrule->insert(); 
    578585     } 
    579       
     586 
    580587     private function insertCategorySingle($category) 
    581588     { 
    582589          $this->cur_category->clean(); 
    583            
     590 
    584591          $m = $this->searchCategory($this->stack['categories'],$category->cat_url); 
    585            
     592 
    586593          $old_id = $category->cat_id; 
    587594          if ($m !== false) 
     
    594601               $category->cat_id = $cat_id; 
    595602               $category->blog_id = $this->blog_id; 
    596                 
     603 
    597604               $this->insertCategory($category); 
    598605               $this->stack['cat_id']++; 
    599606          } 
    600            
     607 
    601608          $this->old_ids['category'][(integer) $old_id] = $cat_id; 
    602609     } 
    603       
     610 
    604611     private function insertLinkSingle($link) 
    605612     { 
    606613          $link->blog_id = $this->blog_id; 
    607614          $link->link_id = $this->stack['link_id']; 
    608            
     615 
    609616          $this->insertLink($link); 
    610617          $this->stack['link_id']++; 
    611618     } 
    612       
     619 
    613620     private function insertPostSingle($post) 
    614621     { 
     
    616623               $post_id = $this->stack['post_id']; 
    617624               $this->old_ids['post'][(integer) $post->post_id] = $post_id; 
    618                 
     625 
    619626               $cat_id = $post->cat_id ? $this->old_ids['category'][(integer) $post->cat_id] : null; 
    620                 
     627 
    621628               $post->post_id = $post_id; 
    622629               $post->cat_id = $cat_id; 
    623630               $post->blog_id = $this->blog_id; 
    624                 
     631 
    625632               $post->post_url = $this->core->blog->getPostURL( 
    626633                    $post->post_url,$post->post_dt,$post->post_title,$post->post_id 
    627634               ); 
    628                 
     635 
    629636               $this->insertPost($post); 
    630637               $this->stack['post_id']++; 
     
    633640          } 
    634641     } 
    635       
     642 
    636643     private function insertMetaSingle($meta) 
    637644     { 
     
    643650          } 
    644651     } 
    645       
     652 
    646653     private function insertMediaSingle($media) 
    647654     { 
    648655          $media_id = $this->stack['media_id']; 
    649656          $old_id = $media->media_id; 
    650            
     657 
    651658          $media->media_id = $media_id; 
    652659          $media->media_path = $this->core->blog->settings->system->public_path; 
    653660          $media->user_id = $this->getUserId($media->user_id); 
    654            
     661 
    655662          $this->insertMedia($media); 
    656663          $this->stack['media_id']++; 
    657664          $this->old_ids['media'][(integer) $old_id] = $media_id; 
    658665     } 
    659       
     666 
    660667     private function insertPostMediaSingle($post_media) 
    661668     { 
     
    664671               $post_media->media_id = $this->old_ids['media'][(integer) $post_media->media_id]; 
    665672               $post_media->post_id = $this->old_ids['post'][(integer) $post_media->post_id]; 
    666                 
     673 
    667674               $this->insertPostMedia($post_media); 
    668675          } elseif (!isset($this->old_ids['media'][(integer) $post_media->media_id])) { 
     
    672679          } 
    673680     } 
    674       
     681 
    675682     private function insertPingSingle($ping) 
    676683     { 
    677684          if (isset($this->old_ids['post'][(integer) $ping->post_id])) { 
    678685               $ping->post_id = $this->old_ids['post'][(integer) $ping->post_id]; 
    679                 
     686 
    680687               $this->insertPing($ping); 
    681688          } else { 
     
    683690          } 
    684691     } 
    685       
     692 
    686693     private function insertCommentSingle($comment) 
    687694     { 
    688695          if (isset($this->old_ids['post'][(integer) $comment->post_id])) { 
    689696               $comment_id = $this->stack['comment_id']; 
    690                 
     697 
    691698               $comment->comment_id = $comment_id; 
    692699               $comment->post_id = $this->old_ids['post'][(integer) $comment->post_id]; 
    693                 
     700 
    694701               $this->insertComment($comment); 
    695702               $this->stack['comment_id']++; 
     
    698705          } 
    699706     } 
    700       
     707 
    701708     private static function throwIdError($name,$line,$related) 
    702709     { 
     
    708715          )); 
    709716     } 
    710       
     717 
    711718     public function searchCategory($rs,$url) 
    712719     { 
     
    717724               } 
    718725          } 
    719            
     726 
    720727          return false; 
    721728     } 
    722       
     729 
    723730     public function getUserId($user_id) 
    724731     { 
     
    730737                    $user_id = preg_replace('/[^A-Za-z0-9]$/','',$user_id); 
    731738                    $user_id .= strlen($user_id) < 2 ? '-a' : ''; 
    732                      
     739 
    733740                    # We change user_id, we need to check again 
    734741                    if (!$this->userExists($user_id)) 
     
    737744                         $this->cur_user->user_id = (string) $user_id; 
    738745                         $this->cur_user->user_pwd = md5(uniqid()); 
    739                           
     746 
    740747                         $this->core->addUser($this->cur_user); 
    741                           
     748 
    742749                         $this->stack['users'][$user_id] = true; 
    743750                    } 
     
    749756               } 
    750757          } 
    751            
     758 
    752759          return $user_id; 
    753760     } 
    754       
     761 
    755762     private function userExists($user_id) 
    756763     { 
     
    758765               return $this->stack['users'][$user_id]; 
    759766          } 
    760            
     767 
    761768          $strReq = 'SELECT user_id '. 
    762769                    'FROM '.$this->prefix.'user '. 
    763770                    "WHERE user_id = '".$this->con->escape($user_id)."' "; 
    764            
     771 
    765772          $rs = $this->con->select($strReq); 
    766            
     773 
    767774          $this->stack['users'][$user_id] = !$rs->isEmpty(); 
    768775          return $this->stack['users'][$user_id]; 
    769776     } 
    770       
     777 
    771778     private function prefExists($pref_ws,$pref_id,$user_id) 
    772779     { 
     
    780787               $strReq .= "AND user_id = '".$this->con->escape($user_id)."' "; 
    781788          } 
    782            
     789 
    783790          $rs = $this->con->select($strReq); 
    784            
     791 
    785792          return !$rs->isEmpty(); 
    786793     } 
    787       
     794 
    788795     private function mediaExists() 
    789796     { 
     
    792799                    "WHERE media_path = '".$this->con->escape($this->cur_media->media_path)."' ". 
    793800                    "AND media_file = '".$this->con->escape($this->cur_media->media_file)."' "; 
    794            
     801 
    795802          $rs = $this->con->select($strReq); 
    796            
     803 
    797804          return !$rs->isEmpty(); 
    798805     } 
    799       
     806 
    800807     private function prepareDC12line(&$line) 
    801808     { 
     
    804811          'dc_wiki_comments','dc_use_smilies','dc_date_format','dc_time_format', 
    805812          'dc_url_scan'); 
    806            
     813 
    807814          switch ($line->__name) 
    808815          { 
     
    830837                    $line->post_content_xhtml = $line->post_content; 
    831838                    $line->post_excerpt_xhtml = $line->post_chapo; 
    832                      
     839 
    833840                    if ($line->post_format == 'wiki') { 
    834841                         $line->post_content = $line->post_content_wiki; 
     
    838845                         $line->post_excerpt = $line->post_chapo; 
    839846                    } 
    840                      
     847 
    841848                    $line->post_status = (integer) $line->post_pub; 
    842849                    $line->post_type = 'post'; 
    843850                    $line->blog_id = 'default'; 
    844                      
     851 
    845852                    $line->drop('post_titre_url','post_content_wiki','post_chapo','post_chapo_wiki','post_pub'); 
    846                      
     853 
    847854                    break; 
    848855               case 'post_meta': 
     
    862869                    break; 
    863870          } 
    864            
     871 
    865872          # --BEHAVIOR-- importPrepareDC12 
    866873          $this->core->callBehavior('importPrepareDC12',$line,$this,$this->core); 
    867874     } 
    868875} 
    869 ?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map