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
.
Public Properties ​
Property | Description |
---|---|
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
existingIndexingSessions | array |
existingIndexingSessions
​
- Type
- array
- Default value
null
Public Methods ​
Method | Description |
---|---|
__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.
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.
Returns ​
getIndexListOnVolume()
​
Returns a sorted list of files on a volume.
Arguments ​
$volume
(craft\models\Volume) – The Volume to perform indexing on.$directory
(string) – Optional path to get index list on a subfolder.
Returns ​
getIndexingSessionById()
​
- Since
- 4.0.0
Get an indexing session by its id.
Arguments ​
$sessionId
(integer)
Returns ​
craft\models\AssetIndexingSession, null
getMissingEntriesForSession()
​
- Since
- 4.0.0
Get missing entries after an indexing session.
Arguments ​
$session
(craft\models\AssetIndexingSession)$path
(string)
Returns ​
array – With files
and folders
keys, containing missing entries.
Throws ​
getNextIndexEntry()
​
Returns the next item to index in an indexing session.
Arguments ​
$session
(craft\models\AssetIndexingSession)
Returns ​
craft\models\AssetIndexData, null
getSkippedItemsForSession()
​
- Since
- 4.0.0
Get skipped items for an indexing session.
Arguments ​
$session
(craft\models\AssetIndexingSession)
Returns ​
string[]
indexFile()
​
Index a single file by Volume and path.
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 ​
Throws ​
- craft\errors\AssetDisallowedExtensionException
if attempting to index an asset with a disallowed extension. - yii\base\InvalidConfigException
if the volume is misconfigured. - craft\errors\MissingAssetException
if asset not found andcreateIfMissing
set tofalse
. - craft\errors\VolumeException
if unable to read metadata.
indexFileByEntry()
​
Indexes a file by its index entry.
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 ​
Throws ​
- craft\errors\AssetDisallowedExtensionException
If the file being indexed has a disallowed extension - yii\base\InvalidConfigException
- craft\errors\MissingAssetException
- craft\errors\VolumeException
indexFileByListing()
​
- Since
- 4.0.0
Arguments ​
$volume
(craft\models\Volume)$listing
(craft\models\FsListing)$sessionId
(integer)$cacheImages
(boolean)$createIfMissing
(boolean)
Returns ​
Throws ​
- craft\errors\AssetDisallowedExtensionException
if attempting to index an asset with a disallowed extension - craft\errors\VolumeException
- yii\base\InvalidConfigException
- craft\errors\MissingAssetException
if asset not found andcreateIfMissing
set tofalse
.
indexFolderByEntry()
​
- Since
- 4.0.0
Indexes a folder by its index entry.
Arguments ​
$indexEntry
(craft\models\AssetIndexData)$createIfMissing
(boolean) – Whether the asset record should be created if it doesn't exist yet
Returns ​
Throws ​
indexFolderByListing()
​
- Since
- 4.0.0
Arguments ​
$volume
(craft\models\Volume)$listing
(craft\models\FsListing)$sessionId
(integer)$createIfMissing
(boolean)
Returns ​
Throws ​
processIndexSession()
​
- Since
- 4.0.0
Process an indexing session step.
Arguments ​
$indexingSession
(craft\models\AssetIndexingSession)
Returns ​
craft\models\AssetIndexingSession
Throws ​
- craft\errors\VolumeException
if unable to index file because of volume issue
removeCliIndexingSessions()
​
- Since
- 4.0.0
Remove all CLI-based indexing sessions.
Returns ​
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.
Arguments ​
Returns ​
craft\models\AssetIndexingSession
stopIndexingSession()
​
- Since
- 4.0.0
Stop an indexing session.
Arguments ​
$session
(craft\models\AssetIndexingSession) – The indexing session to stop.
Throws ​
storeIndexList()
​
Store the index list in the index data table.
Arguments ​
$indexList
(Generator) – Index list generated byAssetIndexer::getIndexListOnVolume()
$sessionId
(integer) – The indexing session ID.$volume
(craft\models\Volume) – The volume.
Returns ​
integer – Number of entries inserted
updateIndexEntry()
​
Update indexing-process related data on an index entry.
Arguments ​
Protected Methods ​
Method | Description |
---|---|
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.
Arguments ​
$session
(craft\models\AssetIndexingSession)
Returns ​
craft\models\AssetIndexingSession
Throws ​
storeIndexEntry()
​
- Since
- 4.0.5
Store a single index entry.
Arguments ​
$indexEntry
(craft\models\AssetIndexData)
Throws ​
storeIndexingSession()
​
Store an indexing session to DB.
Arguments ​
$session
(craft\models\AssetIndexingSession)