Skip to content

Greenlight 2/3 Import: Preparations for import of recordings#3034

Open
pizkaz wants to merge 2 commits intoTHM-Health:developfrom
pizkaz:feat/import-greenlight-recordings
Open

Greenlight 2/3 Import: Preparations for import of recordings#3034
pizkaz wants to merge 2 commits intoTHM-Health:developfrom
pizkaz:feat/import-greenlight-recordings

Conversation

@pizkaz
Copy link
Copy Markdown
Contributor

@pizkaz pizkaz commented Apr 9, 2026

Fixes #

Type

  • Bugfix
  • Feature
  • Documentation
  • Refactoring (e.g. Style updates, Test implementation, etc.)
  • Other (please describe):

Checklist

  • Code updated to current develop branch head
  • Passes CI checks
  • Is a part of an issue
  • Tests added for the bugfix or newly implemented feature, describe below why if not
  • Changelog is updated
  • Documentation of code and features exists

Changes

  • When running a Greenlight 2 / Greenlight 3 import command, a meeting (without timestamps) is created for every imported room so that recordings can be associated later on.

Summary by CodeRabbit

  • Improvements
    • Room imports from Greenlight v2 and v3 now create corresponding Meeting records to ensure data consistency.
    • Recording imports now resolve and associate recordings via their Meeting, improving room linkage for imported recordings.
  • Tests
    • Updated import tests and fixtures to validate meeting creation and adjusted test assertions for import output.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

Walkthrough

This PR updates Greenlight v2/v3 import commands to read external meeting IDs (bbb_id/meeting_id) and create corresponding Meeting records when new Rooms are created; it also changes RecordingFormat::createFromRecordingXML() to resolve the Meeting via Meeting::findOrFail() and associate recordings through $meeting->room. Tests and helpers updated.

Changes

