4

I'm trying to index some asset volumes that I'm creating in a migration. These are local volumes which may already contain files.

I'm hoping to avoid the step where I have to manually update the asset indices after creating volumes.

The following code does not seem to perform the index, am I missing a step? I've studied the controller used by Utilities but I can't see where I'm going wrong.

    $volumeId = Craft::$app->volumes->getVolumeByHandle('myVolume')->id;

    $indexer = Craft::$app->getAssetIndexer();

    $sessionId = $indexer->getIndexingSessionid();

    $indexer->processIndexForVolume($sessionId,$volumeId);

Any help is much appreciated

  • Did you ever find a solution to this? – ryanpcmcquen Dec 6 '18 at 17:57
  • Hey, no I never did. I've tried digging through the services Craft itself uses for this but I don't have enough experience with that side of the application to extract anything of use. It would be nice if there was a service you could just hit but it doesn't appear to be that simple. – Piaras Hoban Dec 11 '18 at 10:19
  • Have you tried downloading and reverse engineering plugins that need to do something similar? I tend to start there when there isn't clear documentation or SO questions to help me out. Check out the plugin store and see if asset related plugins have Craft 2 versions. The Craft 3 version would likely need to do some migrations. – Indigo Viking Dec 14 '18 at 16:10
2

As of 3.1.2 you can now index assets via the cli tool:

./craft index-assets/all 

OR

./craft index-assets/one {handle}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.