SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/WorkerRedoSizes.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16.  
  17. class WorkerRedoSizes extends WorkerBase
  18. {
  19. protected $job_name = 'Redo image sizes';
  20.  
  21.  
  22. /**
  23.   * Do stuff
  24.   **/
  25. public function run($size = null)
  26. {
  27. if ($size) {
  28. Worker::message("Only processing size '{$size}'.");
  29. } else {
  30. Worker::message("Processing all sizes.");
  31. }
  32.  
  33. $q = "SELECT filename FROM ~files WHERE type = ?";
  34. $res = Pdb::query($q, [FileConstants::TYPE_IMAGE], 'pdo');
  35.  
  36. foreach ($res as $row) {
  37. if (!File::exists($row['filename'])) continue;
  38. File::createDefaultSizes($row['filename'], $size);
  39. Worker::message($row['filename']);
  40. }
  41.  
  42. $res->closeCursor();
  43.  
  44. Worker::success();
  45. }
  46.  
  47. }
  48.  
  49.