Remove outdated edge gateway object classes, add new agent implementation

Transitioned from obsolete gateway object classes (`edge_gateway_shell_action_jobs_o`, `edge_gateway_shell_events_o`, `edge_gateway_shell_sessions_o`, `edge_gateway_update_jobs_o`) to the new agent implementation (`edge-gateway-agent/agent.php`).
This commit is contained in:
Jeppe Bundgaard
2026-04-21 14:13:17 +02:00
parent d30a006457
commit 7d450e285e
90 changed files with 11811 additions and 2760 deletions
+58 -10
View File
@@ -6,6 +6,7 @@ use attachments\helpers\attachment_content;
use classes\attachment_store;
use classes\attachments;
use classes\authentication;
use classes\economic;
use classes\orders_input_normalizer;
use classes\response;
use classes\stripe;
@@ -986,19 +987,26 @@ class ordersRoute
break;
}
};
$shouldRefreshAttachedWashCertificate = false;
// PO
if (isset($data['po'])) {
$order->po->set((string)$data['po']);
}
// Registration numbers
if (isset($data['reg_1'])) {
$order->reg_1->set($this->normalizeRegistrationNumberOrError($data['reg_1']));
$normalizedReg1 = $this->normalizeRegistrationNumberOrError($data['reg_1']);
$shouldRefreshAttachedWashCertificate = true;
$order->reg_1->set($normalizedReg1);
}
if (isset($data['reg_2'])) {
$order->reg_2->set($this->normalizeRegistrationNumberOrError($data['reg_2']));
$normalizedReg2 = $this->normalizeRegistrationNumberOrError($data['reg_2']);
$shouldRefreshAttachedWashCertificate = true;
$order->reg_2->set($normalizedReg2);
}
if (isset($data['reg_3'])) {
$order->reg_3->set($this->normalizeRegistrationNumberOrError($data['reg_3']));
$normalizedReg3 = $this->normalizeRegistrationNumberOrError($data['reg_3']);
$shouldRefreshAttachedWashCertificate = true;
$order->reg_3->set($normalizedReg3);
}
// Reference
if (isset($data['reference'])) {
@@ -1009,7 +1017,12 @@ class ordersRoute
$order->notes->set((string)$data['notes']);
}
if (array_key_exists('safety_seal', $data)) {
$order->setSafetySealValue($data['safety_seal']);
$normalizedSafetySeal = orders_o::normalizeSafetySealValue($data['safety_seal']);
$shouldRefreshAttachedWashCertificate = true;
$order->setSafetySealValue($normalizedSafetySeal);
}
if ($shouldRefreshAttachedWashCertificate) {
$order->regenerateAttachedWashCertificate();
}
// Register the change
$order->objectChanged();
@@ -1019,12 +1032,22 @@ class ordersRoute
// Admin/department path (requires edit_order)
self::requirePermission($permission_other);
/** Departmental access */
$originalCustomerNumber = (int)$order->customer_id->value();
$newCustomerNumber = $originalCustomerNumber;
$shouldAutoReassignInvoiceCollection = false;
$shouldRefreshAttachedWashCertificate = false;
// If the customer ID is set, validate it
if (isset($data['customer_id'])) {
if (!(new users_o())->getUserByCustomerNumber((int)$data['customer_id'])->exists() || empty($data['customer_id'])) {
$response->error('Customer not found or invalid', 400);
}
$order->customer_id->set((int)$data['customer_id']);
$newCustomerNumber = (int)$data['customer_id'];
$shouldRefreshAttachedWashCertificate = true;
$shouldAutoReassignInvoiceCollection = $this->shouldAutoReassignInvoiceCollectionForDraftTransition(
$originalCustomerNumber,
$newCustomerNumber
);
$order->customer_id->set($newCustomerNumber);
}
// If the reference is set, validate it
if (isset($data['reference'])) {
@@ -1036,22 +1059,30 @@ class ordersRoute
}
// If the registration number is set, validate it
if (isset($data['reg_1'])) {
$order->reg_1->set($this->normalizeRegistrationNumberOrError($data['reg_1']));
$normalizedReg1 = $this->normalizeRegistrationNumberOrError($data['reg_1']);
$shouldRefreshAttachedWashCertificate = true;
$order->reg_1->set($normalizedReg1);
}
// If the registration number 2 is set, validate it
if (isset($data['reg_2'])) {
$order->reg_2->set($this->normalizeRegistrationNumberOrError($data['reg_2']));
$normalizedReg2 = $this->normalizeRegistrationNumberOrError($data['reg_2']);
$shouldRefreshAttachedWashCertificate = true;
$order->reg_2->set($normalizedReg2);
}
// If the registration number 3 is set, validate it
if (isset($data['reg_3'])) {
$order->reg_3->set($this->normalizeRegistrationNumberOrError($data['reg_3']));
$normalizedReg3 = $this->normalizeRegistrationNumberOrError($data['reg_3']);
$shouldRefreshAttachedWashCertificate = true;
$order->reg_3->set($normalizedReg3);
}
// If the PO is set, validate it
if (isset($data['po'])) {
$order->po->set((string)$data['po']);
}
if (array_key_exists('safety_seal', $data)) {
$order->setSafetySealValue($data['safety_seal']);
$normalizedSafetySeal = orders_o::normalizeSafetySealValue($data['safety_seal']);
$shouldRefreshAttachedWashCertificate = true;
$order->setSafetySealValue($normalizedSafetySeal);
}
// If the lane is set, validate it
if (isset($data['lane'])) {
@@ -1069,7 +1100,7 @@ class ordersRoute
$order->booking_id->set((int)$data['booking_id']);
}
// Check if the invoice collection is set
if (isset($data['invoice_collection_id'])) {
if (isset($data['invoice_collection_id']) && !$shouldAutoReassignInvoiceCollection) {
$order->invoice_collection_id->set((int)$data['invoice_collection_id']);
}
// Check if the wash_id is set
@@ -1094,6 +1125,12 @@ class ordersRoute
$response->error($e->getMessage(), 400);
}
}
if ($shouldAutoReassignInvoiceCollection) {
$order->assignToInvoiceCollection(null, false);
}
if ($shouldRefreshAttachedWashCertificate) {
$order->regenerateAttachedWashCertificate();
}
// Void any cached key for the order
$order->objectChanged();
// Log the incident
@@ -1149,6 +1186,17 @@ class ordersRoute
}
}
private function shouldAutoReassignInvoiceCollectionForDraftTransition(int $originalCustomerNumber, int $newCustomerNumber): bool
{
if ($originalCustomerNumber <= 0 || $newCustomerNumber <= 0 || $originalCustomerNumber === $newCustomerNumber) {
return false;
}
$economic = new economic();
return $economic->isDraftCustomerNumber($originalCustomerNumber)
|| $economic->isDraftCustomerNumber($newCustomerNumber);
}
/**
* @param array<int, array<string, mixed>> $orders
* @return array<int, array<string, mixed>>