From f5592bcc32caa88c0210c51f1f24f3cc1d22731d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 6 May 2012 20:54:58 +0200 Subject: [PATCH] Fix: Removed warning and fix pb with extra fields. --- htdocs/install/repair.php | 64 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 4935047e63c44..cf6a5a830fb32 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -25,6 +25,7 @@ include_once("./inc.php"); if (file_exists($conffile)) include_once($conffile); require_once($dolibarr_main_document_root."/core/lib/admin.lib.php"); +require_once($dolibarr_main_document_root."/core/class/extrafields.class.php"); $grant_query=''; @@ -189,6 +190,67 @@ } } + +// Search list of fields declared and list of fields created into databases and create fields missing +$extrafields=new ExtraFields($db); +$listofmodulesextra=array('societe'=>'company','adherent'=>'member','product'=>'product'); +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 $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 = 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]=$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." -> "; + $field_desc=array( + 'type'=>'varchar', + 'value'=>'', + 'attribute'=>'', + 'default'=>'', + 'extra'=>'', + 'null'=>'null' + ); + + $result=$db->DDLAddField($tableextra,$code,$field_desc,""); + if ($result < 0) + { + print "KO ".$db->lasterror."
\n"; + } + else + { + print "OK
\n"; + } + } + } + + print " \n"; + } +} + + // Run purge of directory if (GETPOST('purge')) { @@ -198,7 +260,7 @@ foreach ($listmodulepart as $modulepart) { $filearray=array(); - $upload_dir = $conf->$modulepart->dir_output; + $upload_dir = isset($conf->$modulepart->dir_output)?$conf->$modulepart->dir_output:''; if ($modulepart == 'company') $upload_dir = $conf->societe->dir_output; // TODO change for multicompany sharing if ($modulepart == 'invoice') $upload_dir = $conf->facture->dir_output; if ($modulepart == 'invoice_supplier') $upload_dir = $conf->fournisseur->facture->dir_output;