From d2c19d42778d7e1705b3533dd2d110ea2bc7cd7d Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 20 Mar 2026 17:14:34 +0100 Subject: [PATCH] fix(commoninjectionlib): fix crash when injection model has no mandatory fields defined --- CHANGELOG.md | 6 ++++++ inc/commoninjectionlib.class.php | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de5e469b..0b6c08e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Fixed + +- Fix crash when injection model has no mandatory fields defined + ## [2.15.4] - 2026-03-16 ### Fixed diff --git a/inc/commoninjectionlib.class.php b/inc/commoninjectionlib.class.php index 5a7f18d6..65a2d5e8 100644 --- a/inc/commoninjectionlib.class.php +++ b/inc/commoninjectionlib.class.php @@ -236,8 +236,9 @@ public function areTypeMandatoryFieldsOK($injectionClass) } $status_check = true; - if (count($this->mandatory_fields[$itemtype]) > 0) { - foreach ($this->mandatory_fields[$itemtype] as $field => $value) { + $mandatory_fields = $this->mandatory_fields[$itemtype] ?? []; + if (count($mandatory_fields) > 0) { + foreach ($mandatory_fields as $field => $value) { //Get value associated with the mandatory field $value = $this->getValueByItemtypeAndName($itemtype, $field); @@ -256,6 +257,12 @@ public function areTypeMandatoryFieldsOK($injectionClass) $this->results[self::ACTION_CHECK][] = [self::MANDATORY, $option['name']]; } } + } else { + $status_check = false; + $this->results[self::ACTION_CHECK][] = [ + self::FAILED, + __('No mandatory field is defined for this model', 'datainjection'), + ]; } return $status_check; }