Changeset 877

Show
Ignore:
Timestamp:
09/01/08 18:34:50 (3 months ago)
Author:
ayunyan
Message:

plugin:mtimport added potfile. two or more internal importar is supported.

Location:
plugins/mtimport/trunk
Files:
2 added
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/mtimport/trunk/mtimport.plugin.php

    r862 r877  
    1212 * Tested with Movable Type Ver 4.12 (MySQL) 
    1313 */ 
    14 define('MT_IMPORT_BATCH', 100); 
    1514class MTImport extends Plugin implements Importer 
    1615{ 
    17     private $supported_importers = array(); 
     16    private $supported_importers; 
     17    private $import_batch = 100; 
    1818 
    1919    /** 
     
    4747        $this->load_text_domain('mtimport'); 
    4848 
    49         $this->supported_importers = array(_t('Movable Type Database' )); 
     49        $this->supported_importers = array(); 
     50        $this->supported_importers['mysql'] = _t('Movable Type Database (MySQL)', 'mtimport'); 
     51        $this->supported_importers['backup'] = _t('Movable Type Backup File', 'mtimport'); 
     52        $this->supported_importers['export'] = _t('Movable Type Export File', 'mtimport'); 
    5053    } 
    5154 
     
    8588    public function filter_import_stage($stageoutput, $import_name, $stage, $step) 
    8689    { 
    87         // Only act on this filter if the import_name is one we handle... 
    88         if( !in_array( $import_name, $this->supported_importers ) ) { 
    89             // Must return $stageoutput as it may contain the stage HTML of another importer 
     90        if (($importer = array_search($import_name, $this->supported_importers)) === false) { 
    9091            return $stageoutput; 
    9192        } 
    9293 
    93         $inputs = array(); 
    94  
    95         $stage_method = 'stage_' . $stage; 
     94 
     95        if (empty($stage)) $stage = 1; 
     96 
     97        $stage_method = $importer . '_stage_' . $stage; 
    9698        if (!method_exists($this, $stage_method)) { 
    97             $stage_method = 'stage_1'; 
    98         } 
    99  
    100         $output = $this->$stage_method($inputs); 
     99            return sprintf(_t('Unknown Stage: %s', 'mtimport'), $stage); 
     100        } 
     101 
     102        $output = $this->$stage_method(array()); 
    101103 
    102104        return $output; 
     
    104106 
    105107    /** 
    106      * Create the UI for first stage of the MT import process 
     108     * first stage of Movable Type (MySQL) import process 
    107109     * 
    108110     * @access private 
    109111     * @return string The UI for the first stage of the import process 
    110112     */ 
    111     private function stage_1($inputs) 
     113    private function mysql_stage_1($inputs) 
    112114    { 
    113115        $default_values= array( 
     
    121123        $inputs= array_merge( $default_values, $inputs ); 
    122124        extract( $inputs ); 
    123         if( $warning != '' ) { 
    124             $warning= "<p class=\"warning\">{$warning}</p>"; 
    125         } 
    126125 
    127126        ob_start(); 
    128127?> 
    129128<p><?php echo _t('Habari will attempt to import from a Movable Type Database.', 'mtimport'); ?></p> 
    130 <?php echo $warning; ?> 
     129<?php if (!empty($warning)): ?> 
     130<p class="warning"><?php echo htmlspecialchars($warning); ?></p> 
     131<?php endif; ?> 
    131132<p><?php echo _t('Please provide the connection details for an existing Movable Type database:', 'mtimport'); ?></p> 
    132133<table> 
     
    146147 
    147148    /** 
    148      * Create the UI for second stage of the MT import process 
     149     * second stage of Movable Type (MySQL) import process 
    149150     * 
    150151     * @access private 
    151152     * @return string The UI for the first stage of the import process 
    152153     */ 
    153     private function stage_2($inputs) 
     154    private function mysql_stage_2($inputs) 
    154155    { 
    155156        $valid_fields= array('db_name','db_host','db_user','db_pass','db_prefix'); 
     
    187188 
    188189    /** 
    189      * Create the UI for third stage of the MT import process 
     190     * third stage of Movable Type (MySQL) import process 
    190191     * 
    191192     * @access private 
    192193     * @return string The UI for the first stage of the import process 
    193194     */ 
    194     private function stage_3($inputs) 
     195    private function mysql_stage_3($inputs) 
    195196    { 
    196197        $valid_fields= array('db_name','db_host','db_user','db_pass','db_prefix', 'blog_id'); 
     
    203204        } 
    204205 
    205         $ajax_url= URL::get('auth_ajax', array('context' => 'mt_import_users')); 
     206        $ajax_url= URL::get('auth_ajax', array('context' => 'mt_mysql_import_users')); 
    206207        EventLog::log(sprintf(_t('Starting import from "%s"'), $db_name)); 
    207208        Options::set('import_errors', array()); 
     
    242243     * @return 
    243244     */ 
    244     public function action_auth_ajax_mt_import_users($handler) 
     245    public function action_auth_ajax_mt_mysql_import_users($handler) 
    245246    { 
    246247        $valid_fields = array('db_name','db_host','db_user','db_pass','db_prefix','userindex', 'blog_id'); 
     
    281282        } 
    282283 
    283         $ajax_url= URL::get('auth_ajax', array('context' => 'mt_import_posts')); 
     284        $ajax_url= URL::get('auth_ajax', array('context' => 'mt_mysql_import_posts')); 
    284285?> 
    285286<script type="text/javascript"> 
     
    310311     * @param AjaxHandler $handler The handler that handled the request, contains $_POST info 
    311312     */ 
    312     public function action_auth_ajax_mt_import_posts($handler) 
     313    public function action_auth_ajax_mt_mysql_import_posts($handler) 
    313314    { 
    314315        $valid_fields= array('db_name','db_host','db_user','db_pass','db_prefix','postindex', 'blog_id'); 
     
    324325 
    325326        $postcount = $mtdb->get_value("SELECT count(entry_id) FROM {$db_prefix}entry WHERE entry_blog_id = '{$blog_id}';"); 
    326         $min= $postindex * MT_IMPORT_BATCH + ($postindex == 0 ? 0 : 1); 
    327         $max= min( ( $postindex + 1 ) * MT_IMPORT_BATCH, $postcount ); 
     327        $min= $postindex * $this->import_batch + ($postindex == 0 ? 0 : 1); 
     328        $max= min( ( $postindex + 1 ) * $this->import_batch, $postcount ); 
    328329 
    329330        $user_map = array(); 
     
    353354            LEFT JOIN {$db_prefix}category ON entry_category_id = category_id 
    354355            WHERE entry_blog_id = '{$blog_id}' 
    355             ORDER BY id DESC LIMIT {$min}," . MT_IMPORT_BATCH . ';', 
     356            ORDER BY id DESC LIMIT {$min}," . $this->import_batch . ';', 
    356357            array(), 'Post'); 
    357358 
     
    411412 
    412413        if($max < $postcount) { 
    413             $ajax_url= URL::get('auth_ajax', array('context' => 'mt_import_posts')); 
     414            $ajax_url= URL::get('auth_ajax', array('context' => 'mt_mysql_import_posts')); 
    414415            $postindex++; 
    415416        } else { 
    416             $ajax_url= URL::get('auth_ajax', array('context' => 'mt_import_comments')); 
     417            $ajax_url= URL::get('auth_ajax', array('context' => 'mt_mysql_import_comments')); 
    417418        } 
    418419?> 
     
    442443     * @param AjaxHandler $handler The handler that handled the request, contains $_POST info 
    443444     */ 
    444     public function action_auth_ajax_mt_import_comments($handler) 
     445    public function action_auth_ajax_mt_mysql_import_comments($handler) 
    445446    { 
    446447        $valid_fields = array( 'db_name','db_host','db_user','db_pass','db_prefix', 'blog_id', 'commentindex'); 
     
    455456 
    456457        $commentcount= $mtdb->get_value("SELECT count(comment_id) FROM {$db_prefix}comment WHERE comment_blog_id = '{$blog_id}';"); 
    457         $min = $commentindex * MT_IMPORT_BATCH + 1; 
    458         $max = min(($commentindex + 1) * MT_IMPORT_BATCH, $commentcount); 
     458        $min = $commentindex * $this->import_batch + 1; 
     459        $max = min(($commentindex + 1) * $this->import_batch, $commentcount); 
    459460 
    460461        echo sprintf(_t('<p>Importing comments %d-%d of %d.</p>'), $min, $max, $commentcount); 
     
    479480            FROM {$db_prefix}comment 
    480481            WHERE comment_blog_id = '{$blog_id}' 
    481             LIMIT {$min}," . MT_IMPORT_BATCH, array(), 'Comment'); 
     482            LIMIT {$min}," . $this->import_batch, array(), 'Comment'); 
    482483 
    483484        $comment_map = DB::get_column("SELECT value FROM " . DB::table('commentinfo') . " WHERE name='mt_comment_id';"); 
     
    528529 
    529530        if( $max < $commentcount ) { 
    530             $ajax_url= URL::get('auth_ajax', array( 'context' => 'mt_import_comments')); 
     531            $ajax_url= URL::get('auth_ajax', array( 'context' => 'mt_mysql_import_comments')); 
    531532            $commentindex++; 
    532533        } else { 
    533             $ajax_url= URL::get('auth_ajax', array('context' => 'mt_import_trackbacks')); 
     534            $ajax_url= URL::get('auth_ajax', array('context' => 'mt_mysql_import_trackbacks')); 
    534535        } 
    535536 
     
    560561     * @param AjaxHandler $handler The handler that handled the request, contains $_POST info 
    561562     */ 
    562     public function action_auth_ajax_mt_import_trackbacks($handler) 
     563    public function action_auth_ajax_mt_mysql_import_trackbacks($handler) 
    563564    { 
    564565        $valid_fields = array( 'db_name','db_host','db_user','db_pass','db_prefix', 'blog_id', 'trackbackindex'); 
     
    573574 
    574575        $trackbackcount= $mtdb->get_value("SELECT count(trackback_id) FROM {$db_prefix}trackback WHERE trackback_blog_id = '{$blog_id}';"); 
    575         $min = $trackbackindex * MT_IMPORT_BATCH + 1; 
    576         $max = min( ( $trackbackindex + 1 ) * MT_IMPORT_BATCH, $trackbackcount ); 
     576        $min = $trackbackindex * $this->import_batch + 1; 
     577        $max = min( ( $trackbackindex + 1 ) * $this->import_batch, $trackbackcount ); 
    577578 
    578579        echo sprintf(_t('<p>Importing trackbacks %d-%d of %d.</p>'), $min, $max, $trackbackcount); 
     
    594595            FROM {$db_prefix}trackback 
    595596            WHERE trackback_blog_id = '{$blog_id}' 
    596             LIMIT {$min}," . MT_IMPORT_BATCH, array(), 'Comment'); 
     597            LIMIT {$min}," . $this->import_batch, array(), 'Comment'); 
    597598 
    598599        $comment_map = DB::get_column("SELECT value FROM " . DB::table('commentinfo') . " WHERE name='mt_trackback_id';"); 
     
    638639 
    639640        if($max < $trackbackcount) { 
    640             $ajax_url= URL::get('auth_ajax', array( 'context' => 'mt_import_trackbacks')); 
     641            $ajax_url= URL::get('auth_ajax', array( 'context' => 'mt_mysql_import_trackbacks')); 
    641642            $trackbackindex++; 
    642643        } else { 
     
    675676 
    676677    /** 
     678     * first stage of Movable Type Backup File import process 
     679     * 
     680     * @access private 
     681     * @return string The UI for the first stage of the import process 
     682     */ 
     683    private function backup_stage_1($inputs) 
     684    { 
     685        $default_values= array( 
     686            'db_name' => '', 
     687            'db_host' => 'localhost', 
     688            'db_user' => '', 
     689            'db_pass' => '', 
     690            'db_prefix' => 'mt_', 
     691            'warning' => '' 
     692         ); 
     693        $inputs= array_merge( $default_values, $inputs ); 
     694        extract($inputs); 
     695 
     696        ob_start(); 
     697?> 
     698<p><?php echo _t('Habari will attempt to import from a Movable Type Backup File.', 'mtimport'); ?></p> 
     699<?php if (!empty($warning)): ?> 
     700<p class="warning"><?php echo htmlspecialchars($warning); ?></p> 
     701<?php endif; ?> 
     702<p><?php echo _t('Please provide the connection details for an existing Movable Type database:', 'mtimport'); ?></p> 
     703<table> 
     704    <tr><td><?php echo _t('Backup File', 'mtimport'); ?></td><td><input type="text" name="db_name" value="<?php echo htmlspecialchars($db_name); ?>"></td></tr> 
     705</table> 
     706<input type="hidden" name="stage" value="2"> 
     707<p class="submit"><input type="submit" name="import" value="<?php echo _t('Next', 'mtimport'); ?>" /></p> 
     708<?php 
     709        $output = ob_get_contents(); 
     710        ob_end_clean(); 
     711        return $output; 
     712    } 
     713 
     714    /** 
    677715     * Attempt to connect to the Movable Type database 
    678716     *