n98-magerun2 Documentation
repository·develop·Indexed 21 days ago
https://github.com/netz98/n98-magerun2A powerful CLI toolset for managing Magento 2, Mage-OS, and Adobe Commerce environments. It provides a comprehensive suite of commands for database operations, cache management, configuration, and developer workflows, including specialized admin user management and token creation.
What's inside n98-magerun2
- n98-magerun2 provides a suite of commands for managing Magento 2 customers via the CLI. These commands allow you to retrieve information, create new customers, manage addresses, list existing customers, change passwords, manage authentication tokens, and delete customer records.
Manage EAV attributes with n98-magerun2
developn98-magerun2 provides a suite of commands to manage Magento's Entity-Attribute-Value (EAV) model. EAV is the flexible data model used for entities like products and customers. You can use these commands to list available attributes, inspect the data associated with a specific attribute, or remove attributes by their code.
Available EAV commands:
eav:attribute:list: Lists EAV attributes.eav:attribute:view: Views the data for a specific attribute.eav:attribute:remove: Removes an attribute based on its attribute code.
Capabilities of n98-magerun2 for Developers and Admins
developn98-magerun2 is a command-line tool designed to automate and simplify tasks for Adobe Commerce, Magento, and Mage-OS environments. It serves different user roles through specific capabilities:
For Developers
- Cache & Index Management: Clean caches or reindex the store via CLI.
- Database Access: Execute direct SQL queries or manage database dumps.
- Code Scaffolding: Generate new modules, plugins, or controllers using templates.
- Admin & Customer Management: Create admin users or inspect customer data.
- Configuration: Modify system configuration values without using the Admin Panel.
For System Administrators & DevOps
- Automation: Designed for seamless integration into deployment and CI/CD pipelines.
- System Inspection: Check the status of caches, indexers, and system requirements.
- Hosting Support: Includes commands tailored for various hosting environments.
Extend n98-magerun2 with 3rd party modules
developYou can extend the core functionality of
n98-magerun2by installing third-party modules. These modules add specialized commands for security, performance, maintenance, and API discovery.Modules are categorized by their primary use case:
Account, security, and vulnerability
- bitExpert/magerun2-password-normalizer: Normalizes customer emails and passwords (Note: This module is archived/unmaintained).
- GetPageSpeed/n98-magerun2-module-getpagespeed: Provides convenience commands for performance and operations.
- qoliber/magerun: Provides theme compilation and performance helpers for development.
- hivecommerce/magerun2-list-api-endpoints: Lists all available API endpoints via the CLI.
- Hypernode/hypernode-magerun: Tailored for Hypernode-based Magento workflows.
- sansecio/magevulndb: Surfaces extensions with known security vulnerabilities.
Operations and maintenance
- elgentos/magerun2-addons: Helpers for database management, reindexing, and general day-to-day maintenance.
Performance review
- florinel-chis/n98-magerun2-performance-review: Performs automated performance reviews for Magento 2, Mage-OS, and Adobe Commerce, providing actionable recommendations.
Manage Magento gift cards with giftcard commands
developThegiftcardcommand group inn98-magerun2provides tools for automating and managing gift card workflows within a Magento store. You can use these commands to generate pools, create individual cards, inspect card details, and remove existing cards.Use Proxy Commands for bin/magento
developn98-magerun2 provides proxy commands that allow you to execute standard Magento 2bin/magentocommands through themagerun2CLI. This is useful for environments where you want to use the enhanced features ofmagerun2while still interacting with the core Magento command set. These commands are typically prefixed or mapped to ensure they are routed correctly through themagerun2execution engine.How configuration merging works in n98-magerun2
developn98-magerun2 uses a hierarchical configuration system that allows you to extend or overwrite built-in settings. Configurations are loaded from multiple levels and merged into a single configuration set.
When multiple configuration files define the same key, the value from the higher-precedence level wins. The merging order (from lowest to highest precedence) is:
- Built-in config: The default settings delivered with magerun.
- System level: Global settings for the entire machine.
- User level: Settings specific to the current user.
- Module level: Settings provided by specific modules.
- Project level: Settings specific to the Magento project being worked on.
Automate tasks with Script Commands
developn98-magerun2 provides ascriptcommand that allows you to automate repetitive tasks by running a sequence of multiple n98-magerun2 commands defined in a script file. Instead of executing commands manually one by one, you can consolidate them into a single file and execute them via thescriptcommand.Understand the n98-magerun2 configuration merge order
developn98-magerun2 merges configuration from multiple sources to allow for flexible overrides. Each subsequent level in the hierarchy can override values defined in the previous levels. The final configuration used by the tool is the result of this cumulative merge process.
The merge order is:
- Build-in config: The default configuration delivered with the magerun PHAR.
- System level config: Configuration applied at the system level.
- User level config: Configuration specific to the current user.
- Project level config: Configuration specific to the current Magento project.
Values defined in the Project level config have the highest priority and will override values from all other levels.
How Magento initialization works in n98-magerun2
developMagento initialization is a multi-step process managed by the
N98\Magento\Applicationclass to ensure the CLI tool operates within a valid Magento context. The process follows these stages:- Application Bootstrapping: The
Applicationclass (extending Symfony's Console Application) manages configuration, event dispatching, and initialization state. - Magento Detection: The
MagentoDetectorclass locates the installation by checking the current working directory, command-line options (e.g.,--root-dir), or specific environment variables. - Version Initialization: Based on the detection, either
Magento1InitializerorMagento2Initializeris used to bootstrap the correct version, setting up autoloaders and the Magento application context. - Helper and Event Setup: Helpers like
MagentoHelperand event listeners are initialized to provide integration points for commands.
- Application Bootstrapping: The
Requirements for packages in composer:redeploy-base-packages
developAny package you add to the
composer:redeploy-base-packageslist must contain a static file mapping in itscomposer.jsonfile to be correctly redeployed. This mapping is defined within theextra.mapkey."extra": { "map": [ [ ".editorconfig", ".editorconfig" ] ] }How Symfony CLI Command Events work
developSince n98-magerun2 is built on the Symfony Console component, you can hook into the CLI command lifecycle by listening to Symfony's built-in events. This allows you to modify input/output, perform cleanup, or handle errors without changing the command code itself.
Key Symfony events available:
ConsoleEvents::COMMAND: Dispatched before a command is executed. Use this to modify input/output or prevent execution.ConsoleEvents::TERMINATE: Dispatched after a command finishes. Use this for logging or cleanup.ConsoleEvents::ERROR: Dispatched if an exception occurs. Use this to handle or log errors.
```php use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\\