# PSP Reset Images — One-Off Cleanup

## What it does

Deletes squared/cropped product images from Cloudflare R2 and resets the PSP
image fetch state so the scraper will re-download fresh uncropped images.

**Background:** The product image FileUpload had `->imageCropAspectRatio('1:1')`
which caused FilePond (browser-side) to crop every image to a square before
uploading. This was removed in July 2026. This command cleans up the bad images
already in storage.

---

## When to run

- After deploying the `imageCropAspectRatio` fix to a new environment
- If you suspect product images have been stored as squares/cropped on a server
  that hasn't been cleaned yet

---

## Steps

### 1. Dry run first

Always check what will be affected before deleting anything:

```bash
php artisan psp:reset-images --dry-run
```

This lists every file that would be deleted without making any changes.

### 2. Test on a single SKU (optional)

```bash
php artisan psp:reset-images --sku=ERR3340
```

Then check that product in the admin — its image should be gone and the PSP
Product Data page should show it under "No Image".

### 3. Full reset

```bash
php artisan psp:reset-images
```

This will:
- Find all products linked to Allmakes as a supplier that have stored images
- Delete each image file from R2
- Set `images = null` on the product
- Set `image_fetched_at = null` in `allmakes_psp_results` so the scraper
  will re-download

Progress bar shows `processed/total`. On ~18k products this takes several
minutes. Final output confirms files deleted and products reset.

### 4. Re-scrape images

Go to **Connectors → Allmakes PSP → Product Data** and click **Fetch Images**.

The scraper will re-download a fresh, uncropped image for every product that
was reset. Monitor progress on the same page — the "Has Image" stat will climb
as it runs.

---

## Checking progress

While the command runs, refresh the PSP Product Data page to watch the
**No Image** count rise. It updates on the 30s poll or with a hard refresh
(`Ctrl+Shift+R`).

After the command finishes and the image fetch completes, **Has Image** should
be back up to roughly where it started, but with correct non-cropped images.

---

## Files involved

| File | Purpose |
|------|---------|
| `plugins/webkul/allmakes-psp/src/Console/ResetPspImagesCommand.php` | The command itself |
| `plugins/webkul/allmakes-psp/src/AllmakesPspServiceProvider.php` | Registers the command |
| `plugins/webkul/inventories/src/Filament/Clusters/Products/Resources/ProductResource.php` | Root cause fix (crop removed) |
| `plugins/webkul/products/src/Filament/Resources/ProductResource.php` | Root cause fix (crop removed) |

---

## Safe to re-run

The command skips products that already have `images = null`, so it is safe
to run multiple times. If the image scrape is interrupted partway through,
re-running `psp:reset-images` will only reset products that still have images
(i.e. ones the scraper hasn't re-fetched yet).
