From ab43e358c367b39806170f45cd793203257eb5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Sch=C3=BCle?= Date: Tue, 18 Feb 2025 16:12:27 +0100 Subject: [PATCH] tweak(Sales/DemoData): add some error handling to demo data creation ... for example we now check, if certain apps (like HR, Timetracker) are installed. --- tine20/Sales/Setup/DemoData.php | 29 ++++++++++++++++----- tine20/Tinebase/Setup/DemoData/Abstract.php | 4 ++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tine20/Sales/Setup/DemoData.php b/tine20/Sales/Setup/DemoData.php index 6decc108bb3..f69113b6abd 100644 --- a/tine20/Sales/Setup/DemoData.php +++ b/tine20/Sales/Setup/DemoData.php @@ -519,6 +519,10 @@ protected function _createSharedInvoices() $now->setDate($now->format('Y'), $now->format('m'), 1); $now->setTime(3,0,0); + if (! $this->_referenceDate) { + $this->_setReferenceDate(); + } + $date = clone $this->_referenceDate; while ($date < $now) { @@ -532,6 +536,10 @@ protected function _createSharedInvoices() */ protected function _createSharedContracts() { + if (!Tinebase_Application::getInstance()->isInstalled('Timetracker')) { + return; + } + $cNumber = 1; $container = $this->_contractController->getSharedContractsContainer(); @@ -738,6 +746,10 @@ protected function _createSharedOffers() foreach ($customers as $customer) { $oc = $orderconfirmations->getByIndex($i); + if (!$oc) { + // order confirmation not found + continue; + } $i++; $relations = array(array( 'own_model' => 'Sales_Model_Offer', @@ -809,12 +821,17 @@ protected function _onCreate() : array('Management', 'IT', 'Marketing', 'Public Relations', 'Production', 'Administration') ; - foreach ($divisionsArray as $divisionName) { - try { - HumanResources_Controller_Division::getInstance()->create(new HumanResources_Model_Division(array('title' => $divisionName))); - } catch (Zend_Db_Statement_Exception $e) { - } catch (Tinebase_Exception_Duplicate $e) { - } catch (Tinebase_Exception_SystemGeneric $e) {} + if (Tinebase_Application::getInstance()->isInstalled('HumanResources')) { + foreach ($divisionsArray as $divisionName) { + try { + HumanResources_Controller_Division::getInstance()->create(new HumanResources_Model_Division( + ['title' => $divisionName] + )); + } catch (Zend_Db_Statement_Exception $e) { + } catch (Tinebase_Exception_Duplicate $e) { + } catch (Tinebase_Exception_SystemGeneric $e) { + } + } } $this->_loadCostCentersAndDivisions(); diff --git a/tine20/Tinebase/Setup/DemoData/Abstract.php b/tine20/Tinebase/Setup/DemoData/Abstract.php index b36dcb5cb2b..1b70acb9ad6 100644 --- a/tine20/Tinebase/Setup/DemoData/Abstract.php +++ b/tine20/Tinebase/Setup/DemoData/Abstract.php @@ -441,7 +441,9 @@ protected function _loadCostCentersAndDivisions() $this->_costCenterKeys[] = $cc->getId(); } - $this->_divisions = HumanResources_Controller_Division::getInstance()->search(); + if (Tinebase_Application::getInstance()->isInstalled('HumanResources')) { + $this->_divisions = HumanResources_Controller_Division::getInstance()->search(); + } return $this->_costCenters; }