Fix: Pb into repair function

This commit is contained in:
Laurent Destailleur 2014-09-24 00:51:36 +02:00
parent 74cba062b4
commit f6445f9cef

View File

@ -132,7 +132,7 @@ if ($ok)
} }
} }
// Affiche version // Show database version
if ($ok) if ($ok)
{ {
$version=$db->getVersion(); $version=$db->getVersion();
@ -143,12 +143,15 @@ if ($ok)
//print '<td align="right">'.join('.',$versionarray).'</td></tr>'; //print '<td align="right">'.join('.',$versionarray).'</td></tr>';
} }
// Force l'affichage de la progression // Show wait message
print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>'; print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>';
flush(); flush();
// Run repair SQL file /* Start action here */
// run_sql: Run repair SQL file
if ($ok) if ($ok)
{ {
$dir = "mysql/migration/"; $dir = "mysql/migration/";
@ -191,86 +194,169 @@ if ($ok)
} }
// Search list of fields declared and list of fields created into databases and create fields missing // sync_extrafields: Search list of fields declared and list of fields created into databases and create fields missing
$extrafields=new ExtraFields($db); if ($ok)
$listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product',
'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture',
'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm',
'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task');
foreach($listofmodulesextra as $tablename => $elementtype)
{ {
// Get list of fields $extrafields=new ExtraFields($db);
$tableextra=MAIN_DB_PREFIX.$tablename.'_extrafields'; $listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product',
'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture',
'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm',
'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task');
foreach($listofmodulesextra as $tablename => $elementtype)
{
// Get list of fields
$tableextra=MAIN_DB_PREFIX.$tablename.'_extrafields';
// Define $arrayoffieldsdesc // Define $arrayoffieldsdesc
$arrayoffieldsdesc=$extrafields->fetch_name_optionals_label($elementtype); $arrayoffieldsdesc=$extrafields->fetch_name_optionals_label($elementtype);
// Define $arrayoffieldsfound // Define $arrayoffieldsfound
$arrayoffieldsfound=array(); $arrayoffieldsfound=array();
$resql=$db->DDLDescTable($tableextra); $resql=$db->DDLDescTable($tableextra);
if ($resql) if ($resql)
{ {
print '<tr><td>Check availability of extra field for '.$tableextra."<br>\n"; print '<tr><td>Check availability of extra field for '.$tableextra."<br>\n";
$i=0; $i=0;
while($obj=$db->fetch_object($resql)) while($obj=$db->fetch_object($resql))
{ {
$fieldname=$fieldtype=''; $fieldname=$fieldtype='';
if (preg_match('/mysql/',$db->type)) if (preg_match('/mysql/',$db->type))
{ {
$fieldname=$obj->Field; $fieldname=$obj->Field;
$fieldtype=$obj->Type; $fieldtype=$obj->Type;
} }
else else
{ {
$fieldname = isset($obj->Key)?$obj->Key:$obj->attname; $fieldname = isset($obj->Key)?$obj->Key:$obj->attname;
$fieldtype = isset($obj->Type)?$obj->Type:'varchar'; $fieldtype = isset($obj->Type)?$obj->Type:'varchar';
} }
if (empty($fieldname)) continue; if (empty($fieldname)) continue;
if (in_array($fieldname,array('rowid','tms','fk_object','import_key'))) continue; if (in_array($fieldname,array('rowid','tms','fk_object','import_key'))) continue;
$arrayoffieldsfound[$fieldname]=array('type'=>$fieldtype); $arrayoffieldsfound[$fieldname]=array('type'=>$fieldtype);
} }
// If it does not match, we create fields // If it does not match, we create fields
foreach($arrayoffieldsdesc as $code => $label) foreach($arrayoffieldsdesc as $code => $label)
{ {
if (! in_array($code,array_keys($arrayoffieldsfound))) if (! in_array($code,array_keys($arrayoffieldsfound)))
{ {
print 'Found field '.$code.' declared into '.MAIN_DB_PREFIX.'extrafields table but not found into desc of table '.$tableextra." -> "; print 'Found field '.$code.' declared into '.MAIN_DB_PREFIX.'extrafields table but not found into desc of table '.$tableextra." -> ";
$type=$extrafields->attribute_type[$code]; $value=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null'; $type=$extrafields->attribute_type[$code]; $value=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null';
$field_desc=array( $field_desc=array(
'type'=>$type, 'type'=>$type,
'value'=>$value, 'value'=>$value,
'attribute'=>$attribute, 'attribute'=>$attribute,
'default'=>$default, 'default'=>$default,
'extra'=>$extra, 'extra'=>$extra,
'null'=>$null 'null'=>$null
); );
//var_dump($field_desc);exit; //var_dump($field_desc);exit;
$result=$db->DDLAddField($tableextra,$code,$field_desc,""); $result=$db->DDLAddField($tableextra,$code,$field_desc,"");
if ($result < 0) if ($result < 0)
{ {
print "KO ".$db->lasterror."<br>\n"; print "KO ".$db->lasterror."<br>\n";
} }
else else
{ {
print "OK<br>\n"; print "OK<br>\n";
} }
} }
} }
print "</td><td>&nbsp;</td></tr>\n"; print "</td><td>&nbsp;</td></tr>\n";
} }
}
} }
// Clean data into ecm_directories table
clean_data_ecm_directories(); // clean_data_ecm_dir: Clean data into ecm_directories table
if ($ok)
{
clean_data_ecm_directories();
}
// Check and clean linked elements
if (GETPOST('clean_linked_elements')) /* From here, actions need a parameter */
// clean_linked_elements: Check and clean linked elements
if ($ok && GETPOST('restore_thirdparties_logos'))
{
//$exts=array('gif','png','jpg');
$ext='';
//foreach($exts as $ext)
//{
$sql="SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX."societe as s ORDER BY s.nom";
$resql=$db->query($sql);
if ($resql)
{
$num=$db->num_rows($resql);
$i=0;
while($i < $num)
{
$obj=$db->fetch_object($resql);
/*
$name=preg_replace('/é/','',$obj->name);
$name=preg_replace('/ /','_',$name);
$name=preg_replace('/\'/','',$name);
*/
$tmp=explode('.',$obj->logo);
$name=$tmp[0];
if (isset($tmp[1])) $ext='.'.$tmp[1];
if (! empty($name))
{
$filetotest=$dolibarr_main_data_root.'/societe/logos/'.$name.$ext;
$filetotestsmall=$dolibarr_main_data_root.'/societe/logos/thumbs/'.$name.$ext;
$exists=dol_is_file($filetotest);
print 'Check thirdparty '.$obj->rowid.' name='.$obj->name.' logo='.$obj->logo.' file '.$filetotest." exists=".$exists."<br>\n";
if ($exists)
{
$filetarget=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/'.$name.$ext;
$filetargetsmall=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs/'.$name.'_small'.$ext;
$existt=dol_is_file($filetarget);
if (! $existt)
{
dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos');
print " &nbsp; &nbsp; &nbsp; -> Copy file ".$filetotest." -> ".$filetarget."<br>\n";
dol_copy($filetotest, $filetarget, '', 0);
}
$existtt=dol_is_file($filetargetsmall);
if (! $existtt)
{
dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs');
print " &nbsp; &nbsp; &nbsp; -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."<br>\n";
dol_copy($filetotestsmall, $filetargetsmall, '', 0);
}
}
}
$i++;
}
}
else
{
$ok=0;
dol_print_error($db);
}
//}
}
// clean_linked_elements: Check and clean linked elements
if ($ok && GETPOST('clean_linked_elements'))
{ {
// propal => order // propal => order
print "</td><td>".checkLinkedElements('propal', 'commande')."</td></tr>\n"; print "</td><td>".checkLinkedElements('propal', 'commande')."</td></tr>\n";
@ -292,8 +378,8 @@ if (GETPOST('clean_linked_elements'))
} }
// Run purge of directory // clean_orphelin_dir: Run purge of directory
if (GETPOST('purge')) if ($ok && GETPOST('clean_orphelin_dir'))
{ {
$conf->setValues($db); $conf->setValues($db);