Fix: Pb into repair function
This commit is contained in:
parent
74cba062b4
commit
f6445f9cef
@ -132,7 +132,7 @@ if ($ok)
|
||||
}
|
||||
}
|
||||
|
||||
// Affiche version
|
||||
// Show database version
|
||||
if ($ok)
|
||||
{
|
||||
$version=$db->getVersion();
|
||||
@ -143,12 +143,15 @@ if ($ok)
|
||||
//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>';
|
||||
flush();
|
||||
|
||||
|
||||
// Run repair SQL file
|
||||
/* Start action here */
|
||||
|
||||
|
||||
// run_sql: Run repair SQL file
|
||||
if ($ok)
|
||||
{
|
||||
$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
|
||||
$extrafields=new ExtraFields($db);
|
||||
$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)
|
||||
// sync_extrafields: Search list of fields declared and list of fields created into databases and create fields missing
|
||||
if ($ok)
|
||||
{
|
||||
// Get list of fields
|
||||
$tableextra=MAIN_DB_PREFIX.$tablename.'_extrafields';
|
||||
$extrafields=new ExtraFields($db);
|
||||
$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
|
||||
$arrayoffieldsdesc=$extrafields->fetch_name_optionals_label($elementtype);
|
||||
// Define $arrayoffieldsdesc
|
||||
$arrayoffieldsdesc=$extrafields->fetch_name_optionals_label($elementtype);
|
||||
|
||||
// Define $arrayoffieldsfound
|
||||
$arrayoffieldsfound=array();
|
||||
$resql=$db->DDLDescTable($tableextra);
|
||||
if ($resql)
|
||||
{
|
||||
print '<tr><td>Check availability of extra field for '.$tableextra."<br>\n";
|
||||
$i=0;
|
||||
while($obj=$db->fetch_object($resql))
|
||||
{
|
||||
$fieldname=$fieldtype='';
|
||||
if (preg_match('/mysql/',$db->type))
|
||||
{
|
||||
$fieldname=$obj->Field;
|
||||
$fieldtype=$obj->Type;
|
||||
}
|
||||
else
|
||||
{
|
||||
$fieldname = isset($obj->Key)?$obj->Key:$obj->attname;
|
||||
$fieldtype = isset($obj->Type)?$obj->Type:'varchar';
|
||||
}
|
||||
// Define $arrayoffieldsfound
|
||||
$arrayoffieldsfound=array();
|
||||
$resql=$db->DDLDescTable($tableextra);
|
||||
if ($resql)
|
||||
{
|
||||
print '<tr><td>Check availability of extra field for '.$tableextra."<br>\n";
|
||||
$i=0;
|
||||
while($obj=$db->fetch_object($resql))
|
||||
{
|
||||
$fieldname=$fieldtype='';
|
||||
if (preg_match('/mysql/',$db->type))
|
||||
{
|
||||
$fieldname=$obj->Field;
|
||||
$fieldtype=$obj->Type;
|
||||
}
|
||||
else
|
||||
{
|
||||
$fieldname = isset($obj->Key)?$obj->Key:$obj->attname;
|
||||
$fieldtype = isset($obj->Type)?$obj->Type:'varchar';
|
||||
}
|
||||
|
||||
if (empty($fieldname)) continue;
|
||||
if (in_array($fieldname,array('rowid','tms','fk_object','import_key'))) continue;
|
||||
$arrayoffieldsfound[$fieldname]=array('type'=>$fieldtype);
|
||||
}
|
||||
if (empty($fieldname)) continue;
|
||||
if (in_array($fieldname,array('rowid','tms','fk_object','import_key'))) continue;
|
||||
$arrayoffieldsfound[$fieldname]=array('type'=>$fieldtype);
|
||||
}
|
||||
|
||||
// If it does not match, we create fields
|
||||
foreach($arrayoffieldsdesc as $code => $label)
|
||||
{
|
||||
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." -> ";
|
||||
$type=$extrafields->attribute_type[$code]; $value=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null';
|
||||
$field_desc=array(
|
||||
'type'=>$type,
|
||||
'value'=>$value,
|
||||
'attribute'=>$attribute,
|
||||
'default'=>$default,
|
||||
'extra'=>$extra,
|
||||
'null'=>$null
|
||||
);
|
||||
//var_dump($field_desc);exit;
|
||||
// If it does not match, we create fields
|
||||
foreach($arrayoffieldsdesc as $code => $label)
|
||||
{
|
||||
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." -> ";
|
||||
$type=$extrafields->attribute_type[$code]; $value=$extrafields->attribute_size[$code]; $attribute=''; $default=''; $extra=''; $null='null';
|
||||
$field_desc=array(
|
||||
'type'=>$type,
|
||||
'value'=>$value,
|
||||
'attribute'=>$attribute,
|
||||
'default'=>$default,
|
||||
'extra'=>$extra,
|
||||
'null'=>$null
|
||||
);
|
||||
//var_dump($field_desc);exit;
|
||||
|
||||
$result=$db->DDLAddField($tableextra,$code,$field_desc,"");
|
||||
if ($result < 0)
|
||||
{
|
||||
print "KO ".$db->lasterror."<br>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "OK<br>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$result=$db->DDLAddField($tableextra,$code,$field_desc,"");
|
||||
if ($result < 0)
|
||||
{
|
||||
print "KO ".$db->lasterror."<br>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "OK<br>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print "</td><td> </td></tr>\n";
|
||||
}
|
||||
print "</td><td> </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 " -> 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 " -> 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
|
||||
print "</td><td>".checkLinkedElements('propal', 'commande')."</td></tr>\n";
|
||||
@ -292,8 +378,8 @@ if (GETPOST('clean_linked_elements'))
|
||||
}
|
||||
|
||||
|
||||
// Run purge of directory
|
||||
if (GETPOST('purge'))
|
||||
// clean_orphelin_dir: Run purge of directory
|
||||
if ($ok && GETPOST('clean_orphelin_dir'))
|
||||
{
|
||||
$conf->setValues($db);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user