Skip to content

fix: POST /v1/dateien stichwoerter variable scoping bug (#245)#246

Open
Avatarsia wants to merge 1 commit into
OpenXE-org:masterfrom
Avatarsia:fix/dateien-stichwoerter-245
Open

fix: POST /v1/dateien stichwoerter variable scoping bug (#245)#246
Avatarsia wants to merge 1 commit into
OpenXE-org:masterfrom
Avatarsia:fix/dateien-stichwoerter-245

Conversation

@Avatarsia
Copy link
Copy Markdown
Contributor

Summary

  • Fix variable scoping bug in FileController::createAction() where $stichwoerter was only initialized inside the if-block but used in the foreach outside it
  • Add isset() check to prevent PHP Notice on missing array key

Problem

When uploading files via POST /v1/dateien with stichwoerter parameters for object binding (e.g. attaching a file to an Auftrag), the stichwoerter are silently ignored. The file is created but without any object association. Files created through the PHP UI work correctly.

Root Cause

$stichwoerter = array() was defined on line 128 inside the if (is_array(...)) block, but the foreach ($stichwoerter as ...) on line 176 runs outside that block. When the if condition is false, $stichwoerter is undefined. The resulting PHP Warning is masked by error_reporting(E_ERROR) in www/api/index.php.

Fix (2 lines changed)

-        if (is_array($input['stichwoerter'])) {
-            $stichwoerter = array();
+        $stichwoerter = array();
+        if (isset($input['stichwoerter']) && is_array($input['stichwoerter'])) {

Test plan

  • Upload file via API with stichwoerter — verify datei_stichwoerter table entry created
  • Upload file via API without stichwoerter — verify no error, file created normally
  • Upload file via UI — verify unchanged behavior

Fixes #245

Avatarsia pushed a commit to Avatarsia/OpenXE that referenced this pull request Apr 9, 2026
All four are single-file Avatarsia-authored bug fixes that are
also open upstream PRs on openxe-org:

- fix/250-wiedervorlage-sidebar-counter (PR OpenXE-org#253)
  www/eproosystem.php +2/-2: reactivate Wiedervorlagen counter

- fix/dateien-stichwoerter-245 (PR OpenXE-org#246)
  classes/Modules/Api/Controller/Version1/FileController.php +2/-2:
  fix variable scoping in POST /v1/dateien stichwoerter

- fix/versandpakete-247 (PR OpenXE-org#248)
  classes/Modules/Api/Controller/Version1/TrackingNumberController.php +25:
  write tracking numbers into the versandpakete table so the UI
  shows them

- fix/player-custom-module-support (PR OpenXE-org#256)
  phpwf/class.player.php +12/-2: support _custom.php extension
  files for page controllers, analogous to class.erpapi_custom.php

Each branch is based on an older origin/master snapshot, but
since origin/master is strictly behind upstream/master (zero
divergent commits), git merges only the new commits during
integration without re-applying the upstream drift.
@Avatarsia Avatarsia force-pushed the fix/dateien-stichwoerter-245 branch from 2c879e6 to 2529411 Compare May 7, 2026 20:18
@Avatarsia
Copy link
Copy Markdown
Contributor Author

Force-Push-Hinweis: Branch wurde direkt auf upstream/master rebased, sodass der Diff jetzt nur noch den eigentlichen Fix zeigt — ohne die ~150 Fork-internen Commits, die vorher mitliefen. Code-Endstand byte-identisch, nur die Commit-SHAs sind neu.

Bestehende Inline-Kommentare auf alten SHAs erscheinen jetzt als „outdated" — gerne nochmal kommentieren auf den neuen Commits, falls noch was offen ist.

Avatarsia pushed a commit to Avatarsia/OpenXE that referenced this pull request May 20, 2026
All four are single-file Avatarsia-authored bug fixes that are
also open upstream PRs on openxe-org:

- fix/250-wiedervorlage-sidebar-counter (PR OpenXE-org#253)
  www/eproosystem.php +2/-2: reactivate Wiedervorlagen counter

- fix/dateien-stichwoerter-245 (PR OpenXE-org#246)
  classes/Modules/Api/Controller/Version1/FileController.php +2/-2:
  fix variable scoping in POST /v1/dateien stichwoerter

- fix/versandpakete-247 (PR OpenXE-org#248)
  classes/Modules/Api/Controller/Version1/TrackingNumberController.php +25:
  write tracking numbers into the versandpakete table so the UI
  shows them

- fix/player-custom-module-support (PR OpenXE-org#256)
  phpwf/class.player.php +12/-2: support _custom.php extension
  files for page controllers, analogous to class.erpapi_custom.php

Each branch is based on an older origin/master snapshot, but
since origin/master is strictly behind upstream/master (zero
divergent commits), git merges only the new commits during
integration without re-applying the upstream drift.
$stichwoerter was only initialized inside the if-block but used
in the foreach outside it. When stichwoerter were not provided or
not an array, the variable was undefined — causing the foreach to
silently skip (masked by error_reporting(E_ERROR) in api/index.php).

Also added isset() check to prevent PHP Notice on missing key.

Fixes: OpenXE-org#245
@Avatarsia Avatarsia force-pushed the fix/dateien-stichwoerter-245 branch from 2529411 to d8ac5fb Compare May 20, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: POST /v1/dateien ignoriert stichwoerter (Datei-Objekt-Zuordnung)

1 participant