[PR #173] [MERGED] refactor(admin-api): extract admin/api.php into PSR-4 Ajax controllers #89

Closed
opened 2026-08-28 20:02:36 +02:00 by thegame_1980 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Vateron-Media/XC_VM/pull/173
Author: @Divarion-D
Created: 8/28/2026
Status: ✅ Merged
Merged: 8/28/2026
Merged by: @Divarion-D

Base: main ← Head: refactor/api-ajax-controllers


📝 Commits (10+)

  • 5c5ae46 refactor(admin-api): extract Cache & Handlers actions into a controller
  • 8d4693d refactor(admin-api): extract Servers/Ops actions; move ajax controllers to Admin\Ajax
  • 0ba2241 refactor(admin-api): flatten empty-then conditionals in ServerAjaxController
  • 905318e refactor(admin-api): extract Blocklists & Security actions into a controller
  • 2b271ae refactor(admin-api): extract Devices actions into a controller
  • ba1eaa8 refactor(admin-api): extract EPG actions into a controller
  • 7d6b196 style(routes): normalize admin route section headers
  • f6fad98 refactor(admin-api): extract Users & Lines actions into a controller
  • fbdc719 refactor(admin-api): extract Streams & VOD actions into controllers
  • 6e40de3 refactor(admin-api): extract Packages, Bouquets & Groups actions into a controller

📊 Changes

20 files changed (+4804 additions, -5010 deletions)

View changed files

➕ src/Public/Controllers/Admin/Ajax/BackupAjaxController.php (+206 -0)
➕ src/Public/Controllers/Admin/Ajax/BaseAjaxController.php (+104 -0)
➕ src/Public/Controllers/Admin/Ajax/BlocklistAjaxController.php (+212 -0)
➕ src/Public/Controllers/Admin/Ajax/CacheAjaxController.php (+164 -0)
➕ src/Public/Controllers/Admin/Ajax/DeviceAjaxController.php (+116 -0)
➕ src/Public/Controllers/Admin/Ajax/EpgAjaxController.php (+428 -0)
➕ src/Public/Controllers/Admin/Ajax/LineStateTrait.php (+87 -0)
➕ src/Public/Controllers/Admin/Ajax/MiscAjaxController.php (+214 -0)
➕ src/Public/Controllers/Admin/Ajax/MultiAjaxController.php (+360 -0)
➕ src/Public/Controllers/Admin/Ajax/PackageAjaxController.php (+195 -0)
➕ src/Public/Controllers/Admin/Ajax/ProviderAjaxController.php (+79 -0)
➕ src/Public/Controllers/Admin/Ajax/SearchAjaxController.php (+833 -0)
➕ src/Public/Controllers/Admin/Ajax/ServerAjaxController.php (+532 -0)
➕ src/Public/Controllers/Admin/Ajax/StatsAjaxController.php (+388 -0)
➕ src/Public/Controllers/Admin/Ajax/StreamAjaxController.php (+184 -0)
➕ src/Public/Controllers/Admin/Ajax/StreamToolsAjaxController.php (+401 -0)
➕ src/Public/Controllers/Admin/Ajax/UserAjaxController.php (+133 -0)
📝 src/Public/Controllers/Admin/AjaxController.php (+20 -12)
➖ src/Public/Views/admin/api.php (+0 -4985)
📝 src/Public/routes/admin.php (+148 -13)

📄 Description

Summary

Refactor the ~4985-line legacy src/Public/Views/admin/api.php — a flat chain of ~90 if (action == 'x') { … exit(); } blocks — into dedicated PSR-4 controllers, and retire the file entirely.

Result: admin/api.php 4985 lines → removed; ~90 actions live in 16 controllers under Public/Controllers/Admin/Ajax/.

How it works

Each action is peeled off by registering $router->api('action', [Ctrl::class, 'method']) in Public/routes/admin.php. Public/index.php runs Router::dispatchApi($action) before the AjaxController fallback, so migration was incremental and behaviour-preserving — one action group at a time. Admin authentication is already enforced by AdminScopeBootstrap::boot() before dispatch. URL and JSON contracts are unchanged (/api?action=… still works).

Building blocks

  • Ajax/BaseAjaxController — JSON-only base: ok() / fail() / gate() / gateAny() / requireXhr() / json().
  • Ajax/LineStateTrait — shared enable/disable/ban/unban/kill sub-actions for the device and line controllers.

Controllers

Cache · Server (Servers/Ops) · Blocklist · Device · Epg · User (Users & Lines) · Stream · StreamTools · Package · Stats · Backup · Provider · Misc · Search · Multi.

Notable points

  • search (848 lines) and multi were lifted byte-for-byte (verified identical), then their empty-then if (c) {} else {…} idioms were flattened by a mechanical, negation-preserving pass; multi was further de-nested into a switch → per-entity handler methods with shared helpers.
  • report keeps its non-XHR, full-page-download behaviour (dispatches TableController in-process).
  • Two real latent bugs fixed (found while porting):
    • proxy → kill read an undefined $rServerID (no-op + warnings in redis mode) — now uses server_id.
    • multi enigma bulk ops used a permission map keyed 'enigma2' while the type is 'enigma' → null permission → every enigma bulk op silently failed. Now resolves edit_e2 correctly.

Verification

Every one of the 18 commits passes: php -l, make gates (incl. check-procedural-use), make phpstan (0 errors), make cs.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Vateron-Media/XC_VM/pull/173 **Author:** [@Divarion-D](https://github.com/Divarion-D) **Created:** 8/28/2026 **Status:** ✅ Merged **Merged:** 8/28/2026 **Merged by:** [@Divarion-D](https://github.com/Divarion-D) **Base:** `main` ← **Head:** `refactor/api-ajax-controllers` --- ### 📝 Commits (10+) - [`5c5ae46`](https://github.com/Vateron-Media/XC_VM/commit/5c5ae46a2c51bce4ff6b52daaa37125945a15ab2) refactor(admin-api): extract Cache & Handlers actions into a controller - [`8d4693d`](https://github.com/Vateron-Media/XC_VM/commit/8d4693d6f4013a4134bb68984ecad2fa9ea529ab) refactor(admin-api): extract Servers/Ops actions; move ajax controllers to Admin\Ajax - [`0ba2241`](https://github.com/Vateron-Media/XC_VM/commit/0ba22412118c9b071c4aaed2f2287162427627f2) refactor(admin-api): flatten empty-then conditionals in ServerAjaxController - [`905318e`](https://github.com/Vateron-Media/XC_VM/commit/905318ef47147a716cc31d20d1079ef26a359ae6) refactor(admin-api): extract Blocklists & Security actions into a controller - [`2b271ae`](https://github.com/Vateron-Media/XC_VM/commit/2b271aee873cae243dbba50f42a4bbe07434d676) refactor(admin-api): extract Devices actions into a controller - [`ba1eaa8`](https://github.com/Vateron-Media/XC_VM/commit/ba1eaa88276a9e4d77af7e8dea6ae381989082ef) refactor(admin-api): extract EPG actions into a controller - [`7d6b196`](https://github.com/Vateron-Media/XC_VM/commit/7d6b196f7ad76e3a720bcb937760a2b2594e383a) style(routes): normalize admin route section headers - [`f6fad98`](https://github.com/Vateron-Media/XC_VM/commit/f6fad9818fc77f36abf3cef20cfd3ecbcac4a2e5) refactor(admin-api): extract Users & Lines actions into a controller - [`fbdc719`](https://github.com/Vateron-Media/XC_VM/commit/fbdc719404660063e0a6ba8510e05ec5b66df9ef) refactor(admin-api): extract Streams & VOD actions into controllers - [`6e40de3`](https://github.com/Vateron-Media/XC_VM/commit/6e40de339a1c16f62d11037d9deb54623c9a9d21) refactor(admin-api): extract Packages, Bouquets & Groups actions into a controller ### 📊 Changes **20 files changed** (+4804 additions, -5010 deletions) <details> <summary>View changed files</summary> ➕ `src/Public/Controllers/Admin/Ajax/BackupAjaxController.php` (+206 -0) ➕ `src/Public/Controllers/Admin/Ajax/BaseAjaxController.php` (+104 -0) ➕ `src/Public/Controllers/Admin/Ajax/BlocklistAjaxController.php` (+212 -0) ➕ `src/Public/Controllers/Admin/Ajax/CacheAjaxController.php` (+164 -0) ➕ `src/Public/Controllers/Admin/Ajax/DeviceAjaxController.php` (+116 -0) ➕ `src/Public/Controllers/Admin/Ajax/EpgAjaxController.php` (+428 -0) ➕ `src/Public/Controllers/Admin/Ajax/LineStateTrait.php` (+87 -0) ➕ `src/Public/Controllers/Admin/Ajax/MiscAjaxController.php` (+214 -0) ➕ `src/Public/Controllers/Admin/Ajax/MultiAjaxController.php` (+360 -0) ➕ `src/Public/Controllers/Admin/Ajax/PackageAjaxController.php` (+195 -0) ➕ `src/Public/Controllers/Admin/Ajax/ProviderAjaxController.php` (+79 -0) ➕ `src/Public/Controllers/Admin/Ajax/SearchAjaxController.php` (+833 -0) ➕ `src/Public/Controllers/Admin/Ajax/ServerAjaxController.php` (+532 -0) ➕ `src/Public/Controllers/Admin/Ajax/StatsAjaxController.php` (+388 -0) ➕ `src/Public/Controllers/Admin/Ajax/StreamAjaxController.php` (+184 -0) ➕ `src/Public/Controllers/Admin/Ajax/StreamToolsAjaxController.php` (+401 -0) ➕ `src/Public/Controllers/Admin/Ajax/UserAjaxController.php` (+133 -0) 📝 `src/Public/Controllers/Admin/AjaxController.php` (+20 -12) ➖ `src/Public/Views/admin/api.php` (+0 -4985) 📝 `src/Public/routes/admin.php` (+148 -13) </details> ### 📄 Description ## Summary Refactor the ~4985-line legacy `src/Public/Views/admin/api.php` — a flat chain of ~90 `if (action == 'x') { … exit(); }` blocks — into dedicated PSR-4 controllers, and retire the file entirely. **Result:** `admin/api.php` **4985 lines → removed**; ~90 actions live in **16 controllers** under `Public/Controllers/Admin/Ajax/`. ## How it works Each action is peeled off by registering `$router->api('action', [Ctrl::class, 'method'])` in `Public/routes/admin.php`. `Public/index.php` runs `Router::dispatchApi($action)` **before** the `AjaxController` fallback, so migration was incremental and behaviour-preserving — one action group at a time. Admin authentication is already enforced by `AdminScopeBootstrap::boot()` before dispatch. URL and JSON contracts are unchanged (`/api?action=…` still works). ### Building blocks - `Ajax/BaseAjaxController` — JSON-only base: `ok()` / `fail()` / `gate()` / `gateAny()` / `requireXhr()` / `json()`. - `Ajax/LineStateTrait` — shared enable/disable/ban/unban/kill sub-actions for the device and line controllers. ### Controllers Cache · Server (Servers/Ops) · Blocklist · Device · Epg · User (Users & Lines) · Stream · StreamTools · Package · Stats · Backup · Provider · Misc · Search · Multi. ## Notable points - **`search`** (848 lines) and **`multi`** were lifted byte-for-byte (verified identical), then their empty-then `if (c) {} else {…}` idioms were flattened by a mechanical, negation-preserving pass; `multi` was further de-nested into a `switch` → per-entity handler methods with shared helpers. - **`report`** keeps its non-XHR, full-page-download behaviour (dispatches `TableController` in-process). - **Two real latent bugs fixed** (found while porting): - `proxy → kill` read an undefined `$rServerID` (no-op + warnings in redis mode) — now uses `server_id`. - `multi` enigma bulk ops used a permission map keyed `'enigma2'` while the type is `'enigma'` → null permission → every enigma bulk op silently failed. Now resolves `edit_e2` correctly. ## Verification Every one of the 18 commits passes: `php -l`, `make gates` (incl. `check-procedural-use`), `make phpstan` (0 errors), `make cs`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
thegame_1980 added the pull-request label 2026-08-28 20:02:36 +02:00
Sign in to join this conversation.
No labels pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Vateron-Media/XC_VM#89