Skip to content

Implement hypernode:maps-generate command for Magento 2#4

Draft
dvershinin with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-e979dcf9-1e8a-43c8-88ed-a58625ddeefc
Draft

Implement hypernode:maps-generate command for Magento 2#4
dvershinin with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-e979dcf9-1e8a-43c8-88ed-a58625ddeefc

Conversation

Copilot AI commented Sep 30, 2025

Copy link
Copy Markdown

Overview

This PR implements the hypernode:maps-generate command for Magento 2, which is the equivalent of the n98-magerun hypernode:maps-generate command available for Magento 1.

What This Command Does

The hypernode:maps-generate command generates nginx map files for URL redirects by querying Magento 2's url_rewrite table. It extracts redirect entries (301 permanent and 302 temporary redirects) and formats them as nginx map configuration that can be used for efficient URL redirection at the web server level, improving performance by offloading redirect handling from Magento to nginx.

Usage

# Generate all redirects (301 and 302)
n98-magerun2 hypernode:maps-generate

# Generate redirects for a specific store ID
n98-magerun2 hypernode:maps-generate --store=1

# Generate only 301 permanent redirects
n98-magerun2 hypernode:maps-generate --type=301

# Save to a file for nginx configuration
n98-magerun2 hypernode:maps-generate > /etc/nginx/maps/magento-redirects.conf

Example Output

# Nginx map for URL redirects
# Generated by n98-magerun2 hypernode:maps-generate

# 301 redirects
map $request_uri $redirect_uri {
    default "";
    "/old-product.html" "/new-product.html";
    "/old-category.html" "/new-category.html";
}

Benefits

  1. Performance Improvement: Offloads redirect handling from Magento to nginx for significantly better performance
  2. Reduced Server Load: Handles redirects at the web server level instead of requiring PHP/Magento processing
  3. Scalability: Efficiently manages large numbers of URL rewrites without impacting application performance
  4. Hypernode Compatibility: Maintains compatibility with Hypernode hosting environment expectations

Implementation Details

  • Follows the same coding patterns as existing commands in the repository
  • Uses Magento's ObjectManager and ResourceConnection for proper database access
  • Includes proper SQL escaping and type casting for security
  • Supports filtering by store ID and redirect type (301/302)
  • Returns appropriate success/failure codes
  • Includes comprehensive documentation in README.md

Files Changed

  • src/GetPageSpeed/MapsGenerateCommand.php (NEW): Command implementation
  • n98-magerun2.yaml: Registered the new command
  • README.md: Added documentation and usage examples

Closes #[issue_number]

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • docs.hypernode.com
    • Triggering command: curl -s REDACTED (dns block)
  • https://api.github.com/search/code
    • Triggering command: curl -s REDACTED (http block)
  • support.hypernode.com
    • Triggering command: curl -s REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement maps-generate</issue_title>
<issue_description>Need an equivalent of n98-magerun hypernode:maps-generate, for Magento 2</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #2

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: dvershinin <250071+dvershinin@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement maps-generate Implement hypernode:maps-generate command for Magento 2 Sep 30, 2025
Copilot AI requested a review from dvershinin September 30, 2025 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement maps-generate

2 participants