fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10354] catch/property: add location_id


From: Sigurd Nes
Subject: [Fmsystem-commits] [10354] catch/property: add location_id
Date: Thu, 25 Oct 2012 16:51:34 +0000

Revision: 10354
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10354
Author:   sigurdne
Date:     2012-10-25 16:51:33 +0000 (Thu, 25 Oct 2012)
Log Message:
-----------
catch/property: add location_id

Modified Paths:
--------------
    trunk/catch/setup/setup.inc.php
    trunk/catch/setup/tables_current.inc.php
    trunk/catch/setup/tables_update.inc.php
    trunk/property/inc/class.soadmin_entity.inc.php
    trunk/property/inc/class.soentity.inc.php
    trunk/property/setup/setup.inc.php
    trunk/property/setup/tables_current.inc.php
    trunk/property/setup/tables_update.inc.php

Modified: trunk/catch/setup/setup.inc.php
===================================================================
--- trunk/catch/setup/setup.inc.php     2012-10-25 12:14:13 UTC (rev 10353)
+++ trunk/catch/setup/setup.inc.php     2012-10-25 16:51:33 UTC (rev 10354)
@@ -27,7 +27,7 @@
         */
 
        $setup_info['catch']['name']                    = 'catch';
-       $setup_info['catch']['version']                 = '0.9.17.513';
+       $setup_info['catch']['version']                 = '0.9.17.514';
        $setup_info['catch']['app_order']               = 20;
        $setup_info['catch']['enable']                  = 1;
        $setup_info['catch']['globals_checked'] = True;

