From 446bd2793ef67ca8f7b928faddecb34922356baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Ga=C5=A1pari=C4=87?= Date: Tue, 29 Apr 2025 14:05:13 +0200 Subject: [PATCH 1/6] Update Form.php mass assign custom field IDs to Form --- src/App/Models/Form.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/App/Models/Form.php b/src/App/Models/Form.php index 524e8ba..101a2e5 100644 --- a/src/App/Models/Form.php +++ b/src/App/Models/Form.php @@ -36,6 +36,8 @@ class Form extends Model implements \Asseco\CustomFields\App\Contracts\Form 'definition' => 'array', ]; + private array $_customFieldNames = []; + protected static function newFactory() { return FormFactory::new(); @@ -71,13 +73,14 @@ protected function relateCustomFieldsFromDefinition() $components = Arr::get($this->definition, 'components', []); $this->extractCustomFields($components); + $this->relateCustomFields(); } protected function extractCustomFields(array $components): void { foreach ($components as $componentKey => $component) { if ($componentKey === 'key') { - $this->relateCustomField($component); + $this->_customFieldNames[] = $component; } if (!is_array($component)) { @@ -103,6 +106,17 @@ protected function relateCustomField(string $key): void } } + protected function relateCustomFields(): void + { + /** @var CustomField $customFieldClass */ + $customFieldClass = app(CustomField::class); + $customFieldIds = $customFieldClass::query()->whereIn('name', array_unique($this->_customFieldNames))->get()->pluck('id'); + + if (!empty($customFieldIds)) { + $this->customFields()->attach($customFieldIds); + } + } + public function customFields(): BelongsToMany { return $this->belongsToMany(get_class(app(CustomField::class)))->withTimestamps(); @@ -112,7 +126,7 @@ public function customFields(): BelongsToMany * @param array $formData * @return array * - * @throws Exception + * @throws Exception|\Throwable */ public function validate(array $formData): array { From b10d5032818da1ef4a5b53a342b26e4449c7ecc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Ga=C5=A1pari=C4=87?= Date: Tue, 29 Apr 2025 14:06:39 +0200 Subject: [PATCH 2/6] Update Form.php handle empty CFs --- src/App/Models/Form.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/App/Models/Form.php b/src/App/Models/Form.php index 101a2e5..a781ff3 100644 --- a/src/App/Models/Form.php +++ b/src/App/Models/Form.php @@ -108,6 +108,10 @@ protected function relateCustomField(string $key): void protected function relateCustomFields(): void { + if (empty($this->_customFieldNames)) { + return; + } + /** @var CustomField $customFieldClass */ $customFieldClass = app(CustomField::class); $customFieldIds = $customFieldClass::query()->whereIn('name', array_unique($this->_customFieldNames))->get()->pluck('id'); From ba793af4fc5d418d88e5cbcdf87666d3b459cee6 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 29 Apr 2025 12:06:48 +0000 Subject: [PATCH 3/6] Apply fixes from StyleCI --- src/App/Models/Form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App/Models/Form.php b/src/App/Models/Form.php index a781ff3..8e0d20f 100644 --- a/src/App/Models/Form.php +++ b/src/App/Models/Form.php @@ -111,7 +111,7 @@ protected function relateCustomFields(): void if (empty($this->_customFieldNames)) { return; } - + /** @var CustomField $customFieldClass */ $customFieldClass = app(CustomField::class); $customFieldIds = $customFieldClass::query()->whereIn('name', array_unique($this->_customFieldNames))->get()->pluck('id'); From 83c8082f4a314fa209d57b6f82b0def8351b10f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Ga=C5=A1pari=C4=87?= Date: Tue, 29 Apr 2025 14:11:19 +0200 Subject: [PATCH 4/6] Update pull_request.yml runs-on: ubuntu-24.04 --- .github/workflows/pull_request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f9c4443..37f5c15 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -7,7 +7,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v2 @@ -26,7 +26,7 @@ jobs: - name: Cache Composer packages id: composer-cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: vendor key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} From 060be87ba24d39474872c8bfba9e61962d056e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Ga=C5=A1pari=C4=87?= Date: Tue, 29 Apr 2025 14:17:33 +0200 Subject: [PATCH 5/6] Update Form.php for testing. there's one instance used mutliple times --- src/App/Models/Form.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App/Models/Form.php b/src/App/Models/Form.php index 8e0d20f..6b69b29 100644 --- a/src/App/Models/Form.php +++ b/src/App/Models/Form.php @@ -72,6 +72,7 @@ protected function relateCustomFieldsFromDefinition() { $components = Arr::get($this->definition, 'components', []); + $this->_customFieldNames = []; $this->extractCustomFields($components); $this->relateCustomFields(); } From 5bf218014a5d18dbc6413ec19b20fda84b27fae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Ga=C5=A1pari=C4=87?= Date: Tue, 29 Apr 2025 14:20:30 +0200 Subject: [PATCH 6/6] Update pull_request.yml pull_req --- .github/workflows/pull_request.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 37f5c15..1359912 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -15,7 +15,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' extensions: mbstring, intl ini-values: post_max_size=256M, max_execution_time=180 coverage: xdebug @@ -44,7 +44,7 @@ jobs: - name: PHP STatic ANalyser (phpstan) uses: php-actions/phpstan@v3 with: + version: latest path: 'src' - php_version: '8.1' + php_version: '8.2' level: 0 - memory_limit: 256M