1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

Upgrade from 0.7.x to 0.8 now leaves a clean error-free table-structure.

This commit is contained in:
CaMer0n 2011-06-15 05:41:06 +00:00
parent 1e2aba1770
commit 2475e1f5aa
3 changed files with 232 additions and 119 deletions

View File

@ -278,28 +278,33 @@ function update_706_to_800($type='')
// List of DB tables newly required (defined in core_sql.php) (The existing dblog table gets renamed)
$new_tables = array('admin_log', 'audit_log', 'dblog', 'news_rewrite', 'core_media', 'mail_recipients', 'mail_content');
// No Longer required. - automatically checked against core_sql.php.
// $new_tables = array('audit_log', 'dblog', 'news_rewrite', 'core_media', 'core_media_cat','cron', 'mail_recipients', 'mail_content');
// List of core prefs that need to be converted from serialized to e107ArrayStorage.
$serialized_prefs = array("'emote'", "'menu_pref'", "'search_prefs'", "'emote_default'");
// List of changed DB tables (defined in core_sql.php)
// No Longer required. - automatically checked against core_sql.php.
// (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster)
$changed_tables = array('user', 'dblog', 'admin_log', 'userclass_classes', 'banlist', 'menus',
'plugin', 'news', 'news_category', 'online', 'page', 'links', 'comments');
// $changed_tables = array('user', 'dblog', 'admin_log', 'userclass_classes', 'banlist', 'menus',
// 'plugin', 'news', 'news_category', 'online', 'page', 'links', 'comments');
// List of changed DB tables from core plugins (defined in pluginname_sql.php file)
// key = plugin directory name. Data = comma-separated list of tables to check
// (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster)
$pluginChangedTables = array('linkwords' => 'linkwords',
// No Longer required. - automatically checked by db-verify
/* $pluginChangedTables = array('linkwords' => 'linkwords',
'featurebox' => 'featurebox',
'links_page' => 'links_page',
'poll' => 'polls',
'content' => 'pcontent'
);
*/
$setCorePrefs = array( //modified prefs during upgrade.
'adminstyle' => 'infopanel',
'admintheme' => 'jayya'
@ -573,31 +578,34 @@ function update_706_to_800($type='')
// Add index to download history
if (FALSE !== ($temp = addIndexToTable('download_requests', 'download_request_datestamp', $just_check, $updateMessages)))
{
if ($just_check)
{
return update_needed($temp);
}
}
// Deprecated by db-verify-class
// if (FALSE !== ($temp = addIndexToTable('download_requests', 'download_request_datestamp', $just_check, $updateMessages)))
// {
// if ($just_check)
// {
// return update_needed($temp);
// }
// }
// Extra index to tmp table
if (FALSE !== ($temp = addIndexToTable('tmp', 'tmp_time', $just_check, $updateMessages)))
{
if ($just_check)
{
return update_needed($temp);
}
}
// Deprecated by db-verify-class
// if (FALSE !== ($temp = addIndexToTable('tmp', 'tmp_time', $just_check, $updateMessages)))
// {
// if ($just_check)
// {
// return update_needed($temp);
// }
// }
// Extra index to rss table (if used)
if (FALSE !== ($temp = addIndexToTable('rss', 'rss_name', $just_check, $updateMessages, TRUE)))
{
if ($just_check)
{
return update_needed($temp);
}
}
// Deprecated by db-verify-class
// if (FALSE !== ($temp = addIndexToTable('rss', 'rss_name', $just_check, $updateMessages, TRUE)))
// {
// if ($just_check)
// {
// return update_needed($temp);
// }
// }
// Front page prefs (logic has changed)
if (!isset($pref['frontpage_force']))
@ -610,6 +618,9 @@ function update_706_to_800($type='')
$do_save = TRUE;
}
/*
* Deprecated by db-verify-class
*
if ($sql->db_Table_exists('newsfeed'))
{ // Need to extend field newsfeed_url varchar(250) NOT NULL default ''
@ -627,7 +638,6 @@ function update_706_to_800($type='')
}
}
//TODO use generic function for this update.
if ($sql->db_Table_exists('download'))
{ // Need to extend field download_url varchar(255) NOT NULL default ''
@ -662,7 +672,7 @@ function update_706_to_800($type='')
}
}
*/
// Check need for user timezone before we delete the field
if (varsettrue($pref['signup_option_timezone']))
{
@ -681,7 +691,7 @@ function update_706_to_800($type='')
}
// Tables defined in core_sql.php
// Tables defined in core_sql.php to be RENAMED.
//---------------------------------
if ($sql->db_Table_exists('dblog') && !$sql->db_Table_exists('admin_log'))
{
@ -704,6 +714,8 @@ function update_706_to_800($type='')
}
// New tables required (list at top. Definitions in core_sql.php)
// ALL DEPRECATED by db_verify class.. see below.
/*
foreach ($new_tables as $nt)
{
if (!$sql->db_Table_exists($nt))
@ -727,6 +739,7 @@ function update_706_to_800($type='')
}
// Tables whose definition needs changing significantly
$debugLevel = E107_DBG_SQLDETAILS;
@ -843,16 +856,7 @@ function update_706_to_800($type='')
}
}
// This has to be done after the table is upgraded
if($sql->db_Select('plugin', 'plugin_category', "plugin_category = ''"))
{
if ($just_check) return update_needed('Update plugin table');
require_once(e_HANDLER.'plugin_class.php');
$ep = new e107plugin;
$ep -> update_plugins_table();
// $_pdateMessages[] = LAN_UPDATE_XX24;
// catch_error($sql);
}
*/
// Obsolete tables (list at top)
@ -935,6 +939,40 @@ function update_706_to_800($type='')
}
/* -------------- Upgrade Entire Table Structure - Multi-Language Supported ----------------- */
require_once(e_HANDLER."db_verify_class.php");
$dbv = new db_verify;
$dbv->compareAll(); // core & plugins
if(count($dbv->errors))
{
if ($just_check) return update_needed("Database Tables require updating.");
}
$dbv->compileResults();
// print_a($dbv->results);
// print_a($dbv->fixList);
$dbv->runFix(); // Fix entire core database structure.
//TODO - send notification messages to Log.
// ------------------- Populate Plugin Table With Changes ------------------
// This has to be done after the table is upgraded
if($sql->db_Select('plugin', 'plugin_category', "plugin_category = ''"))
{
if ($just_check) return update_needed('Update plugin table');
require_once(e_HANDLER.'plugin_class.php');
$ep = new e107plugin;
$ep -> update_plugins_table();
// $_pdateMessages[] = LAN_UPDATE_XX24;
// catch_error($sql);
}
//-- Media-manger import --------------------------------------------------
$med = e107::getMedia();
@ -1005,6 +1043,7 @@ function update_706_to_800($type='')
return $just_check;
}
/* No Longed Used I think
function core_media_import($cat,$epath)
{
if(!vartrue($cat)){ return;}
@ -1053,7 +1092,7 @@ function core_media_import($cat,$epath)
}
}
}
*/
function update_70x_to_706($type='')
{

View File

@ -25,6 +25,9 @@
Note: there are some uncommented 'echo' statements which are intentional to highlight that something's gone wrong! (not that it should, of course)
*/
// DEPRECATED - USE db_verify_class where possible.
class db_table_admin
{
var $file_buffer = ''; // Contents of a file

View File

@ -27,6 +27,7 @@ class db_verify
var $sqlLanguageTables = array();
var $results = array();
var $indices = array(); // array(0) - Issue?
var $fixList = array();
var $fieldTypes = array('time','timestamp','datetime','year','tinyblob','blob',
'mediumblob','longblob','tinytext','mediumtext','longtext','text','date');
@ -34,6 +35,14 @@ class db_verify
var $fieldTypeNum = array('bit','tinyint','smallint','mediumint','integer','int','bigint',
'real','double','float','decimal','numeric','varchar','char','binary','varbinary','enum','set');
var $modes = array(
'missing_table' => 'create',
'mismatch' => 'alter',
'missing_field' => 'insert',
'missing_index' => 'index',
'mismatch_index' => '', // TODO
);
/**
* Setup
*/
@ -88,7 +97,7 @@ class db_verify
{
if(isset($_POST['runfix']))
{
$this->runFix();
$this->runFix($_POST['fix']);
}
@ -141,6 +150,30 @@ class db_verify
// print_a($match[2]);
// echo "<pre>".$sql_data."</pre>";
/**
* Check core tables and installed plugin tables
*/
function compareAll()
{
$dtables = array_keys($this->tables);
foreach($dtables as $tb)
{
$this->compare($tb);
}
foreach($this->sqlLanguageTables as $lng=>$lantab) // language tables.
{
foreach($dtables as $tb)
{
$this->compare($tb,$lng);
}
}
}
function compare($selection,$language='')
{
@ -276,6 +309,46 @@ class db_verify
}
/**
* Compile Results into a complete list of Fixes that could be run without the need of a form selection.
*/
function compileResults()
{
foreach($this->results as $tabs => $field)
{
$file = $this->results[$tabs]['_file'];
if($this->errors[$tabs]['_status'] == 'missing_table') // Missing Table
{
$this->fixList[$file][$tabs]['all'][] = 'create';
}
elseif($this->errors[$tabs] != 'ok') // All Other Issues..
{
foreach($field as $k=>$f)
{
if($f['_status']=='ok') continue;
$this->fixList[$f['_file']][$tabs][$k][] = $this->modes[$f['_status']];
}
}
}
// Index
if(count($this->indices))
{
foreach($this->indices as $tabs => $field)
{
if($this->errors[$tabs] != 'ok')
{
foreach($field as $k=>$f)
{
if($f['_status']=='ok') continue;
$this->fixList[$f['_file']][$tabs][$k][] = $this->modes[$f['_status']];
}
}
}
}
}
function renderResults()
{
@ -317,13 +390,6 @@ class db_verify
'missing_index' => DBVLAN_25,
);
$modes = array(
'missing_table' => 'create',
'mismatch' => 'alter',
'missing_field' => 'insert',
'missing_index' => 'index',
'mismatch_index' => '', // TODO
);
foreach($this->results as $tabs => $field)
{
@ -354,7 +420,7 @@ class db_verify
<td>".$k."&nbsp;</td>
<td class='center middle error'>".$fstat."</td>
<td>".$this->renderNotes($f)."&nbsp;</td>
<td class='center middle autocheck e-pointer'>".$this->fixForm($f['_file'],$tabs, $k, $f['_valid'], $modes[$f['_status']]) . "</td>
<td class='center middle autocheck e-pointer'>".$this->fixForm($f['_file'],$tabs, $k, $f['_valid'], $this->modes[$f['_status']]) . "</td>
</tr>
";
}
@ -385,7 +451,7 @@ class db_verify
<td>".$k."&nbsp;</td>
<td class='center middle error'>".$fstat."</td>
<td>".$this->renderNotes($f,'index')."&nbsp;</td>
<td class='center middle autocheck e-pointer'>".$this->fixForm($f['_file'],$tabs, $k, $f['_valid'], $modes[$f['_status']]) . "</td>
<td class='center middle autocheck e-pointer'>".$this->fixForm($f['_file'],$tabs, $k, $f['_valid'], $this->modes[$f['_status']]) . "</td>
</tr>
";
}
@ -431,7 +497,7 @@ class db_verify
function fixForm($file,$table,$field, $newvalue,$mode,$after ='')
{
$frm = e107::getForm();
$text .= $frm->checkbox("fix[$file][$table][$field]", $mode, false, array('id'=>false));
$text .= $frm->checkbox("fix[$file][$table][$field][]", $mode, false, array('id'=>false));
return $text;
}
@ -530,16 +596,19 @@ class db_verify
/**
* Fix tables
* FixArray eg. [core][table][field] = alter|create|index| etc.
*/
function runFix()
function runFix($fixArray='')
{
$mes = e107::getMessage();
if(!is_array($fixArray))
{
$fixArray = $this->fixList; // Fix All
}
foreach($_POST['fix'] as $j=>$file)
foreach($fixArray as $j=>$file)
{
foreach($file as $table=>$val)
@ -547,9 +616,10 @@ class db_verify
$id = $this->getId($this->tables[$j]['tables'],$table);
foreach($val as $field=>$mode)
foreach($val as $field=>$fixes)
{
foreach($fixes as $mode)
{
if(substr($mode,0,5)== 'index')
{
$fdata = $this->getIndex($this->tables[$j]['data'][$id]);
@ -609,6 +679,7 @@ class db_verify
}
}
}
}
} //
}
@ -739,7 +810,7 @@ class db_verify
}
$prefix .= "lan_".$language."_";
$mes->addDebug("<h2>Retrieving Language Table Data: ".$prefix . $tbl."</h2>");
// $mes->addDebug("<h2>Retrieving Language Table Data: ".$prefix . $tbl."</h2>");
}
mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');