![]() |
VOOZH | about |
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.
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.
The maho script performs the following initialization:
MAHO_ROOT_DIR and MAHO_PUBLIC_DIR for path resolution maho12-13vendor/autoload.php maho15Application instance with Maho version information maho20-26CommandDiscoverer maho100-104The 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
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
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 Area | Example Commands |
|---|---|
| Admin User | AdminUserList, AdminUserCreate, AdminUserChangepassword, AdminUserEnable, AdminUserDisable maho28-32 |
| Cache | CacheEnable, CacheDisable, CacheFlush, CacheMinifyFlush maho34-37 |
| Customer | CustomerCreate, CustomerChangepassword, CustomerDelete, CustomerList maho39-42 |
| Database | DBConnect, DBQuery, Migrate maho44-45 maho71 |
EmailConfigShow, EmailQueueClear, EmailQueueProcess, EmailTestQueue, EmailTestSend maho47-51 | |
| Index | IndexList, IndexReindex, IndexReindexAll, IndexReindexProduct maho53-56 |
| Cron | CronHistory, CronList, CronRun maho58-60 |
| Maintenance | MaintenanceEnable, MaintenanceDisable, MaintenanceStatus maho65-67 |
| Legacy Migration | LegacyRenameMysql4Classes, LegacyMigrateObservers, LegacyMigrateCron, LegacyMigrateRoutes maho72-75 |
| Development | DevModuleList, Shell, Serve, FrontendLayoutDebug maho95 maho78 maho77 maho97 |
| Config | ConfigGet, ConfigSet, ConfigDelete maho86-88 |
Sources: maho28-99
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
Sources: maho1-106 lib/MahoCLI/CommandDiscoverer.php22-64
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.
Sources: lib/MahoCLI/Commands/BaseMahoCommand.php18-35 lib/MahoCLI/Commands/IndexReindex.php26 lib/MahoCLI/Commands/CronRun.php28
The initMaho() method bootstraps the Maho application in CLI context:
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).Mage::app('admin') to initialize the application in the admin store context lib/MahoCLI/Commands/BaseMahoCommand.php23Sources: lib/MahoCLI/Commands/BaseMahoCommand.php20-24
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
Commands use PHP 8 attributes for metadata:
Sources: lib/MahoCLI/Commands/IndexReindex.php22-25
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
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
Sources: maho106 lib/MahoCLI/Commands/BaseMahoCommand.php20-24 lib/MahoCLI/Commands/IndexReindex.php37-52
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
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 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
Refresh this wiki