Skip to content

Conversation

@TinyMemoria
Copy link
Contributor

@TinyMemoria TinyMemoria commented Jan 26, 2026

Fixes #88

Added event listener for "deleting" event and deletes subdomain.
Not throwing exception to not interfere with server deletion.

Summary by CodeRabbit

  • Bug Fixes
    • Automatic subdomain cleanup on server deletion: when a server is removed, all associated subdomains are now deleted automatically. Individual deletion failures are caught and reported so cleanup continues, preventing orphaned subdomains and improving consistency and error visibility during server removal.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

Adds a Server deletion hook in the Subdomains plugin provider that iterates related subdomains and attempts to delete each one, catching and reporting any exceptions during deletion.

Changes

Cohort / File(s) Summary
Server Deletion Cascade
subdomains/src/Providers/SubdomainsPluginProvider.php
Added Exception import and implemented a Server::deleting event hook inside boot() to iterate related subdomains and call delete() on each, catching and reporting exceptions.

Sequence Diagram(s)

sequenceDiagram
    participant Server
    participant Provider
    participant Subdomain
    participant Reporter

    Server->>Provider: deleting event
    Provider->>Subdomain: fetch related subdomains
    loop for each subdomain
        Provider->>Subdomain: call delete()
        alt delete succeeds
            Subdomain-->>Provider: deletion confirmed
        else delete throws Exception
            Subdomain-->>Provider: throws Exception
            Provider->>Reporter: reportException(Exception)
        end
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰✨ I hop through logs and tidy the lair,
When Servers drop, I handle the care.
Subdomains vanish, no leftovers stay,
I nibble the records and hop away. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: adding automatic subdomain deletion when a server is deleted.
Linked Issues check ✅ Passed The code implements the required functionality from issue #88: a server deletion cascade that removes associated subdomain DNS records without interfering with server deletion.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue #88; only the SubdomainsPluginProvider boot method was modified to add the deletion cascade logic.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link
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: 1

🤖 Fix all issues with AI agents
In `@subdomains/src/Providers/SubdomainsPluginProvider.php`:
- Around line 37-43: The Server::deleting listener currently has an empty catch
block which breaks Pint's braces_position rule and swallows exceptions; update
the listener around Server::deleting so the catch block uses proper braces on
their own lines and does not silently discard errors—log the caught Exception
(for example via Log::error or logger()->error) including context (Server id and
$subdomain->id/name) when handling exceptions thrown by $subdomain->delete();
keep deletion resilient by catching and logging but not rethrowing.
🧹 Nitpick comments (2)
subdomains/src/Providers/SubdomainsPluginProvider.php (2)

38-38: PHPStan cannot resolve dynamically registered relation — consider suppressing.

The subdomains() relation is dynamically registered via resolveRelationUsing on line 35, so the code will work at runtime. However, PHPStan cannot statically analyze dynamic relations, causing the CI failures.

Since Server is an external model you don't control, consider suppressing the PHPStan error inline:

