Skip to content

AssetIndexer ​

Type
Class
Namespace
craft\services
Inherits
craft\services\AssetIndexer » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

Asset Indexer service.

An instance of the service is available via Craft::$app->assetIndexer.

View source

Public Properties ​

PropertyDescription
behaviorsyii\base\Behavior – List of behaviors attached to this component.
existingIndexingSessionsarray

existingIndexingSessions ​

Type
array
Default value
null

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
createIndexingSession()Create a new indexing session.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getExistingIndexingSessions()Return a list of currently active indexing sessions.
getIndexListOnVolume()Returns a sorted list of files on a volume.
getIndexingSessionById()Get an indexing session by its id.
getMissingEntriesForSession()Get missing entries after an indexing session.
getNextIndexEntry()Returns the next item to index in an indexing session.
getSkippedItemsForSession()Get skipped items for an indexing session.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined for this component.
indexFile()Index a single file by Volume and path.
indexFileByEntry()Indexes a file by its index entry.
indexFileByListing()
indexFolderByEntry()Indexes a folder by its index entry.
indexFolderByListing()
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
processIndexSession()Process an indexing session step.
removeCliIndexingSessions()Remove all CLI-based indexing sessions.
startIndexingSession()Start an indexing session for an array of volumes. If first element of array is "all", all volumes wil be indexed.
stopIndexingSession()Stop an indexing session.
storeIndexList()Store the index list in the index data table.
trigger()Triggers an event.
updateIndexEntry()Update indexing-process related data on an index entry.

createIndexingSession() ​

Since
4.0.0

Create a new indexing session.

View source

Arguments ​

  • $volumeList (craft\models\Volume[])
  • $cacheRemoteImages (boolean) – Whether remote images should be cached.
  • $isCli (boolean) – Whether indexing is run via CLI
  • $listEmptyFolders (boolean) – Whether empty folders should be listed for deletion.

Returns ​

craft\models\AssetIndexingSession

getExistingIndexingSessions() ​

Since
4.0.0

Return a list of currently active indexing sessions.

View source

Returns ​

array

getIndexListOnVolume() ​

Returns a sorted list of files on a volume.

View source

Arguments ​

  • $volume (craft\models\Volume) – The Volume to perform indexing on.
  • $directory (string) – Optional path to get index list on a subfolder.

Returns ​

Generator

getIndexingSessionById() ​

Since
4.0.0

Get an indexing session by its id.

View source

Arguments ​

Returns ​

craft\models\AssetIndexingSession, null

getMissingEntriesForSession() ​

Since
4.0.0

Get missing entries after an indexing session.

View source

Arguments ​

Returns ​

array – With files and folders keys, containing missing entries.

Throws ​

getNextIndexEntry() ​

Returns the next item to index in an indexing session.

View source

Arguments ​

Returns ​

craft\models\AssetIndexData, null

getSkippedItemsForSession() ​

Since
4.0.0

Get skipped items for an indexing session.

View source

Arguments ​

Returns ​

string[]

indexFile() ​

Index a single file by Volume and path.

View source

Arguments ​

  • $volume (craft\models\Volume)
  • $path (string)
  • $sessionId (integer) – The indexing session ID
  • $cacheImages (boolean) – Whether remotely-stored images should be downloaded and stored locally, to speed up transform generation.
  • $createIfMissing (boolean) – Whether the asset record should be created if it doesn't exist yet

Returns ​

craft\elements\Asset

Throws ​

indexFileByEntry() ​

Indexes a file by its index entry.

View source

Arguments ​

  • $indexEntry (craft\models\AssetIndexData)
  • $cacheImages (boolean) – Whether remotely-stored images should be downloaded and stored locally, to speed up transform generation.
  • $createIfMissing (boolean) – Whether the asset record should be created if it doesn't exist yet

Returns ​

craft\elements\Asset

Throws ​

indexFileByListing() ​

Since
4.0.0

View source

Arguments ​

Returns ​

craft\elements\Asset

Throws ​

indexFolderByEntry() ​

Since
4.0.0

Indexes a folder by its index entry.

View source

Arguments ​

Returns ​

craft\models\VolumeFolder

Throws ​

indexFolderByListing() ​

Since
4.0.0

View source

Arguments ​

Returns ​

craft\models\VolumeFolder

Throws ​

processIndexSession() ​

Since
4.0.0

Process an indexing session step.

View source

Arguments ​

Returns ​

craft\models\AssetIndexingSession

Throws ​

removeCliIndexingSessions() ​

Since
4.0.0

Remove all CLI-based indexing sessions.

View source

Returns ​

integer

Throws ​

startIndexingSession() ​

Since
4.0.0

Start an indexing session for an array of volumes. If first element of array is "all", all volumes wil be indexed.

View source

Arguments ​

Returns ​

craft\models\AssetIndexingSession

stopIndexingSession() ​

Since
4.0.0

Stop an indexing session.

View source

Arguments ​

Throws ​

storeIndexList() ​

Store the index list in the index data table.

View source

Arguments ​

  • $indexList (Generator) – Index list generated by AssetIndexer::getIndexListOnVolume()
  • $sessionId (integer) – The indexing session ID.
  • $volumeId (integer) – The volume ID.

Returns ​

integer – Number of entries inserted

updateIndexEntry() ​

Update indexing-process related data on an index entry.

View source

Arguments ​

  • $entryId (integer) – Index entry ID.
  • $data (array) – Key=>value array of data to update.

Protected Methods ​

MethodDescription
incrementProcessedEntryCount()Increment the processed entry count on a session.
storeIndexEntry()Store a single index entry.
storeIndexingSession()Store an indexing session to DB.

incrementProcessedEntryCount() ​

Increment the processed entry count on a session.

View source

Arguments ​

Returns ​

craft\models\AssetIndexingSession

Throws ​

storeIndexEntry() ​

Since
4.0.5

Store a single index entry.

View source

Arguments ​

Throws ​

storeIndexingSession() ​

Store an indexing session to DB.

View source

Arguments ​