From 69f38173a7a533adf901d8dbaac5db2264d040b1 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 26 Jan 2010 14:08:59 +0000 Subject: [PATCH] Works on enhancement of project tasks Fix: data migration field fk_user_resp of llx_projet to llx_element_contact --- htdocs/install/mysql/tables/llx_projet.sql | 1 - .../mysql/tables/llx_projet_task_actors.sql | 28 ---- htdocs/install/upgrade2.php | 122 ++++++++++++++---- htdocs/langs/en_US/install.lang | 5 +- htdocs/langs/fr_FR/install.lang | 3 + 5 files changed, 101 insertions(+), 58 deletions(-) delete mode 100644 htdocs/install/mysql/tables/llx_projet_task_actors.sql diff --git a/htdocs/install/mysql/tables/llx_projet.sql b/htdocs/install/mysql/tables/llx_projet.sql index 24d1ec2d324..40fa87df98b 100644 --- a/htdocs/install/mysql/tables/llx_projet.sql +++ b/htdocs/install/mysql/tables/llx_projet.sql @@ -30,7 +30,6 @@ create table llx_projet ref varchar(50), entity integer DEFAULT 1 NOT NULL, -- multi company id title varchar(255), - fk_user_resp integer, -- responsable du projet fk_user_creat integer, -- createur du projet note text, model_pdf varchar(50) diff --git a/htdocs/install/mysql/tables/llx_projet_task_actors.sql b/htdocs/install/mysql/tables/llx_projet_task_actors.sql deleted file mode 100644 index 017a227d1c0..00000000000 --- a/htdocs/install/mysql/tables/llx_projet_task_actors.sql +++ /dev/null @@ -1,28 +0,0 @@ --- =========================================================================== --- Copyright (C) 2005 Rodolphe Quiedeville --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation; either version 2 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --- --- $Id$ --- =========================================================================== - -create table llx_projet_task_actors -( - fk_projet_task integer NOT NULL, - fk_user integer NOT NULL, - role varchar(5) DEFAULT 'admin', - - UNIQUE (fk_projet_task, fk_user) -)type=innodb; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 5d1ea45fa13..3cb5bb10d1a 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -257,6 +257,8 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) migrate_relationship_tables($db,$langs,$conf,'co_fa','fk_commande','commande','fk_facture','facture'); + migrate_project_user_resp($db,$langs,$conf); + migrate_project_task_actors($db,$langs,$conf); } @@ -279,8 +281,6 @@ else pFooter($error,$setuplang); - - /** * Reporte liens vers une facture de paiements sur table de jointure (lien n-n paiements factures) */ @@ -367,7 +367,6 @@ function migrate_paiements($db,$langs,$conf) print ''; } - /** * Corrige paiement orphelins (liens paumes suite a bugs) * Pour verifier s'il reste des orphelins: @@ -488,7 +487,6 @@ function migrate_paiements_orphelins_1($db,$langs,$conf) print ''; } - /** * Corrige paiement orphelins (liens paumes suite a bugs) * Pour verifier s'il reste des orphelins: @@ -627,7 +625,6 @@ function migrate_paiements_orphelins_2($db,$langs,$conf) print ''; } - function migrate_paiements_orphelins_3($db,$langs,$conf) { @@ -641,7 +638,6 @@ function migrate_paiements_orphelins_3($db,$langs,$conf) } - /* * Mise a jour des contrats (gestion du contrat + detail de contrat) */ @@ -735,7 +731,6 @@ function migrate_contracts_det($db,$langs,$conf) print ''; } - function migrate_links_transfert($db,$langs,$conf) { print ''; @@ -812,7 +807,6 @@ function migrate_links_transfert($db,$langs,$conf) print ''; } - /* * Mise a jour des date de contrats non renseignees */ @@ -844,7 +838,6 @@ function migrate_contracts_date1($db,$langs,$conf) print ''; } - /* * Mise a jour date contrat avec date min effective mise en service si inferieur */ @@ -909,7 +902,6 @@ function migrate_contracts_date2($db,$langs,$conf) print ''; } - /* * Mise a jour des dates de creation de contrat */ @@ -932,7 +924,6 @@ function migrate_contracts_date3($db,$langs,$conf) print ''; } - /* * Reouverture des contrats qui ont au moins une ligne non fermee */ @@ -987,7 +978,6 @@ function migrate_contracts_open($db,$langs,$conf) print ''; } - /** * Factures fournisseurs */ @@ -1100,8 +1090,6 @@ function migrate_paiementfourn_facturefourn($db,$langs,$conf) } } - - /* * Mise a jour des totaux lignes de facture */ @@ -1211,7 +1199,6 @@ function migrate_price_facture($db,$langs,$conf) print ''; } - /* * Mise a jour des totaux lignes de propal */ @@ -1315,8 +1302,6 @@ function migrate_price_propal($db,$langs,$conf) print ''; } - - /* * Mise a jour des totaux lignes de propal */ @@ -1421,7 +1406,6 @@ function migrate_price_contrat($db,$langs,$conf) print ''; } - /* * Mise a jour des totaux lignes de commande */ @@ -1534,7 +1518,6 @@ function migrate_price_commande($db,$langs,$conf) print ''; } - /* * Mise a jour des totaux lignes de commande fournisseur */ @@ -1647,7 +1630,6 @@ function migrate_price_commande_fournisseur($db,$langs,$conf) print ''; } - /* * Mise a jour des modeles selectionnes */ @@ -1826,8 +1808,6 @@ function migrate_commande_expedition($db,$langs,$conf) if ($num) { - $db->begin(); - while ($i < $num) { $obj = $db->fetch_object($resql); @@ -2076,8 +2056,6 @@ function migrate_detail_livraison($db,$langs,$conf) print ''; } - - /* * Migration du champ stock dans produits */ @@ -2147,8 +2125,6 @@ function migrate_stocks($db,$langs,$conf) print ''; } - - /* * Migration of menus (use only 1 table instead of 3) */ @@ -2303,7 +2279,6 @@ function migrate_commande_deliveryaddress($db,$langs,$conf) print ''; } - /* * Migration du champ fk_remise_except dans llx_facturedet doit correspondre a * lien dans llx_societe_remise_except vers llx_facturedet @@ -2458,6 +2433,98 @@ function migrate_restore_missing_links($db,$langs,$conf) print ''; } +/* + * Migration du champ fk_user_resp de llx_projet vers llx_element_contact + */ +function migrate_project_user_resp($db,$langs,$conf) +{ + dolibarr_install_syslog("upgrade2::migrate_project_user_resp"); + + print ''; + + print '
'; + print ''.$langs->trans('MigrationProjectUserResp')."
\n"; + + $result = $db->DDLDescTable(MAIN_DB_PREFIX."projet","fk_user_resp"); + $obj = $db->fetch_object($result); + if ($obj) + { + $error = 0; + + $db->begin(); + + $sql = "SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX."projet"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact ("; + $sql2.= "datecreate"; + $sql2.= ", statut"; + $sql2.= ", element_id"; + $sql2.= ", fk_c_type_contact"; + $sql2.= ", fk_socpeople"; + $sql2.= ") VALUES ("; + $sql2.= $db->idate(dol_now()); + $sql2.= ", '4'"; + $sql2.= ", ".$obj->rowid; + $sql2.= ", '160'"; + $sql2.= ", ".$obj->fk_user_resp; + $sql2.= ")"; + + if ($obj->fk_user_resp > 0) + { + $resql2=$db->query($sql2); + if (!$resql2) + { + $error++; + dol_print_error($db); + } + } + print ". "; + + $i++; + } + } + + if ($error == 0) + { + $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."projet DROP COLUMN fk_user_resp"; + if ($db->query($sqlDrop)) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + print ''; +} + /* * Migration de la table llx_projet_task_actors vers llx_element_contact */ @@ -2636,7 +2703,6 @@ function migrate_relationship_tables($db,$langs,$conf,$table,$fk_source,$sourcet print ''; } - /* * Migration directory */ diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 9efbca2c3b1..d92c450c231 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -209,4 +209,7 @@ MigrationMenusDetail=Update dynamic menus tables MigrationDeliveryAddress=Update delivery address in shipments # Migration project task actors -MigrationProjectTaskActors=Data migration for llx_projet_task_actors table \ No newline at end of file +MigrationProjectTaskActors=Data migration for llx_projet_task_actors table + +# Migration project user resp +MigrationProjectUserResp=Data migration field fk_user_resp of llx_projet to llx_element_contact diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang index 18a9e502f30..71d56582693 100644 --- a/htdocs/langs/fr_FR/install.lang +++ b/htdocs/langs/fr_FR/install.lang @@ -212,3 +212,6 @@ MigrationDeliveryAddress=Mise a jour des adresses de livraison dans les bons d'e # Migration project task actors MigrationProjectTaskActors=Migration de la table llx_projet_task_actors + +# Migration project user resp +MigrationProjectUserResp=Migration du champ fk_user_resp de llx_projet vers llx_element_contact