Cohort / File(s) Summary
Greenlight v2 Import
app/Console/Commands/ImportGreenlight2Command.php, tests/Backend/Unit/Console/ImportGreenlight2Test.php, tests/Backend/Unit/Console/helper/Greenlight2Room.php
Selects bbb_id from Greenlight v2 rooms and creates a Meeting record for newly created Rooms. Test fixtures and assertions updated to include bbb_id and verify created Meeting IDs; CLI output assertions consolidated to table assertions.
Greenlight v3 Import
app/Console/Commands/ImportGreenlight3Command.php, tests/Backend/Unit/Console/ImportGreenlight3Test.php, tests/Backend/Unit/Console/helper/Greenlight3Room.php
Reads meeting_id from Greenlight v3 rooms and creates corresponding Meeting records when creating new Rooms. Test fixtures now supply meeting_id; tests assert the set of created meeting IDs.
Recording association
app/Models/RecordingFormat.php
createFromRecordingXML() now resolves the Meeting exclusively with Meeting::findOrFail($meetingId) (catches ModelNotFoundException) and associates the new Recording via $meeting->room instead of independent Room lookups.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description follows the template structure with type, checklist, and changes sections. However, it is missing required fields: no issue reference (Fixes #), and changelog/documentation checkboxes are unchecked. Add the related issue number using 'Fixes #' format. Consider confirming or updating the code, CI, changelog, and documentation checklist items before merge.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main feature: creating meetings during Greenlight 2/3 import as preparation for recording imports.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.14%. Comparing base (e086f05) to head (9372868).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3034      +/-   ##
=============================================
+ Coverage      96.75%   97.14%   +0.39%     
=============================================
  Files            457      179     -278     
  Lines          12988     6314    -6674     
  Branches        2079     2079              
=============================================
- Hits           12566     6134    -6432     
+ Misses           422      180     -242     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pizkaz pizkaz force-pushed the feat/import-greenlight-recordings branch from 7289bae to 9372868 Compare April 15, 2026 14:39
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/Console/Commands/ImportGreenlight2Command.php`:
- Around line 391-395: Before creating a Meeting record, check that
$room->bbb_id is not null; if it is null, do not set $dbMeeting->id or call
$dbMeeting->save()—instead skip creating the Meeting (and optionally log a
warning) to avoid violating the non-null primary key constraint; update the
block that creates the Meeting (where $dbMeeting = new Meeting, $dbMeeting->id =
$room->bbb_id, $dbMeeting->room()->associate($dbRoom), $dbMeeting->save()) to
guard on $room->bbb_id and only run those lines when it is non-null.

In `@app/Console/Commands/ImportGreenlight3Command.php`:
- Around line 305-309: Add a defensive null/empty check for $room->meeting_id
before instantiating Meeting: in ImportGreenlight3Command (around the block
creating $dbMeeting) verify that $room->meeting_id is not null/empty (and
optionally numeric) and only then create new Meeting, set $dbMeeting->id and
associate room()->associate($dbRoom); if it is null/empty, skip creation and
optionally log or record the missing meeting_id for later; mirror the same
validation used in the GL2 importer for consistency.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e1e4a130-cba1-474f-8d04-10d34acb2b47

📥 Commits

Reviewing files that changed from the base of the PR and between 7289bae and 9372868.

📒 Files selected for processing (7)
  • app/Console/Commands/ImportGreenlight2Command.php
  • app/Console/Commands/ImportGreenlight3Command.php
  • app/Models/RecordingFormat.php
  • tests/Backend/Unit/Console/ImportGreenlight2Test.php
  • tests/Backend/Unit/Console/ImportGreenlight3Test.php
  • tests/Backend/Unit/Console/helper/Greenlight2Room.php
  • tests/Backend/Unit/Console/helper/Greenlight3Room.php
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/Backend/Unit/Console/ImportGreenlight3Test.php
  • app/Models/RecordingFormat.php
  • tests/Backend/Unit/Console/helper/Greenlight2Room.php
  • tests/Backend/Unit/Console/helper/Greenlight3Room.php

Comment on lines +391 to +395
// Create meeting
$dbMeeting = new Meeting;
$dbMeeting->id = $room->bbb_id;
$dbMeeting->room()->associate($dbRoom);
$dbMeeting->save();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if Meeting model has any constraints or validation on the id field
ast-grep --pattern 'class Meeting extends $_ {
  $$$
}'

# Check Meeting migration for id column definition
fd -i 'migration' -e php --exec grep -l 'meetings' {} \; | xargs grep -A 20 'create.*meetings'

Repository: THM-Health/PILOS

Length of output: 3869


🏁 Script executed:

# Find and examine the meetings table migration
find . -path ./node_modules -prune -o -type f -name "*.php" -print | xargs grep -l "create.*table.*meetings" | head -1 | xargs cat

# Also check if there's a Room migration to understand bbb_id
find . -path ./node_modules -prune -o -type f -name "*.php" -print | xargs grep -l "create.*table.*rooms" | head -1 | xargs cat

Repository: THM-Health/PILOS

Length of output: 42


🏁 Script executed:

# Check the Room model for bbb_id definition and nullability
grep -A 50 "class Room extends" app/Models/Room.php | head -60

Repository: THM-Health/PILOS

Length of output: 1696


🏁 Script executed:

# Look at the broader context of the ImportGreenlight2Command around the flagged lines
sed -n '370,410p' app/Console/Commands/ImportGreenlight2Command.php

Repository: THM-Health/PILOS

Length of output: 1882


🏁 Script executed:

# Find migration files more carefully
find . -type d -name "migrations" | head -5

Repository: THM-Health/PILOS

Length of output: 253


🏁 Script executed:

# List migration files related to rooms and meetings
fd "\.php$" -p "*migrations*" | grep -E "(room|meeting)" | head -20

Repository: THM-Health/PILOS

Length of output: 159


🏁 Script executed:

# Check if there's any validation of bbb_id before the Meeting creation
sed -n '1,391p' app/Console/Commands/ImportGreenlight2Command.php | tail -100

Repository: THM-Health/PILOS

Length of output: 4657


🏁 Script executed:

# List all migrations in the database/migrations directory
ls -la database/migrations/ | grep -E "\.(php|sql)$"

Repository: THM-Health/PILOS

Length of output: 4522


🏁 Script executed:

# Search for the meetings table migration
grep -r "create.*table.*meetings" database/migrations/ --include="*.php" | head -1

Repository: THM-Health/PILOS

Length of output: 42


🏁 Script executed:

# Get the full content of the meetings migration
find database/migrations -name "*meetings*" -type f | head -1 | xargs cat

Repository: THM-Health/PILOS

Length of output: 1456


🏁 Script executed:

# Also get the rooms migration to check bbb_id field
find database/migrations -name "*rooms*" -type f | head -1 | xargs cat

Repository: THM-Health/PILOS

Length of output: 3121


🏁 Script executed:

# Check if there's any validation or filtering of bbb_id earlier in the import flow
grep -B 20 "importRooms" app/Console/Commands/ImportGreenlight2Command.php | head -50

Repository: THM-Health/PILOS

Length of output: 2153


Add a null check for bbb_id before creating the Meeting.

The meetings table requires a non-null id (primary key with no nullable definition). If a Greenlight room has a null bbb_id, assigning it to $dbMeeting->id will cause a database constraint violation when save() is called. While this may be rare in practice, defensive validation prevents silent failures:

🛡️ Proposed fix
             $dbRoom->save();

             // Create meeting
-            $dbMeeting = new Meeting;
-            $dbMeeting->id = $room->bbb_id;
-            $dbMeeting->room()->associate($dbRoom);
-            $dbMeeting->save();
+            if (!empty($room->bbb_id)) {
+                $dbMeeting = new Meeting;
+                $dbMeeting->id = $room->bbb_id;
+                $dbMeeting->room()->associate($dbRoom);
+                $dbMeeting->save();
+            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Create meeting
$dbMeeting = new Meeting;
$dbMeeting->id = $room->bbb_id;
$dbMeeting->room()->associate($dbRoom);
$dbMeeting->save();
// Create meeting
if (!empty($room->bbb_id)) {
$dbMeeting = new Meeting;
$dbMeeting->id = $room->bbb_id;
$dbMeeting->room()->associate($dbRoom);
$dbMeeting->save();
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Console/Commands/ImportGreenlight2Command.php` around lines 391 - 395,
Before creating a Meeting record, check that $room->bbb_id is not null; if it is
null, do not set $dbMeeting->id or call $dbMeeting->save()—instead skip creating
the Meeting (and optionally log a warning) to avoid violating the non-null
primary key constraint; update the block that creates the Meeting (where
$dbMeeting = new Meeting, $dbMeeting->id = $room->bbb_id,
$dbMeeting->room()->associate($dbRoom), $dbMeeting->save()) to guard on
$room->bbb_id and only run those lines when it is non-null.

Comment on lines +305 to +309
// Create meeting
$dbMeeting = new Meeting;
$dbMeeting->id = $room->meeting_id;
$dbMeeting->room()->associate($dbRoom);
$dbMeeting->save();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Consider adding a null check for meeting_id before creating the Meeting.

Same concern as the GL2 importer: if meeting_id is null or empty in the source data, this could cause issues. For consistency with the GL2 importer, consider adding the same defensive check.

🛡️ Proposed fix to add validation
             $dbRoom->save();

             // Create meeting
-            $dbMeeting = new Meeting;
-            $dbMeeting->id = $room->meeting_id;
-            $dbMeeting->room()->associate($dbRoom);
-            $dbMeeting->save();
+            if (!empty($room->meeting_id)) {
+                $dbMeeting = new Meeting;
+                $dbMeeting->id = $room->meeting_id;
+                $dbMeeting->room()->associate($dbRoom);
+                $dbMeeting->save();
+            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Create meeting
$dbMeeting = new Meeting;
$dbMeeting->id = $room->meeting_id;
$dbMeeting->room()->associate($dbRoom);
$dbMeeting->save();
// Create meeting
if (!empty($room->meeting_id)) {
$dbMeeting = new Meeting;
$dbMeeting->id = $room->meeting_id;
$dbMeeting->room()->associate($dbRoom);
$dbMeeting->save();
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Console/Commands/ImportGreenlight3Command.php` around lines 305 - 309,
Add a defensive null/empty check for $room->meeting_id before instantiating
Meeting: in ImportGreenlight3Command (around the block creating $dbMeeting)
verify that $room->meeting_id is not null/empty (and optionally numeric) and
only then create new Meeting, set $dbMeeting->id and associate
room()->associate($dbRoom); if it is null/empty, skip creation and optionally
log or record the missing meeting_id for later; mirror the same validation used
in the GL2 importer for consistency.

@samuelwei samuelwei added the backend Pull requests that update Php code label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants