Changeset 727156
- Timestamp:
- 06/16/2013 04:49:16 PM (13 years ago)
- Location:
- wp-hatena-notation/trunk/WP/Hatena/Notation
- Files:
-
- 3 added
- 1 edited
-
Migration (added)
-
Migration.php (modified) (2 diffs)
-
Migration/2_0_0.php (added)
-
Migration/Interface.php (added)
Legend:
- Unmodified
- Added
- Removed
-
wp-hatena-notation/trunk/WP/Hatena/Notation/Migration.php
r707962 r727156 1 1 <?php 2 require_once dirname(__FILE__) . '/Migration/Interface.php'; 3 2 4 class WP_Hatena_Notation_Migration { 5 /** 6 * Migration version number 7 */ 8 const VERSION = '2.0.0'; 9 10 /** 11 * Migration version name 12 */ 13 const VERSION_NAME = 'hatena-notation-migrations'; 14 3 15 /** 4 16 * Legacy option name … … 19 31 */ 20 32 public static function migrate(WP_Hatena_Notation $context) { 21 self::legacyOptions($context); 22 self::linkTitle(); 33 $version = get_option(self::VERSION_NAME, '1.4'); 34 $versions = self::getVersions(); 35 $migrated = false; 36 37 foreach ($versions as $info) { 38 if ($version <= $info['version']) { 39 require_once $info['path']; 40 call_user_func(array($info['class'], 'migrate'), $context); 41 $migrated = true; 42 } 43 } 44 45 if ($migrated) { 46 update_option(self::VERSION_NAME, self::VERSION); 47 } 23 48 } 24 49 25 /** 26 * Legacy options 27 * 28 * @param WP_Hatena_Notation $context 29 */ 30 public static function legacyOptions(WP_Hatena_Notation $context) { 31 $options = get_option(self::LEGACY_OPTION_NAME); 50 public static function getVersions() { 51 $files = glob(dirname(__FILE__) . '/Migration/*.php'); 52 $versions = array(); 32 53 33 if (!$options) { 34 return; 54 foreach ($files as $file) { 55 $version = basename($file, '.php'); 56 if ($version !== 'Interface') { 57 $versions[] = array( 58 'version' => str_replace('_', '.', $version), 59 'path' => $file, 60 'class' => __CLASS__ . '_' . $version 61 ); 62 } 35 63 } 36 64 37 delete_option(self::LEGACY_OPTION_NAME); 38 39 $context->option('Renderer.headerlevel', $options['headerlevel']); 40 $context->option('Renderer.link_target_blank', $options['target_blank']); 41 $context->option('Renderer.title_expires', $options['title_term']); 42 $context->option('Renderer.superpre_method', 'html'); 43 $context->option('Renderer.superpre_html', $options['spremarkup']); 44 $context->option('Renderer.linebreak_method', $options['wp_paragraph'] ? 'wordpress' : 'wpautop'); 45 $context->option('Renderer.footnote_html', sprintf('<div class="%s">%s%s%s</div>', $options['footnoteclass'], PHP_EOL, '%content%', PHP_EOL)); 46 47 if ($options['wrap_section']) { 48 $context->option('Renderer.textbody_html', sprintf('<div class="%s">%s%s%s</div>', $options['sectionclass'], PHP_EOL, '%content%', PHP_EOL)); 49 } else { 50 $context->option('Renderer.textbody_html', '%content%'); 51 } 52 53 self::legacyEnabler($context, $options['after_enable_date']); 54 } 55 56 /** 57 * Legacy enabler 58 * 59 * after_enable_date in legacy option 60 * 61 * @param WP_Hatena_Notation $context 62 * @param string $date 63 */ 64 public static function legacyEnabler(WP_Hatena_Notation $context, $date) { 65 if (!$date) { 66 return; 67 } 68 69 $filter = create_function('$where', 'return "$where AND post_date <= \'' . $date . '\'";'); 70 71 add_filter('posts_where', $filter); 72 $posts = get_posts(array('suppress_filters' => false)); 73 remove_filter('posts_where', $filter); 74 75 foreach ($posts as $post) { 76 $context->enabled($post->ID, 0); 77 } 78 79 $context->option('Config.per_post', true); 80 } 81 82 /** 83 * Migrate LinkTitle 84 * 85 * @global wpdb $wpdb 86 */ 87 public static function linkTitle() { 88 self::legacyLinkTitle(); 89 WP_Hatena_Notation_LinkTitle::getInstance()->create(); 90 } 91 92 /** 93 * Legacy LinkTitle 94 */ 95 public static function legacyLinkTitle() { 96 global $wpdb; 97 $tableName = $wpdb->prefix . self::LEGACY_LINK_TITLE_TABLE_NAME; 98 $wpdb->query("DROP TABLE IF EXISTS `$tableName`;"); 65 return $versions; 99 66 } 100 67 }
Note: See TracChangeset
for help on using the changeset viewer.