Changeset 877
- Timestamp:
- 09/01/08 18:34:50 (3 months ago)
- Location:
- plugins/mtimport/trunk
- Files:
-
- 2 added
- 1 modified
-
locale (added)
-
locale/default.pot (added)
-
mtimport.plugin.php (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plugins/mtimport/trunk/mtimport.plugin.php
r862 r877 12 12 * Tested with Movable Type Ver 4.12 (MySQL) 13 13 */ 14 define('MT_IMPORT_BATCH', 100);15 14 class MTImport extends Plugin implements Importer 16 15 { 17 private $supported_importers = array(); 16 private $supported_importers; 17 private $import_batch = 100; 18 18 19 19 /** … … 47 47 $this->load_text_domain('mtimport'); 48 48 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'); 50 53 } 51 54 … … 85 88 public function filter_import_stage($stageoutput, $import_name, $stage, $step) 86 89 { 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) { 90 91 return $stageoutput; 91 92 } 92 93 93 $inputs = array(); 94 95 $stage_method = 'stage_' . $stage; 94 95 if (empty($stage)) $stage = 1; 96 97 $stage_method = $importer . '_stage_' . $stage; 96 98 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()); 101 103 102 104 return $output; … … 104 106 105 107 /** 106 * Create the UI for first stage of the MTimport process108 * first stage of Movable Type (MySQL) import process 107 109 * 108 110 * @access private 109 111 * @return string The UI for the first stage of the import process 110 112 */ 111 private function stage_1($inputs)113 private function mysql_stage_1($inputs) 112 114 { 113 115 $default_values= array( … … 121 123 $inputs= array_merge( $default_values, $inputs ); 122 124 extract( $inputs ); 123 if( $warning != '' ) {124 $warning= "<p class=\"warning\">{$warning}</p>";125 }126 125 127 126 ob_start(); 128 127 ?> 129 128 <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; ?> 131 132 <p><?php echo _t('Please provide the connection details for an existing Movable Type database:', 'mtimport'); ?></p> 132 133 <table> … … 146 147 147 148 /** 148 * Create the UI for second stage of the MTimport process149 * second stage of Movable Type (MySQL) import process 149 150 * 150 151 * @access private 151 152 * @return string The UI for the first stage of the import process 152 153 */ 153 private function stage_2($inputs)154 private function mysql_stage_2($inputs) 154 155 { 155 156 $valid_fields= array('db_name','db_host','db_user','db_pass','db_prefix'); … … 187 188 188 189 /** 189 * Create the UI for third stage of the MTimport process190 * third stage of Movable Type (MySQL) import process 190 191 * 191 192 * @access private 192 193 * @return string The UI for the first stage of the import process 193 194 */ 194 private function stage_3($inputs)195 private function mysql_stage_3($inputs) 195 196 { 196 197 $valid_fields= array('db_name','db_host','db_user','db_pass','db_prefix', 'blog_id'); … … 203 204 } 204 205 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')); 206 207 EventLog::log(sprintf(_t('Starting import from "%s"'), $db_name)); 207 208 Options::set('import_errors', array()); … … 242 243 * @return 243 244 */ 244 public function action_auth_ajax_mt_ import_users($handler)245 public function action_auth_ajax_mt_mysql_import_users($handler) 245 246 { 246 247 $valid_fields = array('db_name','db_host','db_user','db_pass','db_prefix','userindex', 'blog_id'); … … 281 282 } 282 283 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')); 284 285 ?> 285 286 <script type="text/javascript"> … … 310 311 * @param AjaxHandler $handler The handler that handled the request, contains $_POST info 311 312 */ 312 public function action_auth_ajax_mt_ import_posts($handler)313 public function action_auth_ajax_mt_mysql_import_posts($handler) 313 314 { 314 315 $valid_fields= array('db_name','db_host','db_user','db_pass','db_prefix','postindex', 'blog_id'); … … 324 325 325 326 $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 ); 328 329 329 330 $user_map = array(); … … 353 354 LEFT JOIN {$db_prefix}category ON entry_category_id = category_id 354 355 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 . ';', 356 357 array(), 'Post'); 357 358 … … 411 412 412 413 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')); 414 415 $postindex++; 415 416 } 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')); 417 418 } 418 419 ?> … … 442 443 * @param AjaxHandler $handler The handler that handled the request, contains $_POST info 443 444 */ 444 public function action_auth_ajax_mt_ import_comments($handler)445 public function action_auth_ajax_mt_mysql_import_comments($handler) 445 446 { 446 447 $valid_fields = array( 'db_name','db_host','db_user','db_pass','db_prefix', 'blog_id', 'commentindex'); … … 455 456 456 457 $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); 459 460 460 461 echo sprintf(_t('<p>Importing comments %d-%d of %d.</p>'), $min, $max, $commentcount); … … 479 480 FROM {$db_prefix}comment 480 481 WHERE comment_blog_id = '{$blog_id}' 481 LIMIT {$min}," . MT_IMPORT_BATCH, array(), 'Comment');482 LIMIT {$min}," . $this->import_batch, array(), 'Comment'); 482 483 483 484 $comment_map = DB::get_column("SELECT value FROM " . DB::table('commentinfo') . " WHERE name='mt_comment_id';"); … … 528 529 529 530 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')); 531 532 $commentindex++; 532 533 } 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')); 534 535 } 535 536 … … 560 561 * @param AjaxHandler $handler The handler that handled the request, contains $_POST info 561 562 */ 562 public function action_auth_ajax_mt_ import_trackbacks($handler)563 public function action_auth_ajax_mt_mysql_import_trackbacks($handler) 563 564 { 564 565 $valid_fields = array( 'db_name','db_host','db_user','db_pass','db_prefix', 'blog_id', 'trackbackindex'); … … 573 574 574 575 $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 ); 577 578 578 579 echo sprintf(_t('<p>Importing trackbacks %d-%d of %d.</p>'), $min, $max, $trackbackcount); … … 594 595 FROM {$db_prefix}trackback 595 596 WHERE trackback_blog_id = '{$blog_id}' 596 LIMIT {$min}," . MT_IMPORT_BATCH, array(), 'Comment');597 LIMIT {$min}," . $this->import_batch, array(), 'Comment'); 597 598 598 599 $comment_map = DB::get_column("SELECT value FROM " . DB::table('commentinfo') . " WHERE name='mt_trackback_id';"); … … 638 639 639 640 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')); 641 642 $trackbackindex++; 642 643 } else { … … 675 676 676 677 /** 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 /** 677 715 * Attempt to connect to the Movable Type database 678 716 *
