Skip to content

Module Lifecycle

How XC_VM discovers, loads, enables/disables, installs and distributes modules at runtime. To author a module see Module Authoring; for its extension hooks see Module Extension Points.

Enable / disable modules

All discovered modules load by default. Use src/config/modules.php to override state:

return [
    'my-module' => ['state' => 'disabled'],  // preferred
    // or legacy boolean (still accepted):
    'my-module' => ['enabled' => false],
];

Available state values (backed by ModuleState enum):

Value Meaning
enabled Module loads and boots (default)
disabled Module is discovered but skipped
installing Transient state set by ModuleManager during install
failed Install failed; module skipped (not loaded)

Panel diagnostics. The Modules page shows a yellow ⚠ Issue badge next to a module's status when the module reads Enabled but is not loaded: a required dependency is missing or not enabled (e.g. plex reads Enabled but watch is failed), its requires_core rules out this core, or its module.json cannot be loaded. The badge tooltip lists the concrete problems, for example Not loaded: it has a module.json that cannot be loaded (…). This dependency_warnings field is computed by ModuleManager::listModules().

The page, its module list and every module operation (the row actions, a ZIP upload, a store install) need the settings permission.

To override the class resolved for a module:

return [
    'my-module' => ['class' => 'XcVm\\Module\\MyModuleV2\\MyModuleV2Module'],
];

config/modules.php contains only overrides. An empty or missing file means all discovered modules load.

ModuleManager keeps its own record in the same entry. installed_version is the version of the module's files on disk. schema_version appears beside it only while the schema is ahead of those files: after a store Rollback, or after an update or an upload that failed once some of its deltas had applied. It is the version from which the next update selects its deltas, so a delta that has applied is not applied again. It goes away when the files catch up, and on uninstall. Do not edit it by hand.


How loading works

