From acee68c6c3a49a826b7407701954459d60ba922f Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 3 Oct 2023 15:19:44 +0200 Subject: [PATCH] Fixed not finding unit sometimes in PreorderApi/submitPreorder --- application/AddressDB/AddressDBController.php | 4 ++-- application/Api/v1/PreorderApicontroller.php | 9 ++++----- application/User/UserController.php | 7 ++++++- .../preorder/preorders-split-multiple-connections.php | 5 +++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/application/AddressDB/AddressDBController.php b/application/AddressDB/AddressDBController.php index 6039c2d37..850728fff 100644 --- a/application/AddressDB/AddressDBController.php +++ b/application/AddressDB/AddressDBController.php @@ -9,7 +9,7 @@ class AddressDBController extends mfBaseController { $this->me = $me; $this->layout()->set("me",$me); - if(!$me->is(["Admin", "netowner"])) { + if(!$me->is(["Admin", "netowner"]) && !$me->can("Preorder")) { $this->redirect("Dashboard"); } } @@ -438,7 +438,7 @@ class AddressDBController extends mfBaseController { } protected function apiAction() { - if(!$this->me->is(["Admin","netowner"])) { + if(!$this->me->is(["Admin","netowner"]) && !$this->me->can("Preorder")) { $this->redirect("Dashboard"); } $do = $this->request->do; diff --git a/application/Api/v1/PreorderApicontroller.php b/application/Api/v1/PreorderApicontroller.php index aa18e62e5..99289badb 100644 --- a/application/Api/v1/PreorderApicontroller.php +++ b/application/Api/v1/PreorderApicontroller.php @@ -411,7 +411,7 @@ class PreorderApicontroller extends mfBaseApicontroller { if($field == "ortschaft" || $field == "gemeinde") continue; $where .= " AND `$field` = '$value'"; } - + // filter salesclusters if(count($this->filter_salescluster_ids)) { $where .= " AND netzgebiet_id IN (".implode(',', $this->filter_salescluster_ids).")"; @@ -753,9 +753,8 @@ class PreorderApicontroller extends mfBaseApicontroller { } else { // else get available units with no unit data, so we can update it $exclude_wohneinheit_ids = []; - $preorders_in_hausnummer = PreorderModel::search(['adb_hausnummer_id' => $address->hausnummer_id]); + $preorders_in_hausnummer = PreorderModel::search(['adb_hausnummer_id' => $address->hausnummer_id, "deleted" => 0]); if(count($preorders_in_hausnummer)) { - foreach($preorders_in_hausnummer as $pih) { if($pih->adb_wohneinheit_id) { $exclude_wohneinheit_ids[] = $pih->adb_wohneinheit_id; @@ -770,7 +769,7 @@ class PreorderApicontroller extends mfBaseApicontroller { $where .= " AND ( stock = '' OR stock IS NULL)"; $where .= " AND ( tuer = '' OR tuer IS NULL)"; $where .= " AND ( bezeichner = '' OR bezeichner IS NULL)"; - + if(count($exclude_wohneinheit_ids)) { $where .= " AND wohneinheit_id NOT IN (". implode(",",$exclude_wohneinheit_ids).")"; } @@ -780,7 +779,7 @@ class PreorderApicontroller extends mfBaseApicontroller { if(!$this->db()->num_rows($res)) { return mfResponse::Forbidden(['message' => "Keine Wohneinheiten verfügbar"]); } - + $unit_row = $this->db()->fetch_object($res); $unit = new ADBWohneinheit($unit_row->wohneinheit_id); } diff --git a/application/User/UserController.php b/application/User/UserController.php index 2ca11318c..3ebe67781 100644 --- a/application/User/UserController.php +++ b/application/User/UserController.php @@ -1,4 +1,4 @@ -preorder_networks) && count($r->preorder_networks)) { $pn->value(json_encode($r->preorder_networks)); $pn->save(); + + $user->permissions->canPreorder = true; } else { $pn->delete(); } + + //XXX - set all can permissions true + } $this->layout()->setFlash("Benutzer gespeichert.", "success"); diff --git a/scripts/preorder/preorders-split-multiple-connections.php b/scripts/preorder/preorders-split-multiple-connections.php index 4348e8693..15e9410f4 100755 --- a/scripts/preorder/preorders-split-multiple-connections.php +++ b/scripts/preorder/preorders-split-multiple-connections.php @@ -18,6 +18,7 @@ define("INTERNAL_USER_USERNAME", $me->username); $ignore_preorders = []; $campaign_prem_nord = 5; +$campaign_gross_st_florian = 7; $same_unit_count = 0; $missing_units = []; @@ -25,7 +26,7 @@ $missing_doors = []; $total = 0; $c = 0; -foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaign_prem_nord, "connection_count" => 2]) as $preorder) { +foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaign_gross_st_florian, "connection_count" => 2]) as $preorder) { // check if we have enough units with extref $wohneinheiten = ADBWohneinheitModel::search(["hausnummer_id" => $preorder->adb_hausnummer_id]); $unit_count = count($wohneinheiten); @@ -119,4 +120,4 @@ foreach($missing_doors as $md) { echo "\n"; } -echo "Processed $total, created $c preorders\n"; \ No newline at end of file +echo "Processed $total, created $c preorders\n";