Modified: trunk/catch/setup/tables_current.inc.php
===================================================================
--- trunk/catch/setup/tables_current.inc.php    2012-10-25 12:14:13 UTC (rev 
10353)
+++ trunk/catch/setup/tables_current.inc.php    2012-10-25 16:51:33 UTC (rev 
10354)
@@ -29,6 +29,7 @@
        $phpgw_baseline = array(
                'fm_catch' => array(
                        'fd' => array(
+                               'location_id' => array('type' => 
'int','precision' => '4','nullable' => False),
                                'id' => array('type' => 'int','precision' => 
'4','nullable' => False),
                                'name' => array('type' => 'varchar','precision' 
=> '20','nullable' => False),
                                'descr' => array('type' => 
'varchar','precision' => '50','nullable' => True),
@@ -43,6 +44,7 @@
                ),
                'fm_catch_category' => array(
                        'fd' => array(
+                               'location_id' => array('type' => 
'int','precision' => '4','nullable' => False),
                                'entity_id' => array('type' => 
'int','precision' => '4','nullable' => False),
                                'id' => array('type' => 'int','precision' => 
'4','nullable' => False),
                                'name' => array('type' => 'varchar','precision' 
=> '100','nullable' => True),

Modified: trunk/catch/setup/tables_update.inc.php
===================================================================
--- trunk/catch/setup/tables_update.inc.php     2012-10-25 12:14:13 UTC (rev 
10353)
+++ trunk/catch/setup/tables_update.inc.php     2012-10-25 16:51:33 UTC (rev 
10354)
@@ -383,4 +383,83 @@
                }
        }
 
+       /**
+       * Update catch version from 0.9.17.513 to 0.9.17.514
+       * Add location_id to entities
+       */
 
+       $test[] = '0.9.17.513';
+       function catch_upgrade0_9_17_513()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+               
$GLOBALS['phpgw_setup']->oProc->AddColumn('fm_catch','location_id',array(
+                       'type'          => 'int',
+                       'precision'     => 4,
+                       'nullable'      => true
+                       )
+               );
+               
$GLOBALS['phpgw_setup']->oProc->AddColumn('fm_catch_category','location_id',array(
+                       'type'          => 'int',
+                       'precision'     => 4,
+                       'nullable'      => true
+                       )
+               );
+
+               $sql = 'SELECT id, entity_id FROM fm_catch_category';
+               $GLOBALS['phpgw_setup']->oProc->query($sql,__LINE__,__FILE__);
+
+               $categories = array();
+               while ($GLOBALS['phpgw_setup']->oProc->next_record())
+               {
+                       $categories[] = array
+                       (
+                               'entity_id'     => 
$GLOBALS['phpgw_setup']->oProc->f('entity_id'),
+                               'cat_id'        => 
$GLOBALS['phpgw_setup']->oProc->f('id'),
+                       );
+               }
+
+
+               $sql = 'SELECT id FROM fm_catch';
+               $GLOBALS['phpgw_setup']->oProc->query($sql,__LINE__,__FILE__);
+
+               $entities = array();
+               while ($GLOBALS['phpgw_setup']->oProc->next_record())
+               {
+                       $entities[] = array
+                       (
+                               'entity_id'     => 
$GLOBALS['phpgw_setup']->oProc->f('id'),
+                       );
+               }
+
+               foreach ($categories as $category)
+               {
+                       $location_id    = 
$GLOBALS['phpgw']->locations->get_id('catch', 
".catch.{$category['entity_id']}.{$category['cat_id']}");
+                       $GLOBALS['phpgw_setup']->oProc->query("UPDATE 
fm_catch_category SET location_id = {$location_id} WHERE entity_id = 
{$category['entity_id']} AND id = {$category['cat_id']}",__LINE__,__FILE__);
+               }
+
+               foreach ($entities as $entity)
+               {
+                       $location_id    = 
$GLOBALS['phpgw']->locations->get_id('catch', ".catch.{$entity['entity_id']}");
+                       $GLOBALS['phpgw_setup']->oProc->query("UPDATE fm_catch 
SET location_id = {$location_id} WHERE id = 
{$entity['entity_id']}",__LINE__,__FILE__);
+               }
+
+               
$GLOBALS['phpgw_setup']->oProc->AlterColumn('fm_catch','location_id',array(
+                       'type'          => 'int',
+                       'precision'     => 4,
+                       'nullable'      => false
+                       )
+               );
+               
$GLOBALS['phpgw_setup']->oProc->AlterColumn('fm_catch_category','location_id',array(
+                       'type'          => 'int',
+                       'precision'     => 4,
+                       'nullable'      => false
+                       )
+               );
+
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['catch']['currentver'] = 
'0.9.17.514';
+                       return $GLOBALS['setup_info']['catch']['currentver'];
+               }
+       }

Modified: trunk/property/inc/class.soadmin_entity.inc.php
===================================================================
--- trunk/property/inc/class.soadmin_entity.inc.php     2012-10-25 12:14:13 UTC 
(rev 10353)
+++ trunk/property/inc/class.soadmin_entity.inc.php     2012-10-25 16:51:33 UTC 
(rev 10354)
@@ -477,8 +477,10 @@
                        $entity['descr'] = 
$this->db->db_addslashes($entity['descr']);
 
                        $entity['id'] = 
$this->bocommon->next_id("fm_{$this->type}");
+                       $location_id = 
$GLOBALS['phpgw']->locations->add(".{$this->type}." . $entity['id'], 
$entity['name'], $this->type_app[$this->type], true);
 
                        $values= array(
+                               $location_id,
                                $entity['id'],
                                $entity['name'],
                                $entity['descr'],
@@ -488,10 +490,9 @@
 
                        $values = $this->db->validate_insert($values);
 
-                       $this->db->query("INSERT INTO fm_{$this->type} 
(id,name, descr,location_form,documentation) "
+                       $this->db->query("INSERT INTO fm_{$this->type} 
(location_id,id,name, descr,location_form,documentation) "
                                . "VALUES ($values)",__LINE__,__FILE__);
 
-                       $GLOBALS['phpgw']->locations->add(".{$this->type}." . 
$entity['id'], $entity['name'], $this->type_app[$this->type], true);
 
                        $receipt['id']= $entity['id'];
 
@@ -539,6 +540,7 @@
                        $values['descr'] = 
$this->db->db_addslashes($values['descr']);
 
                        $values['id'] = $this->bocommon->next_id($table, 
array('entity_id'=>$values['entity_id']));
+                       $location_id = 
$GLOBALS['phpgw']->locations->add(".{$this->type}.{$values['entity_id']}.{$values['id']}",
 $values['name'],  $this->type_app[$this->type], true);
 
                        if($values['parent_id'])
                        {
@@ -554,6 +556,7 @@
 
                        $values_insert= array
                                (
+                                       $location_id,
                                        $values['entity_id'],
                                        $values['id'],
                                        $values['name'],
@@ -575,7 +578,7 @@
 
                        $values_insert  = 
$this->db->validate_insert($values_insert);
 
-                       $this->db->query("INSERT INTO {$table} 
(entity_id,id,name, 
descr,prefix,lookup_tenant,tracking,location_level,location_link_level,fileupload,loc_link,start_project,start_ticket,is_eav,jasperupload,parent_id,level
 ) "
+                       $this->db->query("INSERT INTO {$table} 
(location_id,entity_id,id,name, 
descr,prefix,lookup_tenant,tracking,location_level,location_link_level,fileupload,loc_link,start_project,start_ticket,is_eav,jasperupload,parent_id,level
 ) "
                                . "VALUES ($values_insert)",__LINE__,__FILE__);
 
 
@@ -583,7 +586,6 @@
 
                        if($values['is_eav']) // if modelles as eav - we are 
good
                        {
-                               $location_id = 
$GLOBALS['phpgw']->locations->add(".{$this->type}.{$values['entity_id']}.{$values['id']}",
 $values['name'],  $this->type_app[$this->type], true);
                                $values_insert = array
                                (
                                        'location_id'   => $location_id,
@@ -603,7 +605,6 @@
                        
                        
                        // if not eav - we need a table to hold the attributes
-                       $location_id = 
$GLOBALS['phpgw']->locations->add(".{$this->type}.{$values['entity_id']}.{$values['id']}",
 $values['name'],  $this->type_app[$this->type], true, 
"fm_{$this->type}_{$values['entity_id']}_{$values['id']}");
                        $this->init_process();
 
                        $fd = $this->get_default_column_def();

Modified: trunk/property/inc/class.soentity.inc.php
===================================================================
--- trunk/property/inc/class.soentity.inc.php   2012-10-25 12:14:13 UTC (rev 
10353)
+++ trunk/property/inc/class.soentity.inc.php   2012-10-25 16:51:33 UTC (rev 
10354)
@@ -157,7 +157,7 @@
                                                $ordermethod = " ORDER BY 
fm_location1.loc1_name {$sort}";  // Don't work with LDAP. 
                                                break;
                                        default:
-                                               $ordermethod = " ORDER BY 
$entity_table.$order $sort";  
+                                               $ordermethod = " ORDER BY 
$entity_table.$order $sort";
                                }
                        }
                        else
@@ -230,7 +230,7 @@
                        $start                  = isset($data['start']) && 
$data['start'] ? (int)$data['start'] : 0;
                        $results                = isset($data['results']) && 
$data['results'] ? (int)$data['results'] : 0;
                        $location_id    = isset($data['location_id']) && 
$data['location_id'] ? (int)$data['location_id'] : 0;
-                       $conditions             = isset($data['conditions']) && 
$data['conditions'] ? $data['conditions'] : array();                    
+                       $conditions             = isset($data['conditions']) && 
$data['conditions'] ? $data['conditions'] : array();
                        $query                  = isset($data['query']) ? 
$data['query'] : '';
                        $allrows                = isset($data['allrows']) ? 
$data['allrows'] : '';
 
@@ -245,7 +245,7 @@
 //                     $__querymethod = array("fm_bim_item.id = -1"); // block 
query waiting for conditions
 
                        $attribute_table = 'phpgw_cust_attribute';
-                       
+
                        foreach ($conditions as $condition)
                        {
                                $this->db->query("SELECT * FROM 
phpgw_cust_attribute WHERE location_id = {$location_id} AND id= " . (int) 
$condition['attribute_id']);
@@ -394,7 +394,7 @@
                                        'datatype'      => false,
                                        'attrib_id'     => false,
                                );
-                                       
+
                        }
 
                        $values = $this->custom->translate_value($dataset, 
$location_id);
@@ -530,19 +530,19 @@
                        if ($location_code)
                        {
                                $filtermethod .= " $where 
$entity_table.location_code $this->like '$location_code%'";
-                               $where= 'AND';                  
+                               $where= 'AND';
                        }
 
                        if ($attrib_filter)
                        {
                                $filtermethod .= " $where " . implode(' AND ', 
$attrib_filter);
-                               $where= 'AND';                  
+                               $where= 'AND';
                        }
 
                        if ($custom_condition)
                        {
                                $filtermethod .= " {$where} 
{$custom_condition}";
-                               $where= 'AND';                  
+                               $where= 'AND';
                        }
 
                        if ($p_num)
@@ -576,7 +576,7 @@
                                        {
                                                $__querymethod = 
array("{$entity_table}.id = -1"); // block query waiting for criteria
                                        }
-                                       //_debug_array($__querymethod);         
                        
+                                       //_debug_array($__querymethod);
 
                                        $this->db->query("SELECT * FROM 
$attribute_table WHERE $attribute_filter AND search='1'");
 
@@ -625,7 +625,7 @@
                                                                        while 
($this->db2->next_record())
                                                                        {
                                                                                
$_querymethod[]= "xmlexists('//" . $this->db->f('column_name') . "[text() = ''" 
. (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
-                                                                       }       
+                                                                       }
                                                                        
$__querymethod = array(); // remove block
                                                                }
                                                                break;
@@ -644,7 +644,7 @@
                                                                        while 
($this->db2->next_record())
                                                                        {
                                                                                
$_querymethod[]= "xmlexists('//" . $this->db->f('column_name') . "[text() = ''" 
. (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
-                                                                       }       
+                                                                       }
 
                                                                        
$__querymethod = array(); // remove block
                                                                }
@@ -657,7 +657,7 @@
                                                                        while 
($this->db2->next_record())
                                                                        {
                                                                                
$_querymethod[]= "xmlexists('//" . $this->db->f('column_name') . "[text() = ''" 
. (int)$this->db2->f('id') . "'']' PASSING BY REF xml_representation)";
-                                                                       }       
+                                                                       }
 
                                                                        
$__querymethod = array(); // remove block
                                                                }
@@ -722,7 +722,7 @@
                        }
 
 //                     $filtermethod .= "AND xmlexists('//location_code[text() 
= ''5002-02'']' PASSING BY REF xml_representation)";
-                       
+
                        $sql .= " $filtermethod $querymethod";
 
                        $_sql = str_replace('__XML-ORDER__', '', $sql);
@@ -733,7 +733,7 @@
                        {
                                $cache_info = array();
                        }
-//_debug_array($_sql);die();                   
+//_debug_array($_sql);die();
 //                     if(!$cache_info)
                        {
                                $sql_cnt = "SELECT DISTINCT fm_bim_item.id 
{$sql_cnt_control_fields}" . substr($_sql,strripos($_sql,'FROM'));
@@ -799,7 +799,7 @@
                        }
 
                        $j=0;
-                       
+
                        $uicols = $this->uicols;
                        $cols_return = $uicols['name'];
                        $dataset = array();
@@ -872,7 +872,7 @@
                                                        'attrib_id'     => false
                                                );
                                }
