# Does OpenMage Image Cleaner Handle the wysiwyg/swatches Folder for Configurable Swatches?

> OpenMage Image Cleaner safely handles the media/wysiwyg/swatches folder for configurable swatches preventing accidental image deletion. Learn how.

- Repository: [Fabrizio Balliano/openmage-image-cleaner](https://github.com/fballiano/openmage-image-cleaner)
- Tags: how-to-guide
- Published: 2026-03-01

---

**Yes, OpenMage Image Cleaner explicitly preserves images in `media/wysiwyg/swatches/` whenever Configurable Swatches are enabled, automatically marking them as "used" to prevent accidental deletion.**

The `fballiano/openmage-image-cleaner` extension scans your Magento media directory to identify unused images, but it includes specific safeguards for Configurable Swatches. When the Configurable Swatches module is active, the cleaner treats the `wysiwyg/swatches` directory as protected territory, ensuring swatch images remain intact during cleanup operations.

## How the Extension Protects Swatch Images

Inside the `syncwysiwygAction` method of the admin controller, the extension evaluates whether Configurable Swatches are enabled before determining which WYSIWYG images are safe to remove.

According to the source code in [`app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php`](https://github.com/fballiano/openmage-image-cleaner/blob/main/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php), the cleaner retrieves the system configuration flag at line 81:

```php
$swatches_enabled = Mage::getStoreConfigFlag('configswatches/general/enabled');

```

If this flag returns `true`, any filesystem image matching the pattern `wysiwyg/swatches/*` is automatically added to the used images array. This logic appears at lines 81-87 in the controller:

```php
if ($swatches_enabled && fnmatch('wysiwyg/swatches/*', $fs_image)) {
    $used_images[] = $fs_image;               // <‑‑ treat as "used"
}

```

By pushing these files into the `$used_images` array, the extension ensures they are excluded from the "unused" list and never presented for deletion in the admin interface.

## Running the WYSIWYG Cleanup Process

You can trigger the swatch-aware cleanup through the admin panel or programmatically depending on your workflow requirements.

### Via the Admin Panel

The "Sync WYSIWYG" button on the Image Cleaner grid invokes the `syncwysiwygAction` method. When clicked, the controller executes the full scan while applying the Configurable Swatches protection rule.

```php
// URL pattern generated by the admin button
$url = '*/*/syncwysiwyg';   // triggers the protective scan

```

### Programmatically via PHP

For automated scripts or cron jobs, instantiate the controller directly and execute the action:

```php
$controller = new Fballiano_ImageCleaner_Adminhtml_FbimagecleanerController(
    Mage::app()->getRequest(),
    Mage::app()->getResponse()
);
$controller->syncwysiwygAction();   // scans wysiwyg, preserves swatch images if enabled

```

### Verifying Swatch Protection Status

To confirm whether your swatch images will be preserved before running a cleanup, check the configuration flag manually:

```php
$swatchesEnabled = Mage::getStoreConfigFlag('configswatches/general/enabled');
if ($swatchesEnabled) {
    echo "Configurable Swatches are active – wysiwyg/swatches will be preserved.";
}

```

## Key Source Files and Components

The swatch protection mechanism relies on these specific components within the repository:

- **[`app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php`](https://github.com/fballiano/openmage-image-cleaner/blob/main/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php)** – Contains the `syncwysiwygAction` method (lines 81-87) that implements the `fnmatch('wysiwyg/swatches/*')` logic and the `configswatches/general/enabled` configuration check.

- **[`app/code/community/Fballiano/ImageCleaner/Helper/Data.php`](https://github.com/fballiano/openmage-image-cleaner/blob/main/app/code/community/Fballiano/ImageCleaner/Helper/Data.php)** – Provides `getMediaDirByEntityTypeId()` and `scandirRecursive()` utilities that the controller uses to locate and scan media files.

- **[`app/code/community/Fballiano/ImageCleaner/Block/Adminhtml/Image.php`](https://github.com/fballiano/openmage-image-cleaner/blob/main/app/code/community/Fballiano/ImageCleaner/Block/Adminhtml/Image.php)** – Renders the "Sync WYSIWYG" button in the admin grid, serving as the UI entry point that triggers the controller action.

- **[`app/code/community/Fballiano/ImageCleaner/etc/system.xml`](https://github.com/fballiano/openmage-image-cleaner/blob/main/app/code/community/Fballiano/ImageCleaner/etc/system.xml)** – Defines the configuration structure for the WYSIWYG sync options, clarifying that the root directory is `media`.

## Summary

- **OpenMage Image Cleaner specifically handles `wysiwyg/swatches`** by checking if Configurable Swatches are enabled via `Mage::getStoreConfigFlag('configswatches/general/enabled')`.
- **Pattern matching protection** uses `fnmatch('wysiwyg/swatches/*', $fs_image)` to identify and preserve swatch images.
- **Files are marked as used** by adding them to the `$used_images` array within the `syncwysiwygAction` method, preventing their deletion.
- **Protection applies automatically** whenever the Configurable Swatches module is active, requiring no manual configuration of the Image Cleaner extension.

## Frequently Asked Questions

### How does OpenMage Image Cleaner know if Configurable Swatches are enabled?

The extension queries the Magento configuration flag `configswatches/general/enabled` using `Mage::getStoreConfigFlag()` at the beginning of the `syncwysiwygAction` method. When this returns true, the cleaner activates special handling for the `wysiwyg/swatches` directory.

### Will swatch images be deleted if I disable Configurable Swatches?

If you disable Configurable Swatches in the system configuration (`configswatches/general/enabled = false`), the protection rule no longer applies. During the next WYSIWYG sync, images in `media/wysiwyg/swatches/` will be evaluated normally and may be marked as unused if not referenced elsewhere, making them eligible for deletion.

### Can I manually verify which files are protected before running a cleanup?

Yes. You can instantiate the controller or check the configuration flag programmatically to verify protection status. The extension uses standard Magento configuration accessors, so `Mage::getStoreConfigFlag('configswatches/general/enabled')` will indicate whether the swatch directory is currently protected.

### Where is the swatch protection logic located in the source code?

The specific logic resides in [`app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php`](https://github.com/fballiano/openmage-image-cleaner/blob/main/app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php) within the `syncwysiwygAction` method, specifically around lines 81-87, where the code checks the configuration flag and applies `fnmatch()` to identify swatch images.