]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
fix(ERP-250): add null check for WriteOffsErp model in actionUpdate origin/feature_filippov_ERP-250_fix_writeoffs_null_check
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Mon, 2 Mar 2026 08:16:52 +0000 (11:16 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Mon, 2 Mar 2026 08:16:52 +0000 (11:16 +0300)
$query->one() can return null when the record is deleted, sent to 1C,
or the user has no store access. Without the check, line 1076 crashes
with "Call to a member function getRelation() on null".

Now throws NotFoundHttpException (404) as documented in the PHPDoc.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
erp24/controllers/WriteOffsErpController.php

index 9904f6e600e5351f394347c68782a6bcfe96168e..e56bcab7953ad9bbb95c5cfa668c7b04dfc97940 100644 (file)
@@ -1072,6 +1072,9 @@ class WriteOffsErpController extends Controller
 
         $model = $query->one();
 
+        if ($model === null) {
+            throw new NotFoundHttpException('Списание не найдено или недоступно.');
+        }
 
         $modelWriteOffsProductsErps = ($model->getRelation('writeOffsProductsErps', false));
         $model->writeOffsProductsErps = ArrayHelper::getValue($model->getRelatedRecords(), 'writeOffsProductsErps');