Skip to content

Media Gallery Indexing

Sergii Ivashchenko edited this page Apr 6, 2020 · 1 revision

Overview

Media gallery indexing is a process of reflecting media assets located in media storage in the database.

Use cases

Media gallery data consistency is ensured by updating the information about media gallery assets on each media asset upload and delete operation.

The indexing is required only in the following two situations:

  • When Enhanced Media Gallery is enabled (to reflect already existing media assets in the database)
  • After manual changes are applied to media storage bypassing the Magento application

Stages

There are two stages of media gallery indexing process:

  • media_gallery_asset table is updated on the first stage of indexing
  • media_gallery_asset_grid table is updated on the second stage of indexing

Indexing process:

The indexing process includes the following steps

Stage 1

  • Scan the media assets storage
  • Retrieve the data for each media asset
  • Create and save media asset entities to the database. Write the data to media_gallery_asset table Stage 2
  • Retrieve information of media assets from the database
  • Retrieve information required for displaying in the media gallery grid from extensions
  • Update media_gallery_asset_grid with flat data for media gallery grid rendering

Triggers

There are two triggers for the media gallery indexing process:

  • bin/magento media-gallery:index console command can be used for manual index triggering. The command is implemented by Magento\MediaGalleryUi\Console\Command\IndexAssets
  • Saving the stores configuration after enabling Enhanced Media Gallery implemented by Magento\MediaGalleryUi\Plugin\MediaGalleryIndexerTrigger::afterSave plugin applied to Magento\Framework\App\Config\Value class

Implementation

  • Magento\MediaGalleryUi\Model\ImagesIndexer::execute provides the assets storage root path, assets name pattern, indexer options and list of asset indexers configured in the DI
  • Magento\MediaGalleryUi\Model\FilesIndexer::execute goes through the file system and calls Magento\MediaGalleryUi\Model\Filesystem\IndexerInterface for each file (\SplFileInfo)
  • Magento\MediaGalleryUi\Model\Filesystem\IndexerInterface is responsible for retrieving any information needed from \SplFileInfo and saving it to the database
Clone this wiki locally