Skip to content

Commit 97c731a

Browse files
authored
Merge pull request #13039 from craftcms/feature/additional-list-volume-event-checks
check list of passed volumes on start indexing Resolves #12819
2 parents f372e8b + 2adbc45 commit 97c731a

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- Selectize menus now expand upwards when there’s not ample space below them. ([#12976](https://github.com/craftcms/cms/issues/12976))
77
- Element index bulk action spinners are now centered on the viewport. ([#12972](https://github.com/craftcms/cms/issues/12972))
88
- All control panel errors are new presented via error notifications rather than browser alerts. ([#13024](https://github.com/craftcms/cms/issues/13024))
9+
- Added `craft\utilities\AssetIndexes::volumes()`.
10+
- `craft\controllers\AssetIndexesController::actionStartIndexing()` now cross-references the selected volumes with those allowed by `craft\utilities\AssetIndexes::EVENT_LIST_VOLUMES` event handlers. ([#13039](https://github.com/craftcms/cms/pull/13039), [#12819](https://github.com/craftcms/cms/pull/12819))
911
- Fixed a bug where Assets fields weren’t respecting their View Mode setting when viewing entry revisions. ([#12948](https://github.com/craftcms/cms/issues/12948))
1012
- Fixed a bug where asset pagination was broken when there was more than 100 subfolders. ([#12969](https://github.com/craftcms/cms/issues/12969))
1113
- Fixed a bug where entry index pages’ “Revision Notes” and “Last Edited By” columns weren’t getting populated for disabled entries. ([#12981](https://github.com/craftcms/cms/issues/12981))

src/controllers/AssetIndexesController.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use craft\helpers\Json;
1414
use craft\i18n\Locale;
1515
use craft\models\AssetIndexingSession;
16+
use craft\models\Volume;
17+
use craft\utilities\AssetIndexes;
1618
use craft\web\Controller;
1719
use Throwable;
1820
use yii\web\BadRequestHttpException;
@@ -50,15 +52,20 @@ public function beforeAction($action): bool
5052
public function actionStartIndexing(): Response
5153
{
5254
$request = Craft::$app->getRequest();
53-
$volumes = (array)$request->getRequiredBodyParam('volumes');
55+
$volumeIds = (array)$request->getRequiredBodyParam('volumes');
5456
$cacheRemoteImages = (bool)$request->getBodyParam('cacheImages', false);
5557
$listEmptyFolders = (bool)$request->getBodyParam('listEmptyFolders', false);
5658

57-
if (empty($volumes)) {
59+
// Typecast volume IDs and filter out any disallowed volumes
60+
$volumeIds = array_map(fn($volumeId) => (int)$volumeId, $volumeIds);
61+
$allowedVolumeIds = array_map(fn(Volume $volume) => $volume->id, AssetIndexes::volumes());
62+
$volumeIds = array_intersect($volumeIds, $allowedVolumeIds);
63+
64+
if (empty($volumeIds)) {
5865
return $this->asFailure(Craft::t('app', 'No volumes specified.'));
5966
}
6067

61-
$indexingSession = Craft::$app->getAssetIndexer()->startIndexingSession($volumes, $cacheRemoteImages, $listEmptyFolders);
68+
$indexingSession = Craft::$app->getAssetIndexer()->startIndexingSession($volumeIds, $cacheRemoteImages, $listEmptyFolders);
6269
$sessionData = $this->prepareSessionData($indexingSession);
6370

6471
$data = ['session' => $sessionData];

src/utilities/AssetIndexes.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use craft\events\ListVolumesEvent;
1313
use craft\helpers\Html;
1414
use craft\i18n\Locale;
15+
use craft\models\Volume;
1516
use craft\web\assets\assetindexes\AssetIndexesAsset;
1617
use yii\base\Event;
1718

@@ -54,19 +55,29 @@ public static function iconPath(): ?string
5455
}
5556

5657
/**
57-
* @inheritdoc
58+
* Returns all of the available volumes for indexing.
59+
*
60+
* @return Volume[]
61+
* @since 4.4.6
5862
*/
59-
public static function contentHtml(): string
63+
public static function volumes(): array
6064
{
6165
// Fire a 'listVolumes' event
6266
$event = new ListVolumesEvent([
6367
'volumes' => Craft::$app->getVolumes()->getAllVolumes(),
6468
]);
65-
Event::trigger(self::class, self::EVENT_LIST_VOLUMES, $event,);
69+
Event::trigger(self::class, self::EVENT_LIST_VOLUMES, $event);
70+
return $event->volumes;
71+
}
6672

73+
/**
74+
* @inheritdoc
75+
*/
76+
public static function contentHtml(): string
77+
{
6778
$volumeOptions = [];
6879

69-
foreach ($event->volumes as $volume) {
80+
foreach (static::volumes() as $volume) {
7081
$volumeOptions[] = [
7182
'label' => Html::encode($volume->name),
7283
'value' => $volume->id,

0 commit comments

Comments
 (0)