You are here

class ImageStylesWarmerCommands in Image Style Warmer 8

Hierarchy

Expanded class hierarchy of ImageStylesWarmerCommands

1 string reference to 'ImageStylesWarmerCommands'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses ImageStylesWarmerCommands
image_style_warmer.commands in ./drush.services.yml
\Drupal\image_style_warmer\Commands\ImageStylesWarmerCommands

File

src/Commands/ImageStylesWarmerCommands.php, line 8

Namespace

Drupal\image_style_warmer\Commands
View source
class ImageStylesWarmerCommands extends DrushCommands {

  /**
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  private $loggerChannelFactory;
  public function __construct(LoggerChannelFactoryInterface $loggerChannelFactory) {
    $this->loggerChannelFactory = $loggerChannelFactory;
  }

  /**
   * Warms up all the existing images by using the default configuration.
   *
   * @command image-style-warmer:warm-up
   * @aliases isw:wu
   */
  public function warmUp() {
    $this
      ->logger()
      ->notice("Loading files.");
    $this->loggerChannelFactory
      ->get('image_style_warmer')
      ->info('Image styles warmer loading files.');
    $files = \Drupal::entityQuery('file')
      ->execute();
    if (!empty($files)) {
      $count = count($files);
      $numOperations = 0;
      $operations = [];
      $this->loggerChannelFactory
        ->get('image_style_warmer')
        ->info('Image styles warmer batch operations start');
      foreach ($files as $fid) {
        $operations[] = [
          '\\Drupal\\image_style_warmer\\BatchService::warmUpFileProcess',
          [
            $fid,
            $count,
          ],
        ];
        $numOperations++;
      }
      $batch = [
        'title' => t('Warming up image styles for @num file(s)', [
          '@num' => $numOperations,
        ]),
        'operations' => $operations,
        'finished' => '\\Drupal\\image_style_warmer\\BatchService::warmUpFileFinished',
      ];
      batch_set($batch);
      drush_backend_batch_process();
      $this
        ->logger()
        ->notice("Batch operations end.");
      $this->loggerChannelFactory
        ->get('image_style_warmer')
        ->info('Image styles warmer batch operations end.');
    }
    else {
      $this
        ->logger()
        ->notice("No files found.");
      $this
        ->logger()
        ->warning('No files found to warm up.');
      $this->loggerChannelFactory
        ->get('image_style_warmer')
        ->info('No files found to warm up.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImageStylesWarmerCommands::$loggerChannelFactory private property
ImageStylesWarmerCommands::warmUp public function Warms up all the existing images by using the default configuration.
ImageStylesWarmerCommands::__construct public function