Maintenance

How to clean up a PrestaShop store without breaking anything: step-by-step scans and a restorable quarantine

A PrestaShop store that has been running for a few years piles up gigabytes nobody uses: old cache, thumbnails for image formats that no longer exist, photos of deleted products, forgotten backups and statistics tables with millions of rows. Hosting runs short and backups take longer and longer. Cleaning it by hand is risky, which is why we built Shop Cleaner.

Why it is not trivial in PrestaShop

  • Not everything that looks like junk is junk. An image in the wrong place may be orphaned or may belong to a product that is still live. A folder in /modules with no record may be leftovers or something the merchant wants to keep.
  • Deleting rows by hand leaves inconsistencies. A customer or a product has data spread across many tables, and other modules expect to be told when they are removed.
  • Hosting providers cut long requests. Walking through hundreds of thousands of images does not fit in the 30 seconds a shared server usually allows.
  • Database space does not always return to disk when rows are deleted, and optimising a table does not always free anything.
  • Each PrestaShop version stores cache and images in different places, from 1.6 to 9.

The approach: separate what regenerates from what does not

The core decision was to classify every clean-up category by risk. What PrestaShop recreates on its own (cache, compiled templates, combined CSS and JS, temporary images, old logs) is deleted. Everything else (thumbnails with no format, orphaned images, backups, customer or product records and module folders) first goes into a restorable quarantine that purges itself after 30 days.

Technical decisions

A scan that resumes

The scan is split into steps and saves its state, including the exact position inside the folder it is walking. Each request works for a few seconds and the next one carries on where it stopped, from the dashboard or from a scheduled task. A database lock prevents two requests from advancing the same scan at once. It works the same on a dedicated server as on the most limited hosting.

Delete through the core, not behind its back

Records are removed with PrestaShop's own delete methods, so other modules' hooks run and the store stays consistent. Beforehand, the module finds every related row in any table that uses the standard key columns, including those of other modules, and saves them together with the product images. Restoring inserts them again, and refuses if the identifier is already taken by another record.

Safety in every action

The form only sends the name of the category to clean, never paths or identifiers, and module names are checked against a fresh scan. The quarantine folder denies web access.

Measure before promising

The dashboard shows how much can be recovered, which folders and tables weigh most and how much has been recovered each month, with charts built in plain CSS. The back office notice reads totals that are already stored, so it adds no cost to any page. Limitations are documented too: InnoDB sizes are estimates, and tables whose free space would not return to disk after optimising are left out.

What we learned

In maintenance, the value is not in deleting a lot but in being able to undo. Knowing where each PrestaShop version keeps its files and how its tables relate is what makes it possible to clean with confidence, and it is the same knowledge we apply when we maintain, audit or upgrade stores.

What this development demonstrates

  • Knowledge of PrestaShop file and table structure from 1.6 to 9
  • Long processes split into resumable steps, suitable for any hosting
  • Consistent deletion through the core, respecting other modules' hooks
  • Restorable copies of related data before every change
  • Concurrency control in scheduled tasks
  • Strict validation of everything sent from the back office