1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
<?php
/**
* This file implements support functions for the installer
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package install
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
/**
* check_db_version(-)
*
* Note: version number 8000 once meant 0.8.00.0, but I decided to switch to sequential
* increments of 10 (in case we ever need to introduce intermediate versions for intermediate
* bug fixes...)
*/
function check_db_version()
{
global $DB, $old_db_version, $new_db_version, $tablesettings;
echo '<p>'.T_('Checking DB schema version...').' ';
$DB->query( "SELECT * FROM $tablesettings LIMIT 1" );
if( $DB->get_col_info('name', 0) == 'set_name' )
{ // we have new table format
$old_db_version = $DB->get_var( "SELECT set_value FROM $tablesettings WHERE set_name = 'db_version'" );
}
else
{
$old_db_version = $DB->get_var( "SELECT db_version FROM $tablesettings" );
}
if( $old_db_version == NULL ) die( T_('NOT FOUND! This is not a b2evolution database.') );
echo $old_db_version, ' : ';
if( $old_db_version < 8000 ) die( T_('This version is too old!') );
if( $old_db_version > $new_db_version ) die( T_('This version is too recent! We cannot downgrade to it!') );
echo "OK.<br />\n";
}
/**
* Clean up extra quotes in posts
*/
function cleanup_post_quotes()
{
global $DB;
echo "Checking for extra quote escaping in posts... ";
$query = "SELECT ID, post_title, post_content
FROM T_posts
WHERE post_title LIKE '%\\\\\\\\\'%'
OR post_title LIKE '%\\\\\\\\\"%'
OR post_content LIKE '%\\\\\\\\\'%'
OR post_content LIKE '%\\\\\\\\\"%' ";
/* FP: the above looks overkill, but mySQL is really full of surprises...
tested on 4.0.14-nt */
// echo $query;
$rows = $DB->get_results( $query, ARRAY_A );
if( $DB->num_rows )
{
echo 'Updating '.$DB->num_rows.' posts... ';
foreach( $rows as $row )
{
// echo '<br />'.$row['post_title'];
$query = "UPDATE T_posts
SET post_title = ".$DB->quote( stripslashes( $row['post_title'] ) ).",
post_content = ".$DB->quote( stripslashes( $row['post_content'] ) )."
WHERE ID = ".$row['ID'];
// echo '<br />'.$query;
$DB->query( $query );
}
}
echo "OK.<br />\n";
}
/**
* Clean up extra quotes in comments
*/
function cleanup_comment_quotes()
{
global $DB;
echo "Checking for extra quote escaping in comments... ";
$query = "SELECT comment_ID, comment_content
FROM T_comments
WHERE comment_content LIKE '%\\\\\\\\\'%'
OR comment_content LIKE '%\\\\\\\\\"%' ";
/* FP: the above looks overkill, but mySQL is really full of surprises...
tested on 4.0.14-nt */
// echo $query;
$rows = $DB->get_results( $query, ARRAY_A );
if( $DB->num_rows )
{
echo 'Updating '.$DB->num_rows.' comments... ';
foreach( $rows as $row )
{
$query = "UPDATE T_comments
SET comment_content = ".$DB->quote( stripslashes( $row['comment_content'] ) )."
WHERE comment_ID = ".$row['comment_ID'];
// echo '<br />'.$query;
$DB->query( $query );
}
}
echo "OK.<br />\n";
}
?>
|