♻️ Proposed fix
         Server::deleting(function (Server $server) {
+            /** `@phpstan-ignore` method.notFound */
             foreach ($server->subdomains()->get() as $subdomain) {

Alternatively, add the error to your PHPStan baseline if you prefer not to use inline ignores.


10-12: Consider reordering imports per PSR-12 conventions.

Exception is a global PHP class and conventionally should be grouped before framework imports.

♻️ Suggested ordering
 use App\Filament\Admin\Resources\Servers\ServerResource;
 use App\Models\Role;
 use App\Models\Server;
 use Boy132\Subdomains\Filament\Admin\Resources\Servers\RelationManagers\SubdomainRelationManager;
 use Boy132\Subdomains\Models\Subdomain;
+use Exception;
 use Illuminate\Support\Facades\Http;
-use Exception;
 use Illuminate\Support\ServiceProvider;
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6a2910 and 8008d95.

📒 Files selected for processing (1)
  • subdomains/src/Providers/SubdomainsPluginProvider.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-04T11:13:45.197Z
Learnt from: HarlequinSin
Repo: pelican-dev/plugins PR: 67
File: subdomains/src/Models/Subdomain.php:49-65
Timestamp: 2026-01-04T11:13:45.197Z
Learning: In Subdomain model creating hook at subdomains/src/Models/Subdomain.php, the code uses setRelation('server', Filament::getTenant()) because the model hasn't been saved yet and load() won't work during creation. This is intentional for Filament-context creation.

Applied to files:

  • subdomains/src/Providers/SubdomainsPluginProvider.php
🧬 Code graph analysis (1)
subdomains/src/Providers/SubdomainsPluginProvider.php (3)
subdomains/src/Models/Subdomain.php (1)
  • server (48-51)
subdomains/src/Models/CloudflareDomain.php (1)
  • subdomains (31-34)
robo-avatars/src/RoboAvatarsSchema.php (1)
  • get (20-23)
🪛 GitHub Actions: Lint
subdomains/src/Providers/SubdomainsPluginProvider.php

[error] 1-1: vendor/bin/pint --test failed with exit code 1 due to style issue: braces_position (Laravel).

🪛 GitHub Check: PHPStan (8.2)
subdomains/src/Providers/SubdomainsPluginProvider.php

[failure] 38-38:
Call to an undefined method App\Models\Server::subdomains().

🪛 GitHub Check: PHPStan (8.3)
subdomains/src/Providers/SubdomainsPluginProvider.php

[failure] 38-38:
Call to an undefined method App\Models\Server::subdomains().

🪛 GitHub Check: PHPStan (8.4)
subdomains/src/Providers/SubdomainsPluginProvider.php

[failure] 38-38:
Call to an undefined method App\Models\Server::subdomains().

🪛 GitHub Check: PHPStan (8.5)
subdomains/src/Providers/SubdomainsPluginProvider.php

[failure] 38-38:
Call to an undefined method App\Models\Server::subdomains().

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
subdomains/src/Providers/SubdomainsPluginProvider.php (1)

5-12: Fix ordered imports to satisfy Pint.

The lint pipeline is failing on ordered_imports. Reorder the use statements alphabetically to pass Pint.

✅ Proposed fix
 use App\Filament\Admin\Resources\Servers\ServerResource;
 use App\Models\Role;
 use App\Models\Server;
 use Boy132\Subdomains\Filament\Admin\Resources\Servers\RelationManagers\SubdomainRelationManager;
 use Boy132\Subdomains\Models\Subdomain;
-use Illuminate\Support\Facades\Http;
 use Exception;
+use Illuminate\Support\Facades\Http;
 use Illuminate\Support\ServiceProvider;
🤖 Fix all issues with AI agents
In `@subdomains/src/Providers/SubdomainsPluginProvider.php`:
- Around line 35-39: PHPStan can't see the runtime relation registered via
Server::resolveRelationUsing() so add a static declaration for the relation to
satisfy analysis: add a `@method` HasMany subdomains() annotation to the Server
model class (App\Models\Server) or alternatively create a phpstan stub declaring
method subdomains(): HasMany; if you prefer suppressing the error instead, add
an ignoreErrors entry for larastan.noMethodFound with a message matching 'Call
to an undefined method.*subdomains' in phpstan.neon; reference the
Server::resolveRelationUsing and Server::subdomains() symbols when making the
change.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8008d95 and 30588b1.

📒 Files selected for processing (1)
  • subdomains/src/Providers/SubdomainsPluginProvider.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-04T11:13:45.197Z
Learnt from: HarlequinSin
Repo: pelican-dev/plugins PR: 67
File: subdomains/src/Models/Subdomain.php:49-65
Timestamp: 2026-01-04T11:13:45.197Z
Learning: In Subdomain model creating hook at subdomains/src/Models/Subdomain.php, the code uses setRelation('server', Filament::getTenant()) because the model hasn't been saved yet and load() won't work during creation. This is intentional for Filament-context creation.

Applied to files:

  • subdomains/src/Providers/SubdomainsPluginProvider.php
🧬 Code graph analysis (1)
subdomains/src/Providers/SubdomainsPluginProvider.php (2)
subdomains/src/Models/Subdomain.php (1)
  • server (48-51)
subdomains/src/Models/CloudflareDomain.php (1)
  • subdomains (31-34)
🪛 GitHub Actions: Lint
subdomains/src/Providers/SubdomainsPluginProvider.php

[error] 1-1: Pint: ordered_imports violation detected in SubdomainsPluginProvider.php. Ensure imports are alphabetically ordered.

🪛 GitHub Check: PHPStan (8.2)
subdomains/src/Providers/SubdomainsPluginProvider.php

[failure] 38-38:
Call to an undefined method App\Models\Server::subdomains().

🪛 GitHub Check: PHPStan (8.3)
subdomains/src/Providers/SubdomainsPluginProvider.php

[failure] 38-38:
Call to an undefined method App\Models\Server::subdomains().

🪛 GitHub Check: PHPStan (8.4)
subdomains/src/Providers/SubdomainsPluginProvider.php

[failure] 38-38:
Call to an undefined method App\Models\Server::subdomains().

🪛 GitHub Check: PHPStan (8.5)
subdomains/src/Providers/SubdomainsPluginProvider.php

[failure] 38-38:
Call to an undefined method App\Models\Server::subdomains().

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Member

@Boy132 Boy132 left a comment

Choose a reason for hiding this comment

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

Small nitpick, otherwise looks good.

Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
Copy link
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: 1

🤖 Fix all issues with AI agents
In `@subdomains/src/Providers/SubdomainsPluginProvider.php`:
- Line 10: Replace the current Exception-only handling with Throwable so PHP
Errors/TypeErrors don't abort deletion: update the import from "use Exception;"
to "use Throwable;" (or remove the Exception import and reference Throwable) and
change the catch(Exception $e) blocks that wrap the $subdomain->delete() call to
catch(Throwable $e) in the SubdomainsPluginProvider class where
$subdomain->delete() is invoked, preserving the existing logging/handling inside
the catch.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd4f571 and ba4455f.

📒 Files selected for processing (1)
  • subdomains/src/Providers/SubdomainsPluginProvider.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-04T11:13:45.197Z
Learnt from: HarlequinSin
Repo: pelican-dev/plugins PR: 67
File: subdomains/src/Models/Subdomain.php:49-65
Timestamp: 2026-01-04T11:13:45.197Z
Learning: In Subdomain model creating hook at subdomains/src/Models/Subdomain.php, the code uses setRelation('server', Filament::getTenant()) because the model hasn't been saved yet and load() won't work during creation. This is intentional for Filament-context creation.

Applied to files:

  • subdomains/src/Providers/SubdomainsPluginProvider.php
🧬 Code graph analysis (1)
subdomains/src/Providers/SubdomainsPluginProvider.php (2)
subdomains/src/Models/Subdomain.php (1)
  • server (48-51)
subdomains/src/Models/CloudflareDomain.php (1)
  • subdomains (31-34)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@TinyMemoria TinyMemoria requested a review from Boy132 January 26, 2026 07:13
Copy link
Member

@Boy132 Boy132 left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

@Boy132 Boy132 merged commit d249909 into pelican-dev:main Jan 26, 2026
7 checks passed
@TinyMemoria TinyMemoria deleted the deleteserver branch January 26, 2026 07:21
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.

[Subdomains] When a server is Deleted, DNS record remains

2 participants