From 39cf386638279ffd7db5349b3a861382bfb5f2f3 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Fri, 24 Jan 2025 15:04:24 +0100 Subject: [PATCH] Fixed saving edit_by in some Controllers --- application/ADBHausnummer/ADBHausnummer.php | 15 +++++++++++++-- application/ADBWohneinheit/ADBWohneinheit.php | 12 +++++++++++- application/Address/Address.php | 11 ++++++++++- application/Address/AddressController.php | 4 ---- application/Building/Building.php | 14 ++++++++++++-- application/Building/BuildingController.php | 2 -- .../ConstructionConsent/ConstructionConsent.php | 10 ++++++++++ .../ConstructionConsentContact.php | 10 ++++++++++ .../ConstructionConsentHistory.php | 10 ++++++++++ .../ConstructionConsentJournal.php | 9 +++++++++ .../ConstructionConsentNetwork.php | 10 ++++++++++ .../ConstructionConsentOwner.php | 10 ++++++++++ .../ConstructionConsentProject.php | 10 ++++++++++ application/Contract/Contract.php | 10 ++++++++++ application/Contract/ContractController.php | 1 - .../ContractconfigItem/ContractconfigItem.php | 15 +++++++++++++-- .../ContractconfigValue/ContractconfigValue.php | 12 +++++++++++- .../Contractconfiggroup/Contractconfiggroup.php | 15 +++++++++++++-- .../ContractconfiggroupProductgroup.php | 14 ++++++++++++-- application/Contractjournal/Contractjournal.php | 14 ++++++++++++-- application/Contractqueue/Contractqueue.php | 12 +++++++++++- application/Mailtemplate/Mailtemplate.php | 10 ++++++++++ .../MailtemplateDispatch/MailtemplateDispatch.php | 9 +++++++++ .../MaintenanceNotification.php | 10 ++++++++++ .../MaintenanceNotificationTemplate.php | 9 +++++++++ application/Network/Network.php | 13 +++++++++++-- application/OpenAccessId/OpenAccessId.php | 14 ++++++++++++-- application/Order/Order.php | 12 +++++++++++- application/OrderJournal/OrderJournal.php | 14 ++++++++++++-- application/OrderProduct/OrderProduct.php | 15 +++++++++++++-- application/Pop/Pop.php | 15 +++++++++++++-- application/Preorder/Preorder.php | 10 ++++++++++ application/Preordercampaign/Preordercampaign.php | 15 +++++++++++++-- .../PreordercampaignApiuser.php | 12 +++++++++++- .../PreordercampaignOperator.php | 10 ++++++++++ .../PreordercampaignOperatorIsp.php | 10 ++++++++++ .../PreordercampaignOriginhostname.php | 12 +++++++++++- .../PreordercampaignSalescluster.php | 12 +++++++++++- ...rdercampaignStatusnotificationMailtemplate.php | 10 ++++++++++ .../Preordernotification/Preordernotification.php | 14 ++++++++++++-- application/Product/Product.php | 14 ++++++++++++-- application/ProductNetwork/ProductNetwork.php | 14 ++++++++++++-- application/Productgroup/Productgroup.php | 14 ++++++++++++-- application/Producttech/Producttech.php | 14 ++++++++++++-- application/RimoWorkorder/RimoWorkorder.php | 10 ++++++++++ application/Vatgroup/Vatgroup.php | 14 ++++++++++++-- application/Vatrate/Vatrate.php | 12 +++++++++++- application/Voicenumber/Voicenumber.php | 14 ++++++++++++-- application/Voicenumberblock/Voicenumberblock.php | 15 +++++++++++++-- application/Voiceplan/Voiceplan.php | 12 +++++++++++- .../Voiceplandestination/Voiceplandestination.php | 14 ++++++++++++-- application/Voiceplanzone/Voiceplanzone.php | 14 ++++++++++++-- lib/mvcfronk/mfBase/mfBaseModel.php | 10 ++++++++++ 53 files changed, 556 insertions(+), 61 deletions(-) diff --git a/application/ADBHausnummer/ADBHausnummer.php b/application/ADBHausnummer/ADBHausnummer.php index 558e646f8..8f37028ea 100644 --- a/application/ADBHausnummer/ADBHausnummer.php +++ b/application/ADBHausnummer/ADBHausnummer.php @@ -16,8 +16,19 @@ class ADBHausnummer extends mfBaseModel { $this->table = "Hausnummer"; mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$this->id, 0); } - - public function afterSave() { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + + public function afterSave() { // prevent potential infinite loop $nesting_level = mfValuecache::singleton()->get("adbhausnummer-save-nesting-level-".$this->id); if(!$nesting_level) { diff --git a/application/ADBWohneinheit/ADBWohneinheit.php b/application/ADBWohneinheit/ADBWohneinheit.php index ff8b12731..6709227ec 100644 --- a/application/ADBWohneinheit/ADBWohneinheit.php +++ b/application/ADBWohneinheit/ADBWohneinheit.php @@ -13,7 +13,17 @@ class ADBWohneinheit extends mfBaseModel { $this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); $this->table = "Wohneinheit"; } - + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + protected function afterSave() { if(!$this->id) return true; if(!$this->hausnummer_id) return true; diff --git a/application/Address/Address.php b/application/Address/Address.php index 4bd40ab69..5aaa52415 100644 --- a/application/Address/Address.php +++ b/application/Address/Address.php @@ -41,9 +41,18 @@ class Address extends mfBaseModel { $this->getCoords(); $this->in_after_save--; - } + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function getCoords() { $update_needed = false; if($this->id) { diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index ab0050adb..26c0fed77 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -355,11 +355,7 @@ class AddressController extends mfBaseController { $data['allow_contact'] = ($r->allow_contact) ? 1 : 0; $data['allow_spin'] = ($r->allow_spin) ? 1 : 0; - - $data['edit_by'] = 1; - if($mode == "add") { - $data['create_by'] = 1; $address = AddressModel::create($data); } else { $address->update($data); diff --git a/application/Building/Building.php b/application/Building/Building.php index da878135a..ea0e41dd3 100644 --- a/application/Building/Building.php +++ b/application/Building/Building.php @@ -28,8 +28,18 @@ class Building extends mfBaseModel { return $address; } - - protected function afterSave() { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + protected function afterSave() { if($this->in_after_save) return true; $this->in_after_save++; diff --git a/application/Building/BuildingController.php b/application/Building/BuildingController.php index 32f9756df..798ba8ea3 100644 --- a/application/Building/BuildingController.php +++ b/application/Building/BuildingController.php @@ -216,8 +216,6 @@ class BuildingController extends mfBaseController { $data['description'] = trim($r->description); $data['note'] = trim($r->note); - $data['edit_by'] = 1; - if($this->me->is(["Admin", "netowner"])) { if($r->gps_lat) $data['gps_lat'] = trim($r->gps_lat); if($r->gps_long) $data['gps_long'] = trim($r->gps_long); diff --git a/application/ConstructionConsent/ConstructionConsent.php b/application/ConstructionConsent/ConstructionConsent.php index 4f0533005..3ecc5d826 100644 --- a/application/ConstructionConsent/ConstructionConsent.php +++ b/application/ConstructionConsent/ConstructionConsent.php @@ -20,6 +20,16 @@ class ConstructionConsent extends mfBaseModel { private $footer_size = "8"; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + protected function afterSave() { $this->createHistory(); } diff --git a/application/ConstructionConsentContact/ConstructionConsentContact.php b/application/ConstructionConsentContact/ConstructionConsentContact.php index 855998e02..154c75ddc 100644 --- a/application/ConstructionConsentContact/ConstructionConsentContact.php +++ b/application/ConstructionConsentContact/ConstructionConsentContact.php @@ -3,6 +3,16 @@ class ConstructionConsentContact extends mfBaseModel { private $consent; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function getProperty($name) { if($this->$name == null) { diff --git a/application/ConstructionConsentHistory/ConstructionConsentHistory.php b/application/ConstructionConsentHistory/ConstructionConsentHistory.php index fc8f4d160..d48dee78f 100644 --- a/application/ConstructionConsentHistory/ConstructionConsentHistory.php +++ b/application/ConstructionConsentHistory/ConstructionConsentHistory.php @@ -6,6 +6,16 @@ class ConstructionConsentHistory extends mfBaseModel { private $editor; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function getValue($type = "new", $raw = false) { if($type != "old" && $type != "new") return null; diff --git a/application/ConstructionConsentJournal/ConstructionConsentJournal.php b/application/ConstructionConsentJournal/ConstructionConsentJournal.php index d442d8c63..19da43bc6 100644 --- a/application/ConstructionConsentJournal/ConstructionConsentJournal.php +++ b/application/ConstructionConsentJournal/ConstructionConsentJournal.php @@ -5,6 +5,15 @@ class ConstructionConsentJournal extends mfBaseModel { private $creator; private $editor; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } public function getProperty($name) { if($this->$name == null) { if($name == "creator") { diff --git a/application/ConstructionConsentNetwork/ConstructionConsentNetwork.php b/application/ConstructionConsentNetwork/ConstructionConsentNetwork.php index eb7e36291..1aa734771 100644 --- a/application/ConstructionConsentNetwork/ConstructionConsentNetwork.php +++ b/application/ConstructionConsentNetwork/ConstructionConsentNetwork.php @@ -3,6 +3,16 @@ class ConstructionConsentNetwork extends mfBaseModel { private $adb_netzgebiet; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function getProperty($name) { if($this->$name == null) { diff --git a/application/ConstructionConsentOwner/ConstructionConsentOwner.php b/application/ConstructionConsentOwner/ConstructionConsentOwner.php index bad5c8712..c7c348748 100644 --- a/application/ConstructionConsentOwner/ConstructionConsentOwner.php +++ b/application/ConstructionConsentOwner/ConstructionConsentOwner.php @@ -10,6 +10,16 @@ class ConstructionConsentOwner extends mfBaseModel { $this->createHistory(); } + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + private function createHistory() { if(!$this->id) return true; diff --git a/application/ConstructionConsentProject/ConstructionConsentProject.php b/application/ConstructionConsentProject/ConstructionConsentProject.php index bf2d22864..d80a96606 100644 --- a/application/ConstructionConsentProject/ConstructionConsentProject.php +++ b/application/ConstructionConsentProject/ConstructionConsentProject.php @@ -5,6 +5,16 @@ class ConstructionConsentProject extends mfBaseModel { private $networks; private $adb_networks; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function getProperty($name) { if($this->$name == null) { diff --git a/application/Contract/Contract.php b/application/Contract/Contract.php index e7ffa125a..51e18dcc4 100644 --- a/application/Contract/Contract.php +++ b/application/Contract/Contract.php @@ -39,6 +39,16 @@ class Contract extends mfBaseModel { private $editor; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + protected function afterSave() { if($this->in_after_save) return true; $this->in_after_save++; diff --git a/application/Contract/ContractController.php b/application/Contract/ContractController.php index 9e15cdb19..ea6231b7b 100644 --- a/application/Contract/ContractController.php +++ b/application/Contract/ContractController.php @@ -885,7 +885,6 @@ class ContractController extends mfBaseController { if ($mode == "add") { $contract = ContractModel::create($contract_data); } else { - $contract->edit_by = $this->me->id; $contract->update($contract_data); } diff --git a/application/ContractconfigItem/ContractconfigItem.php b/application/ContractconfigItem/ContractconfigItem.php index 6b92140dd..0848abfd7 100644 --- a/application/ContractconfigItem/ContractconfigItem.php +++ b/application/ContractconfigItem/ContractconfigItem.php @@ -3,8 +3,19 @@ class ContractconfigItem extends mfBaseModel { private $value; public $contract_id; - - public function setContractId($contract_id) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + + public function setContractId($contract_id) { if(!is_numeric($contract_id)) { return false; } diff --git a/application/ContractconfigValue/ContractconfigValue.php b/application/ContractconfigValue/ContractconfigValue.php index 166ce239e..b11d60338 100644 --- a/application/ContractconfigValue/ContractconfigValue.php +++ b/application/ContractconfigValue/ContractconfigValue.php @@ -3,7 +3,17 @@ class ContractconfigValue extends mfBaseModel { private $item; - protected function afterSave() { + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + protected function afterSave() { $this->runAfterSaveHooks(); } diff --git a/application/Contractconfiggroup/Contractconfiggroup.php b/application/Contractconfiggroup/Contractconfiggroup.php index 16d2f15c1..7967d8417 100644 --- a/application/Contractconfiggroup/Contractconfiggroup.php +++ b/application/Contractconfiggroup/Contractconfiggroup.php @@ -3,8 +3,19 @@ class Contractconfiggroup extends mfBaseModel { private $items; private $contract_id; - - public function setContractId($contract_id) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + + public function setContractId($contract_id) { if(!is_numeric($contract_id)) { return false; } diff --git a/application/ContractconfiggroupProductgroup/ContractconfiggroupProductgroup.php b/application/ContractconfiggroupProductgroup/ContractconfiggroupProductgroup.php index eb0f4a989..a69a44efa 100644 --- a/application/ContractconfiggroupProductgroup/ContractconfiggroupProductgroup.php +++ b/application/ContractconfiggroupProductgroup/ContractconfiggroupProductgroup.php @@ -3,8 +3,18 @@ class ContractconfiggroupProductgroup extends mfBaseModel { private $productgroup; private $contractconfiggroup; - - public function getProperty($name) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getProperty($name) { if($this->$name == null) { if(!$this->id) { diff --git a/application/Contractjournal/Contractjournal.php b/application/Contractjournal/Contractjournal.php index 055ea31d4..9b6f73d09 100644 --- a/application/Contractjournal/Contractjournal.php +++ b/application/Contractjournal/Contractjournal.php @@ -5,8 +5,18 @@ class Contractjournal extends mfBaseModel { private $contractfile; private $creator; private $editor; - - public function getProperty($name) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getProperty($name) { if($this->$name == null) { if($name == "contractfile") { diff --git a/application/Contractqueue/Contractqueue.php b/application/Contractqueue/Contractqueue.php index 7e26c4521..c6b0719c9 100644 --- a/application/Contractqueue/Contractqueue.php +++ b/application/Contractqueue/Contractqueue.php @@ -16,7 +16,17 @@ class Contractqueue extends mfBaseModel { private $creator; private $editor; - protected function afterSave() { + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + protected function afterSave() { $this->crediting_partner = null; $this->reseller = null; $this->owner = null; diff --git a/application/Mailtemplate/Mailtemplate.php b/application/Mailtemplate/Mailtemplate.php index 4c6f81bf1..071b9ec09 100644 --- a/application/Mailtemplate/Mailtemplate.php +++ b/application/Mailtemplate/Mailtemplate.php @@ -6,6 +6,16 @@ class Mailtemplate extends mfBaseModel { private $editor; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function getVariableReplacedSubject($replaceVars) { return $this->replaceVariables($this->subject, $replaceVars); } diff --git a/application/MailtemplateDispatch/MailtemplateDispatch.php b/application/MailtemplateDispatch/MailtemplateDispatch.php index 9d3644e95..f6a511edb 100644 --- a/application/MailtemplateDispatch/MailtemplateDispatch.php +++ b/application/MailtemplateDispatch/MailtemplateDispatch.php @@ -8,6 +8,15 @@ class MailtemplateDispatch extends mfBaseModel { private $creator; private $editor; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } public function sendToRecipients($test_to_email = false) { $emails = []; diff --git a/application/MaintenanceNotification/MaintenanceNotification.php b/application/MaintenanceNotification/MaintenanceNotification.php index 195b91839..09b797d4a 100644 --- a/application/MaintenanceNotification/MaintenanceNotification.php +++ b/application/MaintenanceNotification/MaintenanceNotification.php @@ -6,6 +6,16 @@ class MaintenanceNotification extends mfBaseModel { private $editor; private $creator; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function sendToRecipients($test_to_email = false) { $emails = $this->getRecipients(); diff --git a/application/MaintenanceNotificationTemplate/MaintenanceNotificationTemplate.php b/application/MaintenanceNotificationTemplate/MaintenanceNotificationTemplate.php index 9e0bc9207..718f4813e 100644 --- a/application/MaintenanceNotificationTemplate/MaintenanceNotificationTemplate.php +++ b/application/MaintenanceNotificationTemplate/MaintenanceNotificationTemplate.php @@ -3,6 +3,15 @@ class MaintenanceNotificationTemplate extends mfBaseModel { + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } public function getProperty($name) { if($this->$name == null) { diff --git a/application/Network/Network.php b/application/Network/Network.php index 167132d1b..e9b90487f 100644 --- a/application/Network/Network.php +++ b/application/Network/Network.php @@ -9,8 +9,17 @@ class Network extends mfBaseModel { private $buildings; private $adb_netzgebiet; - - public function getTypeAddresses($search_type) { + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getTypeAddresses($search_type) { if(!$this->id) { return false; } diff --git a/application/OpenAccessId/OpenAccessId.php b/application/OpenAccessId/OpenAccessId.php index 97795c5ab..04f70a191 100644 --- a/application/OpenAccessId/OpenAccessId.php +++ b/application/OpenAccessId/OpenAccessId.php @@ -7,8 +7,18 @@ class OpenAccessId extends mfBaseModel { private $adb_wohneinheit; private $adb_wohneinheit_count; private $termination; - - public function loadRandomUnassigned($attributes = []) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function loadRandomUnassigned($attributes = []) { $where = "active = 1 AND assigned = 0 AND adb_wohneinheit_id IS NULL AND termination_id IS NULL AND exported = 0 AND exported_to IS NULL"; if(array_key_exists("owner_id", $attributes) && $attributes['owner_id']) { diff --git a/application/Order/Order.php b/application/Order/Order.php index 354c5d316..5ba673da4 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -16,7 +16,17 @@ class Order extends mfBaseModel { private $shippingdate; - protected function afterSave() { + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + protected function afterSave() { if($this->billingaddress_id) { $this->getProperty("billingaddress")->generateFibuAccountNumber(); } diff --git a/application/OrderJournal/OrderJournal.php b/application/OrderJournal/OrderJournal.php index 4cab5a5c4..3511f5c4c 100644 --- a/application/OrderJournal/OrderJournal.php +++ b/application/OrderJournal/OrderJournal.php @@ -4,8 +4,18 @@ class OrderJournal extends mfBaseModel { private $order; private $creator; private $editor; - - public function getProperty($name) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getProperty($name) { if($this->$name == null) { if(!$this->id) { diff --git a/application/OrderProduct/OrderProduct.php b/application/OrderProduct/OrderProduct.php index 2383c18f4..ea1cc5ec1 100644 --- a/application/OrderProduct/OrderProduct.php +++ b/application/OrderProduct/OrderProduct.php @@ -10,8 +10,19 @@ class OrderProduct extends mfBaseModel { private $voiceplan; private $editor; private $creator; - - public function formatAmount() { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + + public function formatAmount() { if(!$this->id) { return 0; } diff --git a/application/Pop/Pop.php b/application/Pop/Pop.php index e57334483..ce4ea825a 100644 --- a/application/Pop/Pop.php +++ b/application/Pop/Pop.php @@ -3,8 +3,19 @@ class Pop extends mfBaseModel { protected $forcestr = ['gps_lat','gps_long','vlan_public','vlan_nat','vlan_ipv6']; private $network; - - public function getProperty($name) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + + public function getProperty($name) { if ($this->$name == null) { if (!$this->id) { diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 82d1c57d0..abf3cc4d9 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -21,6 +21,16 @@ class Preorder extends mfBaseModel { private $logistics; private $history; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function afterLoad() { if($this->uid === "string") { $this->uid = ""; diff --git a/application/Preordercampaign/Preordercampaign.php b/application/Preordercampaign/Preordercampaign.php index 820276619..a756d9233 100644 --- a/application/Preordercampaign/Preordercampaign.php +++ b/application/Preordercampaign/Preordercampaign.php @@ -23,8 +23,19 @@ class Preordercampaign extends mfBaseModel { private $active_operators; private $passive_operators; private $statusnotifcation_mailtemplates; - - public function getAllFcpNames() { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + + public function getAllFcpNames() { if(!$this->id) return []; $network = $this->getProperty("network"); diff --git a/application/PreordercampaignApiuser/PreordercampaignApiuser.php b/application/PreordercampaignApiuser/PreordercampaignApiuser.php index fc5d3ce04..342feba48 100644 --- a/application/PreordercampaignApiuser/PreordercampaignApiuser.php +++ b/application/PreordercampaignApiuser/PreordercampaignApiuser.php @@ -1,5 +1,15 @@ loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + } \ No newline at end of file diff --git a/application/PreordercampaignOperator/PreordercampaignOperator.php b/application/PreordercampaignOperator/PreordercampaignOperator.php index e60041cb4..ba1c58344 100644 --- a/application/PreordercampaignOperator/PreordercampaignOperator.php +++ b/application/PreordercampaignOperator/PreordercampaignOperator.php @@ -6,6 +6,16 @@ class PreordercampaignOperator extends mfBaseModel private $preordercampaign; private $isps; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + protected function beforeDelete() { // delete all ISPs foreach(PreordercampaignOperatorIspModel::search(["campaignoperator_id" => $this->id]) as $isp) { diff --git a/application/PreordercampaignOperatorIsp/PreordercampaignOperatorIsp.php b/application/PreordercampaignOperatorIsp/PreordercampaignOperatorIsp.php index b22cd3ccc..c9fbcb8c3 100644 --- a/application/PreordercampaignOperatorIsp/PreordercampaignOperatorIsp.php +++ b/application/PreordercampaignOperatorIsp/PreordercampaignOperatorIsp.php @@ -4,6 +4,16 @@ class PreordercampaignOperatorIsp extends mfBaseModel { private $isp; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function getProperty($name) { if($this->$name == null) { diff --git a/application/PreordercampaignOriginhostname/PreordercampaignOriginhostname.php b/application/PreordercampaignOriginhostname/PreordercampaignOriginhostname.php index 5f6de989b..38ea83576 100644 --- a/application/PreordercampaignOriginhostname/PreordercampaignOriginhostname.php +++ b/application/PreordercampaignOriginhostname/PreordercampaignOriginhostname.php @@ -1,5 +1,15 @@ loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + } \ No newline at end of file diff --git a/application/PreordercampaignSalescluster/PreordercampaignSalescluster.php b/application/PreordercampaignSalescluster/PreordercampaignSalescluster.php index 4afba512f..b291ebc00 100644 --- a/application/PreordercampaignSalescluster/PreordercampaignSalescluster.php +++ b/application/PreordercampaignSalescluster/PreordercampaignSalescluster.php @@ -1,5 +1,15 @@ loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + } \ No newline at end of file diff --git a/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php b/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php index 744bb891f..83a28e69a 100644 --- a/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php +++ b/application/PreordercampaignStatusnotificationMailtemplate/PreordercampaignStatusnotificationMailtemplate.php @@ -5,6 +5,16 @@ class PreordercampaignStatusnotificationMailtemplate extends mfBaseModel { private $mailtemplate; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function getProperty($name) { if($this->$name == null) { diff --git a/application/Preordernotification/Preordernotification.php b/application/Preordernotification/Preordernotification.php index 14ee14757..53e41233f 100644 --- a/application/Preordernotification/Preordernotification.php +++ b/application/Preordernotification/Preordernotification.php @@ -7,8 +7,18 @@ class Preordernotification extends mfBaseModel { private $creator; private $editor; - - public function getPreorders() { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getPreorders() { if(!$this->preordercampaign_id) return false; $preorder_filter = json_decode($this->preorder_filter, true); diff --git a/application/Product/Product.php b/application/Product/Product.php index 9d7e0580d..9bbcd6d9d 100644 --- a/application/Product/Product.php +++ b/application/Product/Product.php @@ -7,8 +7,18 @@ class Product extends mfBaseModel { private $sla; private $networks; private $attributes; - - public function loadAttributes() { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function loadAttributes() { $this->attributes = []; if(!$this->producttech_id) { diff --git a/application/ProductNetwork/ProductNetwork.php b/application/ProductNetwork/ProductNetwork.php index f372f01e0..3b179380e 100644 --- a/application/ProductNetwork/ProductNetwork.php +++ b/application/ProductNetwork/ProductNetwork.php @@ -3,8 +3,18 @@ class ProductNetwork extends mfBaseModel { private $product; private $network; - - public function getProperty($name) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getProperty($name) { if($this->$name == null) { if(!$this->id) { diff --git a/application/Productgroup/Productgroup.php b/application/Productgroup/Productgroup.php index 1d569b5ea..2ebc1bcbf 100644 --- a/application/Productgroup/Productgroup.php +++ b/application/Productgroup/Productgroup.php @@ -3,8 +3,18 @@ class Productgroup extends mfBaseModel { private $products; private $contractconfiggroups; - - public function getProperty($name) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getProperty($name) { if($this->$name == null) { if(!$this->id) { diff --git a/application/Producttech/Producttech.php b/application/Producttech/Producttech.php index 11d0ca7f5..aa21c46c1 100644 --- a/application/Producttech/Producttech.php +++ b/application/Producttech/Producttech.php @@ -2,8 +2,18 @@ class Producttech extends mfBaseModel { private $attributes; - - public function getProperty($name) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getProperty($name) { if($this->$name == null) { if($name == "attributes") { diff --git a/application/RimoWorkorder/RimoWorkorder.php b/application/RimoWorkorder/RimoWorkorder.php index 212ce9d6a..75766f574 100644 --- a/application/RimoWorkorder/RimoWorkorder.php +++ b/application/RimoWorkorder/RimoWorkorder.php @@ -4,6 +4,16 @@ class RimoWorkorder extends mfBaseModel { private $adb_wohneinheit; private $termination; + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + public function afterSave() { // prevent potential infinite loop $nesting_level = mfValuecache::singleton()->get("rimoworkorder-save-nesting-level-".$this->id); diff --git a/application/Vatgroup/Vatgroup.php b/application/Vatgroup/Vatgroup.php index 36f118c2a..7c98c7b90 100644 --- a/application/Vatgroup/Vatgroup.php +++ b/application/Vatgroup/Vatgroup.php @@ -2,8 +2,18 @@ class Vatgroup extends mfBaseModel { private $rates; - - private function loadRates() { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + private function loadRates() { foreach(VatrateModel::search(["vatgroup_id" => $this->id]) as $rate) { $this->rates[$rate->area] = $rate; } diff --git a/application/Vatrate/Vatrate.php b/application/Vatrate/Vatrate.php index fb5005e84..f507a4f02 100644 --- a/application/Vatrate/Vatrate.php +++ b/application/Vatrate/Vatrate.php @@ -1,5 +1,15 @@ loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + } \ No newline at end of file diff --git a/application/Voicenumber/Voicenumber.php b/application/Voicenumber/Voicenumber.php index ec36eed22..db105e9cd 100644 --- a/application/Voicenumber/Voicenumber.php +++ b/application/Voicenumber/Voicenumber.php @@ -4,8 +4,18 @@ class Voicenumber extends mfBaseModel { private $block; private $orderproduct; private $contract; - - public function loadFromBlock(Voicenumberblock $block) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function loadFromBlock(Voicenumberblock $block) { $this->voicenumberblock_id = $block->id; //$this->countrycode = $block->countrycode; //$this->areacode = $block->areacode; diff --git a/application/Voicenumberblock/Voicenumberblock.php b/application/Voicenumberblock/Voicenumberblock.php index a343d8473..b0ba2719e 100644 --- a/application/Voicenumberblock/Voicenumberblock.php +++ b/application/Voicenumberblock/Voicenumberblock.php @@ -10,8 +10,19 @@ class Voicenumberblock extends mfBaseModel { private $short_last; private $files; private $numbers; - - public function isNumberInBlock($number) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + + public function isNumberInBlock($number) { return ($number >= $this->first && $number <= $this->last); } diff --git a/application/Voiceplan/Voiceplan.php b/application/Voiceplan/Voiceplan.php index 7da3fd94b..2b35689b8 100644 --- a/application/Voiceplan/Voiceplan.php +++ b/application/Voiceplan/Voiceplan.php @@ -10,7 +10,17 @@ class Voiceplan extends mfBaseModel { public $import_errors; - public function getDestinationByNumber($number) { + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getDestinationByNumber($number) { if(!$number) return false; $prefix = $number; diff --git a/application/Voiceplandestination/Voiceplandestination.php b/application/Voiceplandestination/Voiceplandestination.php index 6bf20ae74..376908f72 100644 --- a/application/Voiceplandestination/Voiceplandestination.php +++ b/application/Voiceplandestination/Voiceplandestination.php @@ -5,8 +5,18 @@ class Voiceplandestination extends mfBaseModel { private $voiceplan; private $voiceplanzone; - - public function getProperty($name) { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getProperty($name) { if($this->$name == null) { if(!$this->id) { diff --git a/application/Voiceplanzone/Voiceplanzone.php b/application/Voiceplanzone/Voiceplanzone.php index 4c209d701..8b28342f8 100644 --- a/application/Voiceplanzone/Voiceplanzone.php +++ b/application/Voiceplanzone/Voiceplanzone.php @@ -5,8 +5,18 @@ class Voiceplanzone extends mfBaseModel { private $voiceplan; public $cloned_destinations = []; - - public function getDestinationCountOrPrefix() { + + protected function beforeUpdate($data) { + if(!array_key_exists("edit_by", $data)) { + $me = new User(); + $me->loadMe(); + $data["edit_by"] = $me->id; + } + + return $data; + } + + public function getDestinationCountOrPrefix() { $destinations = $this->getProperty("destinations"); if(count($destinations) == 1) { return "+".$destinations[0]->prefix; diff --git a/lib/mvcfronk/mfBase/mfBaseModel.php b/lib/mvcfronk/mfBase/mfBaseModel.php index 2a3beeaa6..5fd0a9361 100644 --- a/lib/mvcfronk/mfBase/mfBaseModel.php +++ b/lib/mvcfronk/mfBase/mfBaseModel.php @@ -129,6 +129,10 @@ class mfBaseModel { } public function update(array $data) { + if(method_exists($this, "beforeUpdate")) { + $data = $this->beforeUpdate($data); + } + foreach($data as $key => $value) { if($value === null) { $this->$key = null; @@ -136,6 +140,12 @@ class mfBaseModel { $this->$key = $value; } } + + if(method_exists($this, "afterUpdate")) { + $this->afterUpdate($data); + } + + return true; } public function save() {