AssetIndexer
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\AssetIndexer » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 3.0.0
Asset Indexer service.
An instance of the service is available via Craft::$app->assetIndexer
.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component. |
existingIndexingSessions | array (opens new window) |
# existingIndexingSessions
- Type
- array (opens new window)
- Default value
null
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | This method is called after the object is created by cloning an existing one. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
createIndexingSession() | Create a new indexing session. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | 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() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | 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() (opens new window) | Initializes the object. |
off() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | 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() (opens new window) | 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 (opens new window)
Arguments
$volumeList
(craft\models\Volume[])$cacheRemoteImages
(boolean (opens new window)) – Whether remote images should be cached.$isCli
(boolean (opens new window)) – Whether indexing is run via CLI$listEmptyFolders
(boolean (opens new window)) – 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 (opens new window)
Returns
# getIndexListOnVolume()
Returns a sorted list of files on a volume.
View source (opens new window)
Arguments
$volume
(craft\models\Volume) – The Volume to perform indexing on.$directory
(string (opens new window)) – Optional path to get index list on a subfolder.
Returns
# getIndexingSessionById()
- Since
- 4.0.0
Get an indexing session by its id.
View source (opens new window)
Arguments
$sessionId
(integer (opens new window))
Returns
craft\models\AssetIndexingSession, null (opens new window)
# getMissingEntriesForSession()
- Since
- 4.0.0
Get missing entries after an indexing session.
View source (opens new window)
Arguments
$session
(craft\models\AssetIndexingSession)
Returns
array (opens new window) – With files
and folders
keys, containing missing entries.
Throws
# getNextIndexEntry()
Returns the next item to index in an indexing session.
View source (opens new window)
Arguments
$session
(craft\models\AssetIndexingSession)
Returns
craft\models\AssetIndexData, null (opens new window)
# getSkippedItemsForSession()
- Since
- 4.0.0
Get skipped items for an indexing session.
View source (opens new window)
Arguments
$session
(craft\models\AssetIndexingSession)
Returns
# indexFile()
Index a single file by Volume and path.
View source (opens new window)
Arguments
$volume
(craft\models\Volume)$path
(string (opens new window))$sessionId
(integer (opens new window)) – The indexing session ID$cacheImages
(boolean (opens new window)) – Whether remotely-stored images should be downloaded and stored locally, to speed up transform generation.$createIfMissing
(boolean (opens new window)) – 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 (opens new window)
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.
View source (opens new window)
Arguments
$indexEntry
(craft\models\AssetIndexData)$cacheImages
(boolean (opens new window)) – Whether remotely-stored images should be downloaded and stored locally, to speed up transform generation.$createIfMissing
(boolean (opens new window)) – 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 (opens new window)
- craft\errors\MissingAssetException
- craft\errors\VolumeException
# indexFileByListing()
- Since
- 4.0.0
View source (opens new window)
Arguments
$volumeId
(integer (opens new window))$listing
(craft\models\FsListing)$sessionId
(integer (opens new window))$cacheImages
(boolean (opens new window))$createIfMissing
(boolean (opens new window))
Returns
Throws
- craft\errors\AssetDisallowedExtensionException
if attempting to index an asset with a disallowed extension - craft\errors\VolumeException
- yii\base\InvalidConfigException (opens new window)
- craft\errors\MissingAssetException
if asset not found andcreateIfMissing
set tofalse
.
# indexFolderByEntry()
- Since
- 4.0.0
Indexes a folder by its index entry.
View source (opens new window)
Arguments
$indexEntry
(craft\models\AssetIndexData)$createIfMissing
(boolean (opens new window)) – Whether the asset record should be created if it doesn't exist yet
Returns
Throws
# indexFolderByListing()
- Since
- 4.0.0
View source (opens new window)
Arguments
$volumeId
(integer (opens new window))$listing
(craft\models\FsListing)$sessionId
(integer (opens new window))$createIfMissing
(boolean (opens new window))
Returns
Throws
# processIndexSession()
- Since
- 4.0.0
Process an indexing session step.
View source (opens new window)
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.
View source (opens new window)
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.
View source (opens new window)
Arguments
$volumes
(array (opens new window))$cacheRemoteImages
(boolean (opens new window))$listEmptyFolders
(boolean (opens new window))
Returns
craft\models\AssetIndexingSession
# stopIndexingSession()
- Since
- 4.0.0
Stop an indexing session.
View source (opens new window)
Arguments
$session
(craft\models\AssetIndexingSession) – The indexing session to stop.
Throws
# storeIndexList()
Store the index list in the index data table.
View source (opens new window)
Arguments
$indexList
(Generator (opens new window)) – Index list generated byAssetIndexer::getIndexListOnVolume()
$sessionId
(integer (opens new window)) – The indexing session ID.$volumeId
(integer (opens new window)) – The volume ID.
Returns
integer (opens new window) – Number of entries inserted
# updateIndexEntry()
Update indexing-process related data on an index entry.
View source (opens new window)
Arguments
$entryId
(integer (opens new window)) – Index entry ID.$data
(array (opens new window)) – Key=>value array of data to update.
# 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.
View source (opens new window)
Arguments
$session
(craft\models\AssetIndexingSession)
Returns
craft\models\AssetIndexingSession
Throws
# storeIndexEntry()
- Since
- 4.0.5
Store a single index entry.
View source (opens new window)
Arguments
$indexEntry
(craft\models\AssetIndexData)
Throws
# storeIndexingSession()
Store an indexing session to DB.
View source (opens new window)
Arguments
$session
(craft\models\AssetIndexingSession)