> For the complete documentation index, see [llms.txt](https://docs.norrnext.com/norrcompetition/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.norrnext.com/norrcompetition/plugins/norrcompetition-media-cleanup.md).

# NorrCompetition Media Cleanup

Automated disk space management and Remote Storage offloading for completed contests via Joomla Scheduled Tasks.

### 1. Getting Started

**Task - NorrCompetition Media Cleanup** (`plg_task_nccleanup`) is a Joomla Scheduled Task plugin that automates disk space optimization for **completed contests** in NorrCompetition.

When contestants upload photos to a contest, NorrCompetition stores the unmodified original file (`orig_*`) alongside several resized display variants (`big_`, `med_`, `small_`, `thumb_`). While a contest is active, keeping the original image and local copies on the server is useful for re-cropping, regenerating image sizes, or fast local delivery. Once a contest is completed (`Completed` status), these extra files can consume significant disk space.

The plugin provides two independent scheduled tasks that you can use separately or together:

1. **NorrCompetition - Purge Original Photos (Completed Contests)** — deletes only the heavy unmodified original image files (`orig_*`) for completed contests while keeping all resized display variants (`small_`, `med_`, `big_`, `thumb_`) on your server so contest and entry pages continue to work locally without changes.
2. **NorrCompetition - Delete Local Files Synced to Remote Storage (Completed Contests)** — designed for sites using [Remote Storage](https://docs.norrnext.com/norrcompetition/remote-storage/general-information.md) (such as AWS S3) with **Delete Local Files** set to **No** in the component options. It keeps files locally while a contest is active and automatically deletes local copies after the contest is completed (verifying or syncing them to Remote Storage first), seamlessly switching completed contests to Remote Storage URLs.

{% hint style="info" %}
**Requirements:** This plugin requires **NorrCompetition 3.1.0** or higher, **Joomla 5.4** or higher, and **PHP 8.2** or higher.
{% endhint %}

***

### 2. Installation

1. In the Joomla Administrator Panel, go to **System > Install > Extensions** and upload the plugin package (`plg_task_nccleanup`).
2. Go to **System > Manage > Plugins**, search for **Task - NorrCompetition Media Cleanup**, and **enable** the plugin.

***

### 3. Setting Up a Scheduled Task

After enabling the plugin, configure one or both cleanup routines in Joomla's Task Scheduler:

1. Go to **System > Manage > Scheduled Tasks**.
2. Click **New** in the toolbar.
3. Select one of the two NorrCompetition task types described below.
4. Set the **Title**, execution schedule (for example, once every 12 or 24 hours), and task parameters under the **Task Parameters** tab.
5. Save and close the task.

***

### 4. Available Task Types

#### 4.1. NorrCompetition - Purge Original Photos (Completed Contests)

Deletes local unmodified original image files (`orig_*`) for **completed contests** while preserving all resized display images (`small_`, `med_`, `big_`, `thumb_`).

* **Typical disk space savings:** **70%–85%** per completed contest without requiring external cloud storage.
* **Safety checks:**
  * Only processes contests with the **Completed** status whose end date is older than the configured **Grace Period (Days)**.
  * Verifies that at least one resized display variant (`big_`, `med_`, or `small_`) exists in the entry folder before deleting `orig_*`.
  * Automatically skips **animated GIFs** (`orig_*.gif`), because animated GIFs are served directly from the original file to preserve animation frames.

{% hint style="warning" %}
Once original `orig_*` files are deleted for a completed contest, you will no longer be able to re-crop those entry photos in the backend. All frontend views (contest grid, entry page, lightbox, and gallery thumbnails) remain completely unaffected.
{% endhint %}

#### 4.2. NorrCompetition - Delete Local Files Synced to Remote Storage (Completed Contests)

Deletes local entry media files for **completed contests** after verifying that the files exist in [Remote Storage](https://docs.norrnext.com/norrcompetition/remote-storage/general-information.md) (e.g. Amazon S3).

This task is ideal when you want a **hybrid storage lifecycle**:

1. In **Components > NorrCompetition > Options > General > Remote Storage Options**, set **Remote Storage** to **Yes** and **Delete Local Files** to **No**.
2. While a contest is **Active**, entry photos are synced to Remote Storage as a backup, but local copies remain on your web server for fast local image processing and re-cropping.
3. After the contest is **Completed** and the configured **Grace Period (Days)** has passed, this scheduled task verifies that every file is present in Remote Storage (and optionally uploads any unsynced files if **Auto-Sync Unsynced Entries Before Deletion** is enabled) before deleting the local copies.
4. As soon as the local files are removed, NorrCompetition automatically serves those images directly from your Remote Storage / CDN URL.

***

### 5. Task Parameters

Both scheduled tasks share common execution settings under the **Task Parameters** tab:

| Parameter                                                                   | Default | Description                                                                                                                                                                                                                                                                                                                                                                          |
| --------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Grace Period (Days)**                                                     | `7`     | Number of days after a contest is completed (`End Date`) before its local files become eligible for cleanup. Set to `0` to process any completed contest immediately after completion.                                                                                                                                                                                               |
| **Auto-Sync Unsynced Entries Before Deletion** *(Remote Storage task only)* | `Yes`   | If enabled, local files of completed contests that are not yet present in Remote Storage will be automatically uploaded to Remote Storage first before deleting the local copies. If disabled, only files already confirmed in Remote Storage will be deleted locally.                                                                                                               |
| **Batch Limit (Entries per Run)**                                           | `50`    | Maximum number of entry folders from completed contests to process during a single task execution. When a batch limit is reached, the task returns a resume status (`WILL_RESUME`) so Joomla's scheduler automatically continues processing the remaining entries in subsequent runs, and marks cleaned entries in the database so already-cleaned contests are never scanned again. |
| **Clean Temporary & Empty Folders** *(Remote Storage task only)*            | `Yes`   | If enabled, removes expired temporary upload files in `photos/tmp` (older than 1 hour) and deletes empty entry and contest directories after offloading files to Remote Storage.                                                                                                                                                                                                     |

***

### 6. Download Key (One-Click Updates)

In the plugin settings (**System > Manage > Plugins > Task - NorrCompetition Media Cleanup**), open the **Download Key** tab and enter your NorrNext Download Key to receive one-click updates via the Joomla Update System.

Read the official tutorial: [How to enable one-click update for NorrNext commercial extensions](https://docs.norrnext.com/joomla-tutorials/how-to-enable-one-click-update-for-norrnext-commercial-extensions).
