New: Can fix some fatal errors with a repair script.

This commit is contained in:
Laurent Destailleur 2009-06-15 18:16:22 +00:00
parent b96f501799
commit 70c4f0bd93
4 changed files with 167 additions and 128 deletions

View File

@ -42,6 +42,7 @@ For developers:
- Updated wiki documentation. - Updated wiki documentation.
- Better W3C standard. - Better W3C standard.
- Can add data provided with a module. - Can add data provided with a module.
- Can fix some corruptions in database by calling the update page with action=repair
***** Changelog for 2.6 compared to 2.5 ***** ***** Changelog for 2.6 compared to 2.5 *****

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -19,9 +19,10 @@
*/ */
/** /**
\file htdocs/install/upgrade.php * \file htdocs/install/upgrade.php
\brief Run migration script * \brief Run migration script
\version $Id$ * \version $Id$
* \remarks Can be also called directly with http://mydolibarr/install/upgrade.php?action=repair
*/ */
include_once("./inc.php"); include_once("./inc.php");
@ -60,14 +61,22 @@ dolibarr_install_syslog("upgrade: Entering upgrade.php page");
if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initialized",LOG_ERR); if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initialized",LOG_ERR);
/*
* View
*/
pHeader($langs->trans("DatabaseMigration"),"upgrade2","upgrade"); pHeader($langs->trans("DatabaseMigration"),"upgrade2","upgrade");
$actiondone=0;
if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") // Action to launch the repair or migrate script
if (! isset($_GET["action"]) || $_GET["action"] == "upgrade" || $_GET["action"] == "repair")
{ {
$actiondone=1;
print '<h3>'.$langs->trans("DatabaseMigration").'<h3>'; print '<h3>'.$langs->trans("DatabaseMigration").'<h3>';
if (! $versionfrom && ! $versionto) if ($_GET["action"] != "repair" && ! $versionfrom && ! $versionto)
{ {
print '<div class="error">Parameter versionfrom or version to missing.</div>'; print '<div class="error">Parameter versionfrom or version to missing.</div>';
exit; exit;
@ -138,7 +147,12 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>'; print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>';
flush(); flush();
// Delete duplicates in table categorie_association
if ($_GET["action"] != "repair")
{
/*
* Delete duplicates in table categorie_association
*/
$couples=array(); $couples=array();
$filles=array(); $filles=array();
$sql = "SELECT fk_categorie_mere, fk_categorie_fille"; $sql = "SELECT fk_categorie_mere, fk_categorie_fille";
@ -203,7 +217,9 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
print '<div class="error">'.$langs->trans("Error").'</div>'; print '<div class="error">'.$langs->trans("Error").'</div>';
} }
/*
* Remove deprecated indexes and constraints
*/
if ($ok) if ($ok)
{ {
$versioncommande=split('\.','4.0'); $versioncommande=split('\.','4.0');
@ -257,12 +273,11 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
} }
} }
} }
}
/*************************************************************************************** /*
* * Load sql files
* Chargement fichiers dans migration */
*
***************************************************************************************/
if ($ok) if ($ok)
{ {
if ($choix==1) $dir = "../../mysql/migration/"; if ($choix==1) $dir = "../../mysql/migration/";
@ -284,7 +299,9 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
} }
sort($filesindir); sort($filesindir);
# Determine les fichiers sql a passer # Define which file to run
if ($_GET["action"] != "repair")
{
foreach($filesindir as $file) foreach($filesindir as $file)
{ {
if (eregi($from,$file)) if (eregi($from,$file))
@ -296,6 +313,17 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
$filelist[]=$file; $filelist[]=$file;
} }
} }
}
else
{
foreach($filesindir as $file)
{
if (eregi('repair',$file))
{
$filelist[]=$file;
}
}
}
# Boucle sur chaque fichier # Boucle sur chaque fichier
foreach($filelist as $file) foreach($filelist as $file)
@ -314,7 +342,9 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
if ($db->connected) $db->close(); if ($db->connected) $db->close();
} }
else
if (empty($actiondone))
{ {
print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>'; print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>';
} }

View File

@ -172,8 +172,3 @@ alter table llx_commande_fournisseur add column ref_supplier varchar(30
alter table llx_mailing add column bgcolor varchar(8) after body; alter table llx_mailing add column bgcolor varchar(8) after body;
alter table llx_mailing add column bgimage varchar(255) after bgcolor; alter table llx_mailing add column bgimage varchar(255) after bgcolor;
-- Request to clean corrupted database
delete from llx_facture where facnumber = '(PROV)';
delete from llx_commande where ref = '(PROV)';
delete from llx_propal where ref = '(PROV)';

View File

@ -0,0 +1,13 @@
--
-- $Id$
--
-- Script to repair some fatal errors due to database corruption
--
-- when current version is 2.6.0 or higher.
--
-- Request to clean corrupted database
delete from llx_facture where facnumber = '(PROV)';
delete from llx_commande where ref = '(PROV)';
delete from llx_propal where ref = '(PROV)';