<p>This is what I ended up with which works great for me. </p>

<pre><code>$ses = craft()-&gt;assetIndexing-&gt;getIndexingSessionId(); 
$src = craft()-&gt;assetIndexing-&gt;getIndexListForSource($ses, 7); 

for ($i = 1; $i &lt;= $src['total']; $i++) { 
    craft()-&gt;assetIndexing-&gt;processIndexForSource($ses, $i, 7); 
}
</code></pre>

CC BY-SA 3.0
2016-07-23T13:24:57.543Z
2016-07-23T13:24:57.543Z
Trevor Orr
<p>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?</p>

<pre><code>$ses = craft()-&gt;assetIndexing-&gt;getIndexingSessionId();
craft()-&gt;assetIndexing-&gt;processIndexForSource($ses, null, 7);
</code></pre>

<p>7 is the id of the asset folder I want to re-index.</p>

CC BY-SA 3.0
2016-07-22T18:55:09.587Z
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
CC BY-SA 3.0
2016-07-22T20:53:42.270Z
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
CC BY-SA 3.0
2016-07-23T00:23:05.573Z
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
<assets><index>
How do you programmatically update an asset index?
# How do you programmatically update an asset index?

(Asked by: username_0 on 2016-07-22)

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.

**Tags:** assets, index

> **Comments:**
> **username_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`.  
> **username_0**: 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);   }  
> **username_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.  

---

## 1 answers

### Answer by username_0 on 2016-07-23. Score: 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); 
}


---