-                               $j++;                           
+                               $j++;
                        }
 
                        $values = $this->custom->translate_value($dataset, 
$location_id);
@@ -1037,7 +1037,7 @@
                                //-------------------
 
                                $user_columns = 
isset($GLOBALS['phpgw_info']['user']['preferences'][$this->type_app[$this->type]]['entity_columns_'.$entity_id.'_'.$cat_id])?$GLOBALS['phpgw_info']['user']['preferences'][$this->type_app[$this->type]]['entity_columns_'.$entity_id.'_'.$cat_id]:array();
-                               
+
                                $_user_columns = array();
                                foreach ($user_columns as $user_column_id)
                                {
@@ -1075,7 +1075,7 @@
                                                (
                                                        'name'  => 
$this->db->f('column_name'),
                                                        'datatype'      => 
$this->db->f('datatype'),
-                                                       'attrib_id'     => 
$this->db->f('id')                                   
+                                                       'attrib_id'     => 
$this->db->f('id')
                                                );
 
                                        $i++;
@@ -1097,7 +1097,7 @@
                                                'datatype'      => 'timestamp',
                                        );
                        }
-       
+
                }
 
 
@@ -1181,7 +1181,7 @@
                                                $ordermethod = " ORDER BY 
fm_location1.loc1_name {$sort}";  // Don't work with LDAP. 
                                                break;
                                        default:
-                                               $ordermethod = " ORDER BY 
$entity_table.$order $sort";  
+                                               $ordermethod = " ORDER BY 
$entity_table.$order $sort";
                                }
                        }
                        else
@@ -1258,13 +1258,13 @@
                        if ($attrib_filter)
                        {
                                $filtermethod .= " $where " . implode(' AND ', 
$attrib_filter);
-                               $where= 'AND';                  
+                               $where= 'AND';
                        }
 
                        if ($custom_condition)
                        {
                                $filtermethod .= " {$where} 
{$custom_condition}";
-                               $where= 'AND';                  
+                               $where= 'AND';
                        }
 
                        if ($p_num)
@@ -1297,7 +1297,7 @@
                                        {
                                                $__querymethod = 
array("{$entity_table}.id = -1"); // block query waiting for criteria
                                        }
-                                       //_debug_array($__querymethod);         
                        
+                                       //_debug_array($__querymethod);
 
                                        $this->db->query("SELECT * FROM 
$attribute_table WHERE $attribute_filter AND search='1'");
 
@@ -1352,7 +1352,7 @@
                                                                        {
                                                                                
$_querymethod[]= "$entity_table." . $this->db->f('column_name') . ' IN (' . 
implode(',', $__filter_choise) . ')';
                                                                        }
-       
+
                                                                        
$__querymethod = array(); // remove block
                                                                }
                                                                break;
@@ -1420,7 +1420,7 @@
                        {
                                $cache_info = array();
                        }
-                       
+
                        if(!$cache_info)
                        {
                                $sql_cnt = "SELECT DISTINCT {$entity_table}.id 
" . substr($sql,strripos($sql,'FROM'));
@@ -1516,7 +1516,7 @@
                                                        'attrib_id'     => false
                                                );
                                }
-                               $j++;                           
+                               $j++;
                        }
 
                        $values = $this->custom->translate_value($dataset, 
$location_id);
@@ -1551,7 +1551,7 @@
                        {
                                $filtermethod = "WHERE id = {$id}";
                        }
-                       
+
                        $this->db->query("SELECT * FROM {$table} 
{$filtermethod}");
 
                        if($this->db->next_record())
@@ -1599,11 +1599,11 @@
                                $id                     = (int)$data['id'];
                                $location_id = 
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], 
".{$this->type}.{$data['entity_id']}.{$data['cat_id']}");
                        }
-                       
+
                        if(!$sql)
                        {
-//                             $sql = "SELECT fm_bim_item.* FROM fm_bim_item 
{$this->join} fm_bim_type ON fm_bim_type.id = fm_bim_item.type WHERE 
fm_bim_item.id = {$id} AND location_id = $location_id";                      
-                               $sql = "SELECT * FROM fm_bim_item WHERE 
fm_bim_item.id = {$id} AND location_id = $location_id";                 
+//                             $sql = "SELECT fm_bim_item.* FROM fm_bim_item 
{$this->join} fm_bim_type ON fm_bim_type.id = fm_bim_item.type WHERE 
fm_bim_item.id = {$id} AND location_id = $location_id";
+                               $sql = "SELECT * FROM fm_bim_item WHERE 
fm_bim_item.id = {$id} AND location_id = $location_id";
                        }
 
                        $this->db->query($sql,__LINE__,__FILE__);
