Merge branch 'fronkdev' into 'master'

Fixed saving edit_by in some Controllers

See merge request fronk/thetool!946
This commit is contained in:
Frank Schubert
2025-01-24 14:05:35 +00:00
53 changed files with 556 additions and 61 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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++;

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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") {

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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++;

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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") {

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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 = [];

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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']) {

View File

@@ -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();
}

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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 = "";

View File

@@ -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");

View File

@@ -1,5 +1,15 @@
<?php
class PreordercampaignApiuser 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;
}
}

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -1,5 +1,15 @@
<?php
class PreordercampaignOriginhostname 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;
}
}

View File

@@ -1,5 +1,15 @@
<?php
class PreordercampaignSalescluster 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;
}
}

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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") {

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -1,5 +1,15 @@
<?php
class Vatrate 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;
}
}

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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() {