Skip to content

Commit

Permalink
Merge pull request #1 from vaersaagod/feature/purge-command
Browse files Browse the repository at this point in the history
Feature/purge command
  • Loading branch information
mmikkel authored Jan 15, 2024
2 parents 8c7642d + 80c1fb6 commit c6416d1
Show file tree
Hide file tree
Showing 7 changed files with 609 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# AssetMate Changelog

## 2.4.0 - 2024-01-15
### Added
- Added the `assetmate/purge` CLI command for bulk-deleting unused assets
- Added the `assetmate/purge/folders` CLI command for bulk-deleting empty folders

## 2.3.2 - 2023-09-28
### Fixed
- Fixed an issue where AssetMate could cause a type related PHP exception for assets without a volume (temporary files)
Expand Down
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,47 @@ return [
];
```

## Console commands

AssetMate adds a couple of asset-related CLI utility commands:

### Purging "unused" assets

An "unused" asset is an asset that isn't a *target* in any element relations, and that is not found in any reference tags in the database content tables.

To delete all unused assets:

`php craft assetmate/purge`

#### Options

##### `--volume` (string, default '*')
Only purge assets in a specific volume, e.g. `php craft assetmate/purge --volume=images`

##### `--kind` (string, default '*')
Only purge assets with a specific file kind, e.g. `php craft assetmate/purge --kind=image`

##### `--lastUpdatedBefore` (string|int|bool, default 'P30D')
By default, AssetMate will not purge assets with a `dateUpdated` timestamp later than 30 days ago. This option can be set to an integer (i.e. number of seconds), a valid PHP date interval string, or `false` to disable the `dateUpdated` check entirely.

##### `--searchContentTables` (bool, default `true`)
In addition to checking the `relations` table, AssetMate will search content tables for non-relation asset uses (e.g. reference tags in rich text fields). This can take a long time if there are a lot of assets and/or content; set this option to `false` to bypass content table searching.

##### `--purgeEmptyFolders` (bool, default `true`)
If `true`, AssetMate will automatically purge empty folders after purging unused assets (if the `--volume` option is used, only empty folders in that volume will be deleted).

### Purging empty folders

An empty folder is a folder that doesn't contain any assets (or any sub folders that contain assets).

To delete all empty folders:

`php craft assetmate/purge/folders`

#### Options

##### `--volume` (string, default '*')
Only delete empty folders in a specific volume, e.g. `php craft assetmate/purge/folders --volume=images`

---

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vaersaagod/assetmate",
"description": "Protect your assets, mate!",
"type": "craft-plugin",
"version": "2.3.2",
"version": "2.4.0",
"keywords": [
"craft",
"cms",
Expand Down
4 changes: 4 additions & 0 deletions src/AssetMate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

namespace vaersaagod\assetmate;

use craft\base\Element;
use craft\base\Plugin;
use craft\elements\Asset;
use craft\events\AssetEvent;
use craft\events\DefineHtmlEvent;
use craft\helpers\App;
use craft\log\MonologTarget;

use Psr\Log\LogLevel;

use vaersaagod\assetmate\helpers\CpHelper;
use vaersaagod\assetmate\models\Settings;
use vaersaagod\assetmate\services\Convert;
use vaersaagod\assetmate\services\Resize;
Expand Down Expand Up @@ -91,6 +94,7 @@ function (AssetEvent $event) {
$this->resize->maybeResize($asset);
}
);

}

// Protected Methods
Expand Down
Loading

0 comments on commit c6416d1

Please sign in to comment.