ModuleLoader follows these steps on every request:

  1. Scans src/Modules/*/module.json
  2. A module whose module.json cannot be used is skipped with an error_log line, and the rest still load: the file is not a JSON object, dependencies or optional_dependencies is not a list of names, or environment is not main, lb or any. The modules that require it are skipped with it (step 4)
  3. Applies overrides from config/modules.php
  4. Filters by environment (main / lb / any)
  5. Resolves the load order:
  6. pruneUnsatisfiableModules() drops modules whose required dependencies are unavailable (cascading, with a logged warning) so the load never aborts
  7. Topological sort (DFS) over the dependency graph
  8. Within the same dependency group, sorts by priority descending, then alphabetically
  9. Throws ModuleCycleException on cycles (a subclass of \RuntimeException; cyclic dependencies remain fatal). ModuleManager therefore refuses to put in place (upload, store install, update) a module that would close a cycle with the modules on disk; optional dependencies and disabled modules count
  10. Missing optional dependencies are silently skipped
  11. Resolves class name: my-module → FQN XcVm\Module\MyModule\MyModuleModule (kebab-case → PascalCase; can be overridden via class key in config)
  12. Registers the module's PSR-4 autoloader (maps XcVm\Module\<Name> onto the module directory)
  13. Instantiates the module class
  14. A module whose class file does not parse, or whose constructor throws, is skipped like one with an unusable module.json: an error_log line gives the reason with its file and line, the modules that require it are skipped with it, and the rest still load. Installing or updating such a module still fails with the reason

In web context:

  • bootAll($container, $router) → calls boot(), registerRoutes(), registerNavbar(), and subscribes to events for every loaded module

In CLI context:

  • registerAllCommands($registry) → calls registerCommands() on every loaded module
  • console.php module:migrate <action> <name> leaves <name> out of the load, and with it the modules that require it: that process runs the module's install or update steps before the module boots

Marketplace: install via the core extension

Modules from the platform are installed via ModuleManager::downloadFromPlatform():

$manager->downloadFromPlatform(slug: 'my-module', version: '1.2.0', apiKey: $key);

Under the hood:

  1. XC_VM::module_install($slug, $version, $apiKey) — the core extension downloads the module's single tar.gz (every *.php already ionCube-encoded) inside the sealed XCVM-API-v1 envelope and swaps it into Modules/<slug>/ atomically; there is no module key and no decryption
  2. installModule($slug) — applies the schema, then runs install() on the module. A first install applies database.sql (without one, every delta up to the module's version). Over an existing install (an update or a Rollback) it first applies the migrations/<semver>.sql deltas and the getMigrations() steps in (schema version, served version], then database.sql when the module ships one, then install()
  3. EventDispatcher::dispatch(new PackageInstalledEvent(...)) — dispatches the event
  4. hotReload($slug, $path) — loads and boots the module in the current request without PHP-FPM restart

When the request has already loaded the module's class (an enabled module being updated), step 2 runs in a console.php module:migrate process of its own — see Versioned migrations.

If a step fails, the previous files and the recorded version are put back. The versions whose deltas applied stay on record as schema_version, so the next attempt resumes after them.

An archive uploaded on the Modules page over an installed module is installed the same way. An upload that is refused, or that fails to install, leaves the installed copy in place: its files, its on/off state and the version shown.

Migrating a backup: tables of modules

The panel installs no module by itself, and keeps no list of which module owns which table. The migration (setup page → console.php migrate) migrates the core tables of a restored XUI.one / Xtream Codes backup, then handles every other table of it (MigrateCommand::moduleTables(): not in bin/install/database.sql, not migrated by the core, not junk of the old panels, e.g. their activity logs):

  • it saves the table to Modules/migration/<table>.sql (its definition and rows) and drops it from xc_vm_migrate;
  • it hands it to the installed modules (LegacyTableMigrationEvent); a module that takes it copies the rows and the file is removed;
  • a table nobody took waits in its file: when its module is installed, the file is loaded into a staging table legacy_<table>, the module copies the rows, and the file and staging table go.

At the end it drops what is left of xc_vm_migrate (tables dropped, grants kept): a backup can weigh gigabytes. If a table could not be saved, the backup database is left as it is and the log says so. Before the migration, the setup page lists the tables that will be saved for modules, with their rows.

The Modules page

The page (ModulesController renders it, ModuleAjaxController answers it) has two tabs:

  • Installed — every module with its status (enabled, disabled, not_installed, installing, failed) and its actions.
  • Store — the official store's modules (ModuleStore). The catalogue is public: it is listed without a Modules API key, a page at a time, by XC_VM::extensions_list(null, $key, $options) (xcvm_core 2.4.0 and later) with page, per_page (1–100, the page asks 50), search (up to 100 characters) and sort (name, popular, newest, price_asc, price_desc). Every module is marked Free, Purchased or Paid. A free module installs without a key and without registering the panel with the store. A paid one needs the key: register on xcvm.tech, buy the module, and set the Modules API key (Settings → API, platform_api_key); with the key the store marks the modules its user bought (owned), shown as Purchased and installable. A paid module not bought links to its store page (<store>/extensions/<slug>) instead of installing; installing it anyway fails with not_entitled, which the job reports as "This module is paid: buy it on xcvm.tech and set the Modules API key". Each answer is cached for 2 minutes per key and request (Refresh asks again; a store install clears the cache). An older extension lists the store only with a key and answers the whole list: the panel then asks XC_VM::plugins_check() for each paid module and searches, sorts and pages it itself (popular and newest keep the store's order).

Enable and disable are applied at once. Every other action (install, update, delete, rollback, license renewal, store install, archive upload, update check) is a background job (ModuleJob): the request queues it and starts console.php module:job, which runs it and records how it ended in CACHE_TMP_PATH/module_job.json. One job runs at a time. The page polls api?action=module_status (the modules and the job) until the job ends, and draws only what that answers.

Action (api?action=) Method Does
module_status GET Every module's state and the current job
module (sub, name) POST enable/disable at once; any other sub queues a job
module_upload (module_zip) POST Installs an uploaded archive as a job
module_store (page, per_page, search, sort, refresh=1) GET One page of the store's modules, with page, per_page, total, last_page

config/modules.php is read with require, which OPcache caches in each of the four PHP-FPM masters. Every read first drops the cached copy if the file changed on disk (ModuleManager::revalidate()), so a change made by one master is what the others serve and boot.


Isolated subsystems

A module can be a fully isolated subsystem with its own entry point and bootstrap (like Ministra). This is a convention, not a marker interface — it stays an ordinary ModuleInterface/BaseModule module:

class MyModule extends BaseModule {

    public function getName(): string {
        return 'my-module';
    }

    public function getVersion(): string {
        return '1.0.0';
    }
}

Isolation means the subsystem runs through its own public entry point (e.g. my-module/portal.php, a path relative to src/ that handles its own bootstrap) with a separate bootstrap path. It shares infrastructure (db, cache, config) but does not participate in the main Router, ModuleLoader::bootAll(), or NavbarRegistry. The boot() and registerRoutes() implementations are typically left as inherited no-ops.


Composer package discovery

Modules can be distributed as Composer packages with "type": "xcvm-module":

{
    "name": "vendor/my-xcvm-module",
    "type": "xcvm-module",
    "extra": {
        "xcvm": {
            "module-path": "src"
        }
    }
}

ModuleLoader automatically scans vendor/composer/installed.json (Composer 1 and 2 formats) and discovers any installed xcvm-module packages alongside the built-in src/Modules/ directory. Packages are deduplicated — a module in both modules/ and vendor/ is loaded only once.