Skip to content

Conversation

addison74
Copy link
Contributor

@addison74 addison74 commented Oct 4, 2025

Add CLI script for managing the admin notifications with advanced filtering

This PR introduces a shell CLI script (shell/notifications.php) for advanced management of the admin notifications.

Features

  • Advanced filtering:

    • Filter notifications by date (--before YYYY-MM-DD)
    • Filter by severity (--severity-0, --severity-1, --severity-2, --severity-3)
    • Filter by read status (--only-read, --include-unread)
    • Combine multiple filters for precise targeting
  • Preview mode (--dry-run):

    • See exactly which notifications would be deleted before any destructive action
    • Table-style output with severity labels and read status
  • Protection for unread notifications:

    • Unread notifications are protected by default and will not be deleted unless --include-unread is specified
    • If --all is used without --include-unread, the script aborts and displays a clear error message, including the count of unread notifications
  • Safe bulk deletion:

    • Bulk delete all notifications only if explicitly allowed (--all --include-unread)
    • Prevents accidental data loss
  • Flexible deletion and preview:

    • Delete or preview only read notifications, only certain severities, or notifications before a specific date
  • Clear error reporting and usage instructions:

    • Error messages provide explicit information about unread notifications and safe delete instructions

Usage examples

# Preview (dry-run) all read notifications
php shell/notifications.php --dry-run

# Preview all notifications, including unread
php shell/notifications.php --include-unread --dry-run

# Delete only read notifications
php shell/notifications.php

# Delete all notifications, including unread (requires explicit confirmation)
php shell/notifications.php --all --include-unread

# Attempt to delete all notifications WITHOUT --include-unread
php shell/notifications.php --all
# > ERROR: Cannot delete ALL notifications unless --include-unread is specified!
# > There are X unread notifications present in the database. Unread notifications are protected by default.
# > To delete all notifications, including unread, use:
# >   php shell/notifications.php --all --include-unread

# Filter by severity and date (only read notifications by default)
php shell/notifications.php --before 2024-01-01 --severity-0 --dry-run

# Delete only read notifications with severity Critical
php shell/notifications.php --severity-1

Important

  • For CLI options with values, use a space (not =): --before 2024-01-01
  • When scheduled as a cronjob, this script enables automated and safe cleanup of admin notifications, ensuring that unread messages are never deleted unintentionally and keeping your Magento backend organized without manual intervention.
screenshot

@Copilot Copilot AI review requested due to automatic review settings October 4, 2025 18:03
@github-actions github-actions bot added the shell Relates to shell scripts label Oct 4, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new CLI shell script for managing admin notifications in OpenMage with advanced filtering and safety features. The script provides comprehensive functionality for cleaning up notifications while protecting unread messages by default.

Key changes:

  • New shell CLI script with advanced filtering options (date, severity, read status)
  • Built-in protection for unread notifications with explicit override requirement
  • Dry-run preview mode with tabular output for safe operation verification

Copy link

sonarqubecloud bot commented Oct 4, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shell Relates to shell scripts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant