Advertisement
Guest User

Only reindex / preparse if necessary when upgrading

a guest
May 26th, 2010
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.31 KB | None | 0 0
  1. diff --git a/db_update.php b/db_update.php
  2. index 1afd920..2a5d9c8 100644
  3. --- a/db_update.php
  4. +++ b/db_update.php
  5. @@ -8,7 +8,10 @@
  6.  
  7.  // The FluxBB version this script updates to
  8.  define('UPDATE_TO', '1.4-rc3');
  9. -define('UPDATE_TO_DB_REVISION', 5);
  10. +
  11. +define('UPDATE_TO_DB_REVISION', 6);
  12. +define('UPDATE_TO_SI_REVISION', 1);
  13. +define('UPDATE_TO_PARSER_REVISION', 1);
  14.  
  15.  define('MIN_PHP_VERSION', '4.3.0');
  16.  define('MIN_MYSQL_VERSION', '4.1.2');
  17. @@ -128,7 +131,10 @@ while ($cur_config_item = $db->fetch_row($result))
  18.     $pun_config[$cur_config_item[0]] = $cur_config_item[1];
  19.  
  20.  // Check the database revision and the current version
  21. -if (isset($pun_config['o_database_revision']) && $pun_config['o_database_revision'] >= UPDATE_TO_DB_REVISION && version_compare($pun_config['o_cur_version'], UPDATE_TO, '>='))
  22. +if (isset($pun_config['o_database_revision']) && $pun_config['o_database_revision'] >= UPDATE_TO_DB_REVISION &&
  23. +       isset($pun_config['o_searchindex_revision']) && $pun_config['o_searchindex_revision'] >= UPDATE_TO_SI_REVISION &&
  24. +       isset($pun_config['o_parser_revision']) && $pun_config['o_parser_revision'] >= UPDATE_TO_PARSER_REVISION &&
  25. +       version_compare($pun_config['o_cur_version'], UPDATE_TO, '>='))
  26.     exit('Your database is already as up-to-date as this script can make it.');
  27.  
  28.  $default_style = $pun_config['o_default_style'];
  29. @@ -508,7 +514,11 @@ if (strpos($cur_version, '1.2') === 0)
  30.  
  31.     // Start by updating the database structure
  32.     case 'start':
  33. -       $query_str = '?stage=pre_finish';
  34. +       $query_str = '?stage=preparse_posts';
  35. +
  36. +       // If we don't need to parse the sigs, skip this stage
  37. +       if (isset($pun_config['o_database_revision']) && $pun_config['o_database_revision'] >= UPDATE_TO_DB_REVISION)
  38. +           break;
  39.  
  40.         // Make all email fields VARCHAR(80)
  41.         $db->alter_field('bans', 'email', 'VARCHAR(80)', true) or error('Unable to alter email field', __FILE__, __LINE__, $db->error());
  42. @@ -547,6 +557,14 @@ if (strpos($cur_version, '1.2') === 0)
  43.         if (!array_key_exists('o_database_revision', $pun_config))
  44.             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_database_revision\', \'0\')') or error('Unable to insert config value \'o_database_revision\'', __FILE__, __LINE__, $db->error());
  45.  
  46. +       // Add search index revision number
  47. +       if (!array_key_exists('o_searchindex_revision', $pun_config))
  48. +           $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_searchindex_revision\', \'0\')') or error('Unable to insert config value \'o_searchindex_revision\'', __FILE__, __LINE__, $db->error());
  49. +
  50. +       // Add parser revision number
  51. +       if (!array_key_exists('o_parser_revision', $pun_config))
  52. +           $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_parser_revision\', \'0\')') or error('Unable to insert config value \'o_parser_revision\'', __FILE__, __LINE__, $db->error());
  53. +
  54.         // Add default email setting option
  55.         if (!array_key_exists('o_default_email_setting', $pun_config))
  56.             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_default_email_setting\', \'1\')') or error('Unable to insert config value \'o_default_email_setting\'', __FILE__, __LINE__, $db->error());
  57. @@ -1243,21 +1261,14 @@ if (strpos($cur_version, '1.2') === 0)
  58.         break;
  59.  
  60.  
  61. -   // Check if we need to do any more work
  62. -   case 'pre_finish':
  63. -       $query_str = '?stage=finish';
  64. -
  65. -       // If we are doing a major update we should preparse the posts and reindex everything
  66. -       if (strpos($cur_version, substr(UPDATE_TO, 0, 3)) !== 0)
  67. -           $query_str = '?stage=preparse_posts';
  68. -
  69. -       break;
  70. -
  71. -
  72.     // Preparse posts
  73.     case 'preparse_posts':
  74.         $query_str = '?stage=preparse_sigs';
  75.  
  76. +       // If we don't need to parse the posts, skip this stage
  77. +       if (isset($pun_config['o_parser_revision']) && $pun_config['o_parser_revision'] >= UPDATE_TO_PARSER_REVISION)
  78. +           break;
  79. +
  80.         require PUN_ROOT.'include/parser.php';
  81.  
  82.         // Fetch posts to process this cycle
  83. @@ -1289,6 +1300,10 @@ if (strpos($cur_version, '1.2') === 0)
  84.     case 'preparse_sigs':
  85.         $query_str = '?stage=rebuild_idx';
  86.  
  87. +       // If we don't need to parse the sigs, skip this stage
  88. +       if (isset($pun_config['o_parser_revision']) && $pun_config['o_parser_revision'] >= UPDATE_TO_PARSER_REVISION)
  89. +           break;
  90. +
  91.         require PUN_ROOT.'include/parser.php';
  92.  
  93.         // Fetch users to process this cycle
  94. @@ -1319,6 +1334,10 @@ if (strpos($cur_version, '1.2') === 0)
  95.     case 'rebuild_idx':
  96.         $query_str = '?stage=finish';
  97.  
  98. +       // If we don't need to update the search index, skip this stage
  99. +       if (isset($pun_config['o_searchindex_revision']) && $pun_config['o_searchindex_revision'] >= UPDATE_TO_SI_REVISION)
  100. +           break;
  101. +
  102.         if ($start_at == 0)
  103.         {
  104.             // Truncate the tables just in-case we didn't already (if we are coming directly here without converting the tables)
  105. @@ -1380,6 +1399,12 @@ if (strpos($cur_version, '1.2') === 0)
  106.         // And the database revision number
  107.         $db->query('UPDATE '.$db->prefix.'config SET conf_value = \''.UPDATE_TO_DB_REVISION.'\' WHERE conf_name = \'o_database_revision\'') or error('Unable to update database revision number', __FILE__, __LINE__, $db->error());
  108.  
  109. +       // And the search index revision number
  110. +       $db->query('UPDATE '.$db->prefix.'config SET conf_value = \''.UPDATE_TO_SI_REVISION.'\' WHERE conf_name = \'o_searchindex_revision\'') or error('Unable to update search index revision number', __FILE__, __LINE__, $db->error());
  111. +
  112. +       // And the parser revision number
  113. +       $db->query('UPDATE '.$db->prefix.'config SET conf_value = \''.UPDATE_TO_PARSER_REVISION.'\' WHERE conf_name = \'o_parser_revision\'') or error('Unable to update parser revision number', __FILE__, __LINE__, $db->error());
  114. +
  115.         // This feels like a good time to synchronize the forums
  116.         $result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum IDs', __FILE__, __LINE__, $db->error());
  117.  
  118. diff --git a/include/common.php b/include/common.php
  119. index 46d990f..951f951 100644
  120. --- a/include/common.php
  121. +++ b/include/common.php
  122. @@ -11,7 +11,10 @@ if (!defined('PUN_ROOT'))
  123.  
  124.  // Define the version and database revision that this code was written for
  125.  define('FORUM_VERSION', '1.4-rc3');
  126. -define('FORUM_DB_REVISION', 5);
  127. +
  128. +define('FORUM_DB_REVISION', 6);
  129. +define('FORUM_SI_REVISION', 1);
  130. +define('FORUM_PARSER_REVISION', 1);
  131.  
  132.  // Block prefetch requests
  133.  if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
  134. @@ -113,7 +116,10 @@ if (!defined('PUN_CONFIG_LOADED'))
  135.  }
  136.  
  137.  // Verify that we are running the proper database schema revision
  138. -if (!isset($pun_config['o_database_revision']) || $pun_config['o_database_revision'] < FORUM_DB_REVISION || version_compare($pun_config['o_cur_version'], FORUM_VERSION, '<'))
  139. +if (!isset($pun_config['o_database_revision']) || $pun_config['o_database_revision'] < FORUM_DB_REVISION ||
  140. +       !isset($pun_config['o_searchindex_revision']) || $pun_config['o_searchindex_revision'] < FORUM_SI_REVISION ||
  141. +       !isset($pun_config['o_parser_revision']) || $pun_config['o_parser_revision'] < FORUM_PARSER_REVISION ||
  142. +       version_compare($pun_config['o_cur_version'], FORUM_VERSION, '<'))
  143.     exit('Your FluxBB database is out-of-date and must be upgraded in order to continue. Please run <a href="'.PUN_ROOT.'db_update.php">db_update.php</a> in order to complete the upgrade process.');
  144.  
  145.  // Enable output buffering
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement