fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10372] api: backup incompatible fields when altering


From: Sigurd Nes
Subject: [Fmsystem-commits] [10372] api: backup incompatible fields when altering datatype on custom fields
Date: Mon, 29 Oct 2012 14:42:31 +0000

Revision: 10372
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10372
Author:   sigurdne
Date:     2012-10-29 14:42:31 +0000 (Mon, 29 Oct 2012)
Log Message:
-----------
api: backup incompatible fields when altering datatype on custom fields

Modified Paths:
--------------
    trunk/phpgwapi/inc/class.custom_fields.inc.php

Modified: trunk/phpgwapi/inc/class.custom_fields.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.custom_fields.inc.php      2012-10-29 13:02:56 UTC 
(rev 10371)
+++ trunk/phpgwapi/inc/class.custom_fields.inc.php      2012-10-29 14:42:31 UTC 
(rev 10372)
@@ -868,8 +868,49 @@
                                }
 
                                $attrib['column_info']['type']  = 
$this->_translate_datatype_insert($attrib['column_info']['type']);
+                               
+                               $incompatible_char_types = array
+                               (
+                                       'int'           => true,
+                                       'decimal'       => true,
+                                       'timestamp'     => true
+                               );
+
                                if($attrib_table)
                                {
+                                       $incompatible_type = false;
+                                       $OldDataType = 
$this->_translate_datatype_insert($OldDataType);
+                                       
+                                       if ($OldDataType == 'varchar' && 
isset($incompatible_char_types[$attrib['column_info']['type']]) && 
$incompatible_char_types[$attrib['column_info']['type']])
+                                       {
+                                               $incompatible_type = true;
+                                       }
+                                       else if ($OldDataType == 'char' && 
isset($incompatible_char_types[$attrib['column_info']['type']]) && 
$incompatible_char_types[$attrib['column_info']['type']])
+                                       {
+                                               $incompatible_type = true;
+                                       }
+                                       else if ($OldDataType == 'text' && 
isset($incompatible_char_types[$attrib['column_info']['type']]) && 
$incompatible_char_types[$attrib['column_info']['type']])
+                                       {
+                                               $incompatible_type = true;
+                                       }
+
+                                       if($incompatible_type)
+                                       {
+                                               $metadata = 
$this->_db->metadata($attrib_table);
+
+                                               $found_column = true;
+                                               $i = 0;
+                                               do
+                                               {
+                                                       $backup_column_name = 
"{$attrib['column_name']}_backup_{$i}";
+                                                       $i++;
+                                               }
+                                               while 
(isset($metadata[$backup_column_name]));
+                                               
+                                               
$this->_oProc->RenameColumn($attrib_table,$attrib['column_name'], 
$backup_column_name);
+                                               
$this->_oProc->AddColumn($attrib_table, $attrib['column_name'], 
$attrib['column_info']);
+                                       }
+                                       
                                        
$this->_oProc->AlterColumn($attrib_table,$attrib['column_name'],$attrib['column_info']);
                                }
                        }




reply via email to

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