n98-magerun2 Documentation

repository·develop·Indexed 21 days ago

https://github.com/netz98/n98-magerun2

A 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.

Tokens
100.8K
Snippets
432
Records
547
Agent score
74%

What's inside n98-magerun2

  1. Manage EAV attributes with n98-magerun2

    develop

    n98-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.
  2. Capabilities of n98-magerun2 for Developers and Admins

    develop

    n98-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.
  3. Extend n98-magerun2 with 3rd party modules

    develop

    You can extend the core functionality of n98-magerun2 by 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.
  4. Use Proxy Commands for bin/magento

    develop
    n98-magerun2 provides proxy commands that allow you to execute standard Magento 2 bin/magento commands through the magerun2 CLI. This is useful for environments where you want to use the enhanced features of magerun2 while still interacting with the core Magento command set. These commands are typically prefixed or mapped to ensure they are routed correctly through the magerun2 execution engine.
  5. How configuration merging works in n98-magerun2

    develop

    n98-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:

    1. Built-in config: The default settings delivered with magerun.
    2. System level: Global settings for the entire machine.
    3. User level: Settings specific to the current user.
    4. Module level: Settings provided by specific modules.
    5. Project level: Settings specific to the Magento project being worked on.
  6. Understand the n98-magerun2 configuration merge order

    develop

    n98-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:

    1. Build-in config: The default configuration delivered with the magerun PHAR.
    2. System level config: Configuration applied at the system level.
    3. User level config: Configuration specific to the current user.
    4. 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.

  7. How Magento initialization works in n98-magerun2

    develop

    Magento initialization is a multi-step process managed by the N98\Magento\Application class to ensure the CLI tool operates within a valid Magento context. The process follows these stages:

    1. Application Bootstrapping: The Application class (extending Symfony's Console Application) manages configuration, event dispatching, and initialization state.
    2. Magento Detection: The MagentoDetector class locates the installation by checking the current working directory, command-line options (e.g., --root-dir), or specific environment variables.
    3. Version Initialization: Based on the detection, either Magento1Initializer or Magento2Initializer is used to bootstrap the correct version, setting up autoloaders and the Magento application context.
    4. Helper and Event Setup: Helpers like MagentoHelper and event listeners are initialized to provide integration points for commands.
  8. How Symfony CLI Command Events work

    develop

    Since 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\\