phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] [19076] don't duplicate organisations during upgrade


From: Dave Hall
Subject: [Phpgroupware-cvs] [19076] don't duplicate organisations during upgrade
Date: Mon, 16 Feb 2009 10:38:44 +0000

Revision: 19076
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=19076
Author:   skwashd
Date:     2009-02-16 10:38:43 +0000 (Mon, 16 Feb 2009)

Log Message:
-----------
don't duplicate organisations during upgrade

Modified Paths:
--------------
    branches/Version-0_9_16-branch/phpgwapi/setup/tables_update.inc.php

Modified: branches/Version-0_9_16-branch/phpgwapi/setup/tables_update.inc.php
===================================================================
--- branches/Version-0_9_16-branch/phpgwapi/setup/tables_update.inc.php 
2009-02-16 10:38:06 UTC (rev 19075)
+++ branches/Version-0_9_16-branch/phpgwapi/setup/tables_update.inc.php 
2009-02-16 10:38:43 UTC (rev 19076)
@@ -1256,27 +1256,40 @@
 
                                if($data['org_name'])
                                {
-                                       
$GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_contact 
(owner,access,cat_id,contact_type_id,ab_id) VALUES ("
-                                                   . $data['owner']
-                                                   . "," . 
($data['access']?"'".$data['access']."'":"null") 
-                                                   . "," . 
($data['cat_id']?"'".$data['cat_id']."'":"null")
-                                                   . "," . $contact_type_org
-                                                   . "," . $key 
-                                                   . ')');
+                                       // see if the org exists before 
creating it
+                                       $org_name = 
$GLOBALS['phpgw_setup']->db->db_addslashes(trim($data['org_name']));
+                                       
$GLOBALS['phpgw_setup']->db->query("SELECT org_id FROM phpgw_contact_org WHERE 
name LIKE '{$org_name}'");
+                                       if ( 
$GLOBALS['phpgw_setup']->db->next_record() )
+                                       {
+                                               // got it
+                                               $org_id = (int) 
$GLOBALS['phpgw_setup']->db->f('org_id');
+                                       }
+                                       else
+                                       {
+                                       
+                                               // need to create it
+                                               
$GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_contact 
(owner,access,cat_id,contact_type_id,ab_id) VALUES ("
+                                                               . $data['owner']
+                                                               . "," . 
($data['access']?"'".$data['access']."'":"null") 
+                                                               . "," . 
($data['cat_id']?"'".$data['cat_id']."'":"null")
+                                                               . "," . 
$contact_type_org
+                                                               . "," . $key 
+                                                               . ')');
                                
-                                       $contact_id++;
-                                       $org_id = $contact_id;
+                                               $contact_id++;
+                                               $org_id = $contact_id;
 
-                                       
$GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_contact_org (org_id,name,
-                                       
created_by,modified_by,created_on,modified_on,ab_id) VALUES ("
-                                                   . $org_id
-                                                   . ",'" . 
$GLOBALS['phpgw_setup']->db->db_addslashes($data['org_name']) . "'"
-                                                   . "," . $data['owner']
-                                                   . "," . $data['owner'] 
-                                                   . "," . $time
-                                                   . "," . $time
-                                                   . "," . $key 
-                                                   .')');
+                                               
$GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_contact_org (org_id,name,
+                                               
created_by,modified_by,created_on,modified_on,ab_id) VALUES ("
+                                                               . $org_id
+                                                               . 
",'{$org_name}'"
+                                                               . "," . 
$data['owner']
+                                                               . "," . 
$data['owner'] 
+                                                               . "," . $time
+                                                               . "," . $time
+                                                               . "," . $key 
+                                                               .')');
+                                       }
 
                                        
$GLOBALS['phpgw_setup']->db->query("INSERT INTO phpgw_contact_org_person 
(org_id,person_id, preferred,
                                        created_on,created_by) VALUES (" 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]