VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/10.1-cli-architecture

⇱ CLI Architecture | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

CLI Architecture

This document covers the architectural foundations of Maho's command-line interface, including the Symfony Console integration, command registration patterns, automatic command discovery, and the base command infrastructure. For details on specific CLI commands and their usage, see subsequent sections: Installation Command, Cache Management Commands, Index Management Commands, User Management Commands, Database Commands, and Maintenance and Development Commands.

Entry Point and Bootstrap

The CLI system is accessed through the maho script located at the repository root maho1-12 This PHP executable script serves as the single entry point for all CLI operations.

Core Bootstrap Sequence

The maho script performs the following initialization:

  1. Defines directory constants MAHO_ROOT_DIR and MAHO_PUBLIC_DIR for path resolution maho12-13
  2. Loads Composer autoloader from vendor/autoload.php maho15
  3. Creates a custom Symfony Console Application instance with Maho version information maho20-26
  4. Registers built-in commands (over 60 commands across functional areas) maho28-94
  5. Discovers and registers additional commands from vendor and project directories using CommandDiscoverer maho100-104
  6. Executes the Console application's run loop maho106

The custom Application class overrides getLongVersion() to display only the version number, calling Mage::getVersion() to retrieve the current Maho version maho22-25

Sources: maho1-106

Directory Constants


These constants enable commands to reference file paths relative to the repository root and the public web directory, ensuring portability across different installation layouts.

Sources: maho12-13

Command Registration Architecture

Manual Command Registration

The maho script explicitly registers commands by instantiating command classes and adding them to the Application via addCommand(). Commands are grouped by functional area:

Functional AreaExample Commands
Admin UserAdminUserList, AdminUserCreate, AdminUserChangepassword, AdminUserEnable, AdminUserDisable maho28-32
CacheCacheEnable, CacheDisable, CacheFlush, CacheMinifyFlush maho34-37
CustomerCustomerCreate, CustomerChangepassword, CustomerDelete, CustomerList maho39-42
DatabaseDBConnect, DBQuery, Migrate maho44-45 maho71
EmailEmailConfigShow, EmailQueueClear, EmailQueueProcess, EmailTestQueue, EmailTestSend maho47-51
IndexIndexList, IndexReindex, IndexReindexAll, IndexReindexProduct maho53-56
CronCronHistory, CronList, CronRun maho58-60
MaintenanceMaintenanceEnable, MaintenanceDisable, MaintenanceStatus maho65-67
Legacy MigrationLegacyRenameMysql4Classes, LegacyMigrateObservers, LegacyMigrateCron, LegacyMigrateRoutes maho72-75
DevelopmentDevModuleList, Shell, Serve, FrontendLayoutDebug maho95 maho78 maho77 maho97
ConfigConfigGet, ConfigSet, ConfigDelete maho86-88

Sources: maho28-99

Automatic Command Discovery

After manual registration, the CommandDiscoverer scans directories for additional commands:


The CommandDiscoverer performs a recursive scan looking for PHP files that define classes inheriting from Symfony's Command class lib/MahoCLI/CommandDiscoverer.php57-59 It allows modules installed via Composer or local project commands to be integrated without modifying the maho script lib/MahoCLI/CommandDiscoverer.php31-41

Sources: maho100-104 lib/MahoCLI/CommandDiscoverer.php17-64

Command Registration Flow


Sources: maho1-106 lib/MahoCLI/CommandDiscoverer.php22-64

BaseMahoCommand Pattern

All Maho-specific CLI commands extend MahoCLI\Commands\BaseMahoCommand, which itself extends Symfony's Command class. This base class provides shared infrastructure for command execution.

Class Hierarchy


Sources: lib/MahoCLI/Commands/BaseMahoCommand.php18-35 lib/MahoCLI/Commands/IndexReindex.php26 lib/MahoCLI/Commands/CronRun.php28

initMaho() Method

The initMaho() method bootstraps the Maho application in CLI context:


  1. Secure Area Registration: Registers isSecureArea flag as true in the Mage registry lib/MahoCLI/Commands/BaseMahoCommand.php22 This bypasses security checks that would normally prevent direct manipulation of sensitive data (e.g., deleting customers or admin users).
  2. Admin Store Bootstrap: Calls Mage::app('admin') to initialize the application in the admin store context lib/MahoCLI/Commands/BaseMahoCommand.php23

Sources: lib/MahoCLI/Commands/BaseMahoCommand.php20-24

Utility Methods

humanReadableSize()

Converts byte counts to human-readable size strings (B, kB, MB, GB, TB) lib/MahoCLI/Commands/BaseMahoCommand.php26-34 This is used by commands like LogStatus to display database table sizes lib/MahoCLI/Commands/LogStatus.php70-71

Sources: lib/MahoCLI/Commands/BaseMahoCommand.php26-34

Command Implementation Patterns

Command Attribute Declaration

Commands use PHP 8 attributes for metadata:


Sources: lib/MahoCLI/Commands/IndexReindex.php22-25

Interactive Input

Commands use Symfony's QuestionHelper for gathering user input:


This pattern is used in AdminUserChangepassword lib/MahoCLI/Commands/AdminUserChangepassword.php34-39 and CustomerDelete lib/MahoCLI/Commands/CustomerDelete.php35-40

Tabular Output

The Symfony\Component\Console\Helper\Table helper is used to display collections:


Used by IndexList lib/MahoCLI/Commands/IndexList.php32-41 LogStatus lib/MahoCLI/Commands/LogStatus.php32-82 and CronList lib/MahoCLI/Commands/CronList.php32-46

Mage Application Integration

CLI to Mage Bootstrap Flow


Sources: maho106 lib/MahoCLI/Commands/BaseMahoCommand.php20-24 lib/MahoCLI/Commands/IndexReindex.php37-52

Indexer Management

The IndexReindex and IndexReindexAll commands interact with Maho's indexing system. They retrieve process instances via Mage::getModel('index/indexer')->getProcessByCode($indexCode) lib/MahoCLI/Commands/IndexReindex.php40 or via the index/process_collection lib/MahoCLI/Commands/IndexReindexAll.php32 then invoke reindexEverything() lib/MahoCLI/Commands/IndexReindex.php48

Sources: lib/MahoCLI/Commands/IndexReindex.php35-53 lib/MahoCLI/Commands/IndexReindexAll.php28-48

Cron Execution

The CronRun command handles both group execution (default/always) and single job execution lib/MahoCLI/Commands/CronRun.php24-27 For group execution, it dispatches events to the crontab area lib/MahoCLI/Commands/CronRun.php54-56 For single jobs, it performs manual locking via tryLockJob() and updates the cron_schedule table status lib/MahoCLI/Commands/CronRun.php95-103

Sources: lib/MahoCLI/Commands/CronRun.php40-134

User Management

User commands utilize the model system. AdminUserChangepassword loads an admin user via loadByUsername($username) lib/MahoCLI/Commands/AdminUserChangepassword.php53-54 sets a new password lib/MahoCLI/Commands/AdminUserChangepassword.php60 and persists changes via save() lib/MahoCLI/Commands/AdminUserChangepassword.php61 AdminUserDisable sets the is_active attribute to 0 lib/MahoCLI/Commands/AdminUserDisable.php52

Sources: lib/MahoCLI/Commands/AdminUserChangepassword.php53-61 lib/MahoCLI/Commands/AdminUserDisable.php45-53