@@ -1643,7 +1643,7 @@
 
                        if(!$location_id && !$id)
                        {
-                               throw new 
Exception("property_soentity::get_short_description() - Missing entity 
information info in input");   
+                               throw new 
Exception("property_soentity::get_short_description() - Missing entity 
information info in input");
                        }
 
                        if(!isset($system_location[$location_id]))
@@ -1671,7 +1671,7 @@
                        }
                        else
                        {
-                               throw new 
Exception("property_soentity::get_short_description() - entity not found");   
+                               throw new 
Exception("property_soentity::get_short_description() - entity not found");
                        }
 
                        $prop_array = $this->read_single($params, 
$cache_attributes[$location_id]);
@@ -1681,7 +1681,7 @@
                        {
                                $short_description[] = 
"{$attribute['input_text']}: {$attribute['value']}";
                        }
-                       
+
                        $short_description = implode(', ', $short_description);
 
                        return $short_description;
@@ -1875,7 +1875,7 @@
                protected function _save_eav($data = array(),$location_id, 
$location_name)
                {
                        $location_id = (int) $location_id;
-                       $location_name = str_replace('.', '_', $location_name); 
                
+                       $location_name = str_replace('.', '_', $location_name);
 
                        $this->db->query("SELECT id as type FROM fm_bim_type 
WHERE location_id = {$location_id}",__LINE__,__FILE__);
                        $this->db->next_record();
@@ -1897,7 +1897,7 @@
                        // Append it to the document itself
                        $doc->appendChild($domElement);
                        $doc->formatOutput = true;
-                       
+
                        $xml = $doc->saveXML();
 
                //      _debug_array($xml);
@@ -1943,7 +1943,7 @@
                        $this->db->next_record();
                        $type = (int)$this->db->f('type');
 
-                       $location_name = str_replace('.', '_', $location_name); 
                
+                       $location_name = str_replace('.', '_', $location_name);
 
                        phpgw::import_class('phpgwapi.xmlhelper');
 
@@ -2082,7 +2082,7 @@
                                                }
                                                else
                                                {
-                                                       $sql = "SELECT * FROM 
fm_bim_item WHERE fm_bim_item.id = {$values['id']} AND location_id = 
$location_id";                       
+                                                       $sql = "SELECT * FROM 
fm_bim_item WHERE fm_bim_item.id = {$values['id']} AND location_id = 
$location_id";
 
                                                        
$this->db->query($sql,__LINE__,__FILE__);
 
@@ -2151,7 +2151,7 @@
                        $cat_id         = (int) $cat_id;
                        $id                     = (int) $id;
 
-                       $location2_id   = 
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], 
".{$this->type}.{$entity_id}.{$cat_id}");  
+                       $location2_id   = 
$GLOBALS['phpgw']->locations->get_id($this->type_app[$this->type], 
".{$this->type}.{$entity_id}.{$cat_id}");
 
                        $admin_entity   = 
CreateObject('property.soadmin_entity');
                        $admin_entity->type = $this->type;
@@ -2248,7 +2248,7 @@
                                        }
                                        else
                                        {
-                                               $sql = "SELECT count(*) as hits 
FROM fm_{$type}_{$entry['entity_id']}_{$entry['cat_id']} WHERE p_entity_id = 
{$entity_id} AND p_cat_id = {$cat_id} AND p_num = '{$id}'";                     
                   
+                                               $sql = "SELECT count(*) as hits 
FROM fm_{$type}_{$entry['entity_id']}_{$entry['cat_id']} WHERE p_entity_id = 
{$entity_id} AND p_cat_id = {$cat_id} AND p_num = '{$id}'";
                                        }
                                        
$this->db->query($sql,__LINE__,__FILE__);
                                        $this->db->next_record();

Modified: trunk/property/setup/setup.inc.php
===================================================================
--- trunk/property/setup/setup.inc.php  2012-10-25 12:14:13 UTC (rev 10353)
+++ trunk/property/setup/setup.inc.php  2012-10-25 16:51:33 UTC (rev 10354)
@@ -12,7 +12,7 @@
        */
 
        $setup_info['property']['name']                 = 'property';
-       $setup_info['property']['version']              = '0.9.17.653';
+       $setup_info['property']['version']              = '0.9.17.654';
        $setup_info['property']['app_order']    = 8;
        $setup_info['property']['enable']               = 1;
        $setup_info['property']['app_group']    = 'office';

