From f7023fb1aa2b47fbb08a514d9257f33032a855bf Mon Sep 17 00:00:00 2001 From: Paul Mehrer Date: Fri, 12 Jan 2024 15:36:59 +0100 Subject: [PATCH] tweak(Sales Debitor) migration sets debitor number to customer number --- tine20/Sales/Model/Address.php | 4 ++-- tine20/Sales/Model/Customer.php | 2 +- tine20/Sales/Setup/Update/17.php | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tine20/Sales/Model/Address.php b/tine20/Sales/Model/Address.php index 76e49bd4ce..545880b937 100644 --- a/tine20/Sales/Model/Address.php +++ b/tine20/Sales/Model/Address.php @@ -189,11 +189,11 @@ class Sales_Model_Address extends Tinebase_Record_NewAbstract self::QUERY_FILTER => TRUE, self::NULLABLE => TRUE, ], + // we should drop this column, be aware of upgrade path though! + // if you remove it here, Setup/Update/17.php ::update001 will remove it! though it is accessed by later update functions!!! self::FLD_CUSTOM1 => [ - self::LABEL => 'Number Debit', //_('Number Debit') self::TYPE => self::TYPE_STRING, self::NULLABLE => TRUE, - self::QUERY_FILTER => TRUE ], self::FLD_TYPE => [ self::TYPE => self::TYPE_STRING, diff --git a/tine20/Sales/Model/Customer.php b/tine20/Sales/Model/Customer.php index 992bada728..7acf70e46d 100644 --- a/tine20/Sales/Model/Customer.php +++ b/tine20/Sales/Model/Customer.php @@ -6,7 +6,7 @@ * @subpackage Model * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3 * @author Alexander Stintzing - * @copyright Copyright (c) 2013-2023 Metaways Infosystems GmbH (http://www.metaways.de) + * @copyright Copyright (c) 2013-2024 Metaways Infosystems GmbH (http://www.metaways.de) */ /** diff --git a/tine20/Sales/Setup/Update/17.php b/tine20/Sales/Setup/Update/17.php index f9adae4382..e942ccc955 100644 --- a/tine20/Sales/Setup/Update/17.php +++ b/tine20/Sales/Setup/Update/17.php @@ -27,6 +27,7 @@ class Sales_Setup_Update_17 extends Setup_Update_Abstract const RELEASE017_UPDATE008 = __CLASS__ . '::update008'; const RELEASE017_UPDATE009 = __CLASS__ . '::update009'; const RELEASE017_UPDATE010 = __CLASS__ . '::update010'; + const RELEASE017_UPDATE011 = __CLASS__ . '::update011'; static protected $_allUpdates = [ self::PRIO_TINEBASE_BEFORE_STRUCT => [ @@ -58,6 +59,10 @@ class Sales_Setup_Update_17 extends Setup_Update_Abstract self::CLASS_CONST => self::class, self::FUNCTION_CONST => 'update005', ], + self::RELEASE017_UPDATE011 => [ + self::CLASS_CONST => self::class, + self::FUNCTION_CONST => 'update011', + ], ], self::PRIO_NORMAL_APP_STRUCTURE => [ self::RELEASE017_UPDATE009 => [ @@ -401,4 +406,25 @@ public function update010() $this->addApplicationUpdate(Sales_Config::APP_NAME, '17.10', self::RELEASE017_UPDATE010); } + + public function update011() + { + $this->_db->query('UPDATE ' . SQL_TABLE_PREFIX . Sales_Model_Debitor::TABLE_NAME . ' as a JOIN ' + . SQL_TABLE_PREFIX . Sales_Model_Customer::TABLE_NAME .' AS b ON a.' . Sales_Model_Debitor::FLD_CUSTOMER_ID . ' = b.id SET a.number = b.number'); + + $this->_db->query('UPDATE ' . SQL_TABLE_PREFIX . Sales_Model_Debitor::TABLE_NAME . ' as d JOIN ' + . SQL_TABLE_PREFIX . Sales_Model_Address::TABLE_NAME . ' AS a ON a.' . Sales_Model_Address::FLD_DEBITOR_ID + . ' = d.id SET d.number = a.' . Sales_Model_Address::FLD_CUSTOM1 . ' WHERE a.' . Sales_Model_Address::FLD_CUSTOM1 . ' IS NOT NULL AND a.' . Sales_Model_Address::FLD_CUSTOM1 . ' <> ""'); + + $this->_db->query('UPDATE ' . SQL_TABLE_PREFIX . Sales_Model_Debitor::TABLE_NAME . ' as d JOIN ' + . SQL_TABLE_PREFIX . Sales_Model_Customer::TABLE_NAME .' AS c ON d.' . Sales_Model_Debitor::FLD_CUSTOMER_ID + . ' = c.id JOIN ' . SQL_TABLE_PREFIX . Sales_Model_Address::TABLE_NAME . ' AS a ON a.' . Sales_Model_Address::FLD_CUSTOMER_ID + . ' = c.id SET d.number = a.' . Sales_Model_Address::FLD_CUSTOM1 . ' WHERE a.' . Sales_Model_Address::FLD_CUSTOM1 . ' IS NOT NULL AND a.' . Sales_Model_Address::FLD_CUSTOM1 . ' <> ""'); + + $bucket = Sales_Model_Debitor::class . '#' . Sales_Model_Debitor::FLD_NUMBER . '#' . Sales_Config::getInstance()->{Sales_Config::DEFAULT_DIVISION}; + $this->getDb()->query('DELETE FROM ' . SQL_TABLE_PREFIX . 'numberable WHERE bucket = "'. $bucket . '"'); + $this->getDb()->query('INSERT INTO ' . SQL_TABLE_PREFIX . 'numberable (bucket, number) SELECT "' . $bucket . '", ' . Sales_Model_Debitor::FLD_NUMBER . ' FROM ' . SQL_TABLE_PREFIX . Sales_Model_Debitor::TABLE_NAME); + + $this->addApplicationUpdate(Sales_Config::APP_NAME, '17.11', self::RELEASE017_UPDATE011); + } }