diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php
index 47456c21c62..48f4b5a6aa6 100644
--- a/htdocs/install/repair.php
+++ b/htdocs/install/repair.php
@@ -132,7 +132,7 @@ if ($ok)
}
}
-// Affiche version
+// Show database version
if ($ok)
{
$version=$db->getVersion();
@@ -143,12 +143,15 @@ if ($ok)
//print '
'.join('.',$versionarray).' | ';
}
-// Force l'affichage de la progression
+// Show wait message
print '| '.$langs->trans("PleaseBePatient").' |
';
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 'Check availability of extra field for '.$tableextra." \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 ' |
Check availability of extra field for '.$tableextra." \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." \n";
- }
- else
- {
- print "OK \n";
- }
- }
- }
+ $result=$db->DDLAddField($tableextra,$code,$field_desc,"");
+ if ($result < 0)
+ {
+ print "KO ".$db->lasterror." \n";
+ }
+ else
+ {
+ print "OK \n";
+ }
+ }
+ }
- print " | |
\n";
- }
+ print " | \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."
\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."
\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."
\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 "".checkLinkedElements('propal', 'commande')." | \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);