Modified: trunk/property/setup/tables_current.inc.php
===================================================================
--- trunk/property/setup/tables_current.inc.php 2012-10-25 12:14:13 UTC (rev 
10353)
+++ trunk/property/setup/tables_current.inc.php 2012-10-25 16:51:33 UTC (rev 
10354)
@@ -1701,6 +1701,7 @@
                ),
                'fm_entity' => array(
                        'fd' => array(
+                               'location_id' => array('type' => 
'int','precision' => '4','nullable' => False),
                                'id' => array('type' => 'int','precision' => 
'4','nullable' => False),
                                'name' => array('type' => 'varchar','precision' 
=> '20','nullable' => False),
                                'descr' => array('type' => 
'varchar','precision' => '50','nullable' => True),
@@ -1715,6 +1716,7 @@
                ),
                'fm_entity_category' => array(
                        'fd' => array(
+                               'location_id' => array('type' => 
'int','precision' => '4','nullable' => False),
                                'entity_id' => array('type' => 
'int','precision' => '4','nullable' => False),
                                'id' => array('type' => 'int','precision' => 
'4','nullable' => False),
                                'name' => array('type' => 'varchar','precision' 
=> '100','nullable' => True),

Modified: trunk/property/setup/tables_update.inc.php
===================================================================
--- trunk/property/setup/tables_update.inc.php  2012-10-25 12:14:13 UTC (rev 
10353)
+++ trunk/property/setup/tables_update.inc.php  2012-10-25 16:51:33 UTC (rev 
10354)
@@ -6738,3 +6738,83 @@
                }
        }
 
+       /**
+       * Update property version from 0.9.17.653 to 0.9.17.654
+       * Add location_id to entities
+       */
+       $test[] = '0.9.17.653';
+       function property_upgrade0_9_17_653()
+       {
+               $GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
+
+               
$GLOBALS['phpgw_setup']->oProc->AddColumn('fm_entity','location_id',array(
+                       'type'          => 'int',
+                       'precision'     => 4,
+                       'nullable'      => true
+                       )
+               );
+               
$GLOBALS['phpgw_setup']->oProc->AddColumn('fm_entity_category','location_id',array(
+                       'type'          => 'int',
+                       'precision'     => 4,
+                       'nullable'      => true
+                       )
+               );
+
+               $sql = 'SELECT id, entity_id FROM fm_entity_category';
+               $GLOBALS['phpgw_setup']->oProc->query($sql,__LINE__,__FILE__);
+
+               $categories = array();
+               while ($GLOBALS['phpgw_setup']->oProc->next_record())
+               {
+                       $categories[] = array
+                       (
+                               'entity_id'     => 
$GLOBALS['phpgw_setup']->oProc->f('entity_id'),
+                               'cat_id'        => 
$GLOBALS['phpgw_setup']->oProc->f('id'),
+                       );
+               }
+
+
+               $sql = 'SELECT id FROM fm_entity';
+               $GLOBALS['phpgw_setup']->oProc->query($sql,__LINE__,__FILE__);
+
+               $entities = array();
+               while ($GLOBALS['phpgw_setup']->oProc->next_record())
+               {
+                       $entities[] = array
+                       (
+                               'entity_id'     => 
$GLOBALS['phpgw_setup']->oProc->f('id'),
+                       );
+               }
+
+               foreach ($categories as $category)
+               {
+                       $location_id    = 
$GLOBALS['phpgw']->locations->get_id('property', 
".entity.{$category['entity_id']}.{$category['cat_id']}");
+                       $GLOBALS['phpgw_setup']->oProc->query("UPDATE 
fm_entity_category SET location_id = {$location_id} WHERE entity_id = 
{$category['entity_id']} AND id = {$category['cat_id']}",__LINE__,__FILE__);
+               }
+
+               foreach ($entities as $entity)
+               {
+                       $location_id    = 
$GLOBALS['phpgw']->locations->get_id('property', 
".entity.{$entity['entity_id']}");
+                       $GLOBALS['phpgw_setup']->oProc->query("UPDATE fm_entity 
SET location_id = {$location_id} WHERE id = 
{$entity['entity_id']}",__LINE__,__FILE__);
+               }
+
+               
$GLOBALS['phpgw_setup']->oProc->AlterColumn('fm_entity','location_id',array(
+                       'type'          => 'int',
+                       'precision'     => 4,
+                       'nullable'      => false
+                       )
+               );
+               
$GLOBALS['phpgw_setup']->oProc->AlterColumn('fm_entity_category','location_id',array(
+                       'type'          => 'int',
+                       'precision'     => 4,
+                       'nullable'      => false
+                       )
+               );
+
+               if($GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit())
+               {
+                       $GLOBALS['setup_info']['property']['currentver'] = 
'0.9.17.654';
+                       return $GLOBALS['setup_info']['property']['currentver'];
+               }
+       }
+




reply via email to

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