OpenMage Image Cleaner Custom Product Image Attributes: Beyond the Default Media Gallery

Yes, OpenMage Image Cleaner automatically detects and processes custom product image attributes by querying all EAV attributes with frontend_input='media_image', not just the default media gallery.

OpenMage Image Cleaner is a maintenance utility for OpenMage (Magento 1) that identifies orphaned product images. While many assume it only scans the standard media gallery, the extension fully supports OpenMage Image Cleaner custom product image attributes through its dynamic attribute detection mechanism in the syncproduct routine.

How OpenMage Image Cleaner Detects Custom Product Image Attributes

The extension does not hardcode checks for the default media_gallery attribute. Instead, it dynamically discovers all product attributes that store image references by querying the EAV attribute table for the specific frontend input type.

This approach ensures that any custom attribute you create—whether it is brand_logo, secondary_image, or lifestyle_photo—is automatically included in the cleanup scan, provided it uses the Media Image input type.

The Attribute Query Logic in FbimagecleanerController

The detection logic resides in controllers/Adminhtml/FbimagecleanerController.php within the syncproductAction method. Lines 79-81 execute a SQL query to collect all relevant attribute IDs:

$attributes = $db->fetchCol(
    "SELECT attribute_id FROM {$resource->getTableName('eav_attribute')} " .
    "WHERE entity_type_id={$entity_type_id} AND frontend_input='media_image'"
);

This query filters for frontend_input='media_image', which is the definitive marker for image-upload attributes in Magento's EAV system. The resulting attribute IDs are then used to fetch values from the product entity tables, and those values are compared against the actual files present in media/catalog/product to identify orphans.

Creating Custom Product Image Attributes for OpenMage Image Cleaner

To ensure your custom attributes are recognized by the cleaner, you must define them with the correct input type during installation. The attribute must use media_image as its frontend input and typically requires the catalog/product_attribute_backend_image backend model to handle file uploads.

Here is an example setup script that creates a custom brand_logo attribute:

$installer = $this;
$installer->startSetup();

$installer->addAttribute('catalog_product', 'brand_logo', [
    'type'               => 'varchar',
    'label'              => 'Brand Logo',
    'input'              => 'media_image',   // Required for cleaner detection
    'required'           => false,
    'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible'            => true,
    'user_defined'       => true,
    'backend'            => 'catalog/product_attribute_backend_image',
]);

$installer->endSetup();

Once this attribute is installed and populated with images, the OpenMage Image Cleaner will automatically include brand_logo values in its synchronization routine without requiring any configuration changes.

Limitations and Scope of Image Detection

While the cleaner is thorough regarding product attributes, it operates within specific constraints defined by the attribute metadata.

  • Media Image Type Only: The SQL query explicitly filters for frontend_input='media_image'. Attributes using other input types—such as text, textarea, or custom frontend inputs—are ignored, even if they store image paths as strings.
  • Category Images: For category entities, the cleaner uses a similar but distinct query targeting frontend_input='image'. This is separate from the product logic and does not affect custom product attribute detection.
  • File System Scope: The comparison is made against files physically present under media/catalog/product. Images stored in external CDNs or custom directories outside this path are not evaluated.

Running the Cleaner on Custom Attributes

After creating custom image attributes, you can trigger the scan using either the administrative interface or programmatically via PHP.

Admin Panel Method

  1. Log into the OpenMage admin dashboard.
  2. Navigate to System → Tools → Image Cleaner.
  3. Click the "Sync Product" button. The controller will execute the attribute query, gather values from all media_image attributes (including your custom ones), and identify unused files.

Programmatic Invocation

For automated maintenance via cron jobs or custom scripts, instantiate the controller and call the synchronization action directly:

$controller = new Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController();
$controller->syncproductAction();   // Triggers full scan including custom attributes

This executes the same logic as the admin button, querying all media_image attributes and comparing them against the file system.

Summary

  • Dynamic Detection: OpenMage Image Cleaner detects custom product image attributes by querying the EAV table for all attributes with frontend_input='media_image', not just the default gallery.
  • Automatic Inclusion: Any custom attribute created with the Media Image input type (e.g., brand_logo, lifestyle_image) is automatically scanned for orphaned files without manual configuration.
  • Implementation Location: The core logic resides in controllers/Adminhtml/FbimagecleanerController.php at lines 79-81 within the syncproductAction method.
  • Scope Limitation: Only attributes explicitly defined as media_image are processed; text fields or other input types storing image paths are ignored.

Frequently Asked Questions

Does OpenMage Image Cleaner detect category image attributes?

Yes, but it uses a different input type filter. While product attributes are queried with frontend_input='media_image', category attributes are queried with frontend_input='image'. The cleaner handles these separately in distinct synchronization routines, so custom category image attributes are supported provided they use the standard image input type for categories.

What happens if my custom attribute uses a different input type?

If your custom attribute stores an image path but uses an input type other than media_image (such as text or textarea), the OpenMage Image Cleaner will not detect it. The SQL query in syncproductAction explicitly filters for frontend_input='media_image'. To include such attributes, you must either change the input type to media_image or extend the cleaner's logic to include additional input types.

Can I exclude specific custom image attributes from the scan?

The current implementation in Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController does not provide a configuration option to exclude specific attributes from the syncproduct routine. The query selects all attributes with frontend_input='media_image' indiscriminately. If you need to exclude specific attributes (for example, a legacy attribute you no longer maintain), you would need to override the controller and modify the SQL query to add an attribute_id NOT IN (...) clause.

How does the cleaner handle image paths in custom attributes?

The cleaner retrieves the raw values stored in custom media_image attributes (which are typically relative paths like /b/r/brand_logo.jpg) and compares them against the actual file list generated by Helper/Data.php's scandirRecursive() method. If a path exists in the database attribute value but the corresponding file is missing from media/catalog/product, or vice versa, the cleaner identifies the discrepancy. The comparison is literal path matching, so custom attributes must store paths in the same format as standard gallery images to be recognized correctly.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →