2

I am trying to update an asset index from a plugin but can't seem to get it to work. Looking at the docs this seems to me like it should work but it does not. I am on the right path here?

$ses = craft()->assetIndexing->getIndexingSessionId();
craft()->assetIndexing->processIndexForSource($ses, null, 7);

7 is the id of the asset folder I want to re-index.

  • 1
    My guess is you're missing craft()->assetIndexing->getIndexListForSource($sessionId, $sourceId);. Check how the Asset Index Tool does it in craft/app/tools/AssetIndexTool.php. – Brad Bell Jul 22 '16 at 18:55
  • 1
    You are correct. I was not using it quite right and not understanding exactly how it worked. This is what I ended up with which works great for me. $ses = craft()->assetIndexing->getIndexingSessionId(); $src = craft()->assetIndexing->getIndexListForSource($ses, 7); for ($i = 1; $i <= $src['total']; $i++) { craft()->assetIndexing->processIndexForSource($ses, $i, 7); } – Trevor Orr Jul 22 '16 at 20:53
  • 1
    Awesome glad you got it sorted! Mind adding that as an official answer instead of a comment? Easier for other people that might have the same question to find. – Brad Bell Jul 23 '16 at 0:23
3

This is what I ended up with which works great for me.

$ses = craft()->assetIndexing->getIndexingSessionId(); 
$src = craft()->assetIndexing->getIndexListForSource($ses, 7); 

for ($i = 1; $i <= $src['total']; $i++) { 
    craft()->assetIndexing->processIndexForSource($ses, $i, 7); 
}
| improve this answer | |

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.