Fix: Removed duplicate records in categorie_association during migration
This commit is contained in:
parent
2f46cda600
commit
0442049531
@ -134,9 +134,75 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Force l'affichage de la progression
|
// Force l'affichage de la progression
|
||||||
print '<tr><td>'.$langs->trans("PleaseBePatient").'</td>';
|
print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>';
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
|
// Delete duplicates in table categorie_association
|
||||||
|
$couples=array();
|
||||||
|
$filles=array();
|
||||||
|
$sql = "SELECT fk_categorie_mere, fk_categorie_fille";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_association";
|
||||||
|
dolibarr_install_syslog("upgrade: search duplicate sql=".$sql);
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num=$db->num_rows($resql);
|
||||||
|
while ($obj=$db->fetch_object($resql))
|
||||||
|
{
|
||||||
|
if (! isset($filles[$obj->fk_categorie_fille])) // Only one record as child (a child has only on parent).
|
||||||
|
{
|
||||||
|
if ($obj->fk_categorie_mere != $obj->fk_categorie_fille)
|
||||||
|
{
|
||||||
|
$filles[$obj->fk_categorie_fille]=1; // Set record for this child
|
||||||
|
$couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille]=array('mere'=>$obj->fk_categorie_mere, 'fille'=>$obj->fk_categorie_fille);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dolibarr_install_syslog("upgrade: result is num=".$num." sizeof(couples)=".sizeof($couples));
|
||||||
|
|
||||||
|
// If there is duplicates couples or child with two parents
|
||||||
|
if (sizeof($couples) > 0 && $num > sizeof($couples))
|
||||||
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
$sql="DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
|
||||||
|
dolibarr_install_syslog("upgrade: delete association sql=".$sql);
|
||||||
|
$resqld=$db->query($sql);
|
||||||
|
if ($resqld)
|
||||||
|
{
|
||||||
|
foreach($couples as $key => $val)
|
||||||
|
{
|
||||||
|
$sql ="INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
|
||||||
|
$sql.=" VALUES(".$val['mere'].", ".$val['fille'].")";
|
||||||
|
dolibarr_install_syslog("upgrade: insert association sql=".$sql);
|
||||||
|
$resqli=$db->query($sql);
|
||||||
|
if (! $resqli) $error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
print '<tr><td>'.$langs->trans("RemoveDuplicates").'</td>';
|
||||||
|
print '<td align="right">'.$langs->trans("Success").' ('.$num.'=>'.sizeof($couples).')</td></tr>';
|
||||||
|
$db->commit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<tr><td>'.$langs->trans("RemoveDuplicates").'</td>';
|
||||||
|
print '<td align="right">'.$langs->trans("Failed").'</td></tr>';
|
||||||
|
$db->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<div class="error">'.$langs->trans("Error").'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($ok)
|
if ($ok)
|
||||||
{
|
{
|
||||||
$versioncommande=split('\.','4.0');
|
$versioncommande=split('\.','4.0');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user