migrations/Version20251215120000.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Add image optimization configuration to backoffice.
  8.  * Allows configuring the maximum dimension (width/height) for uploaded images.
  9.  */
  10. final class Version20251215120000 extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return 'Add image_max_dimension configuration for image upload optimization';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         // Get the next order_value for System parent
  19.         $this->addSql("
  20.             SET @order_value = COALESCE((SELECT MAX(`order_value`) FROM `std_config` WHERE `parent_name` = 'System'), 0) + 1
  21.         ");
  22.         $this->addSql("
  23.             INSERT IGNORE INTO `std_config` (
  24.                 `machine_name`, 
  25.                 `created_by`, 
  26.                 `updated_by`, 
  27.                 `value`, 
  28.                 `description_machine_name`, 
  29.                 `details_machine_name`, 
  30.                 `parent_name`, 
  31.                 `variable_type`, 
  32.                 `order_value`, 
  33.                 `is_hidden`, 
  34.                 `is_active`, 
  35.                 `created_date`, 
  36.                 `updated_date`, 
  37.                 `label`, 
  38.                 `content`, 
  39.                 `language_code`
  40.             ) VALUES (
  41.                 'image_max_dimension',
  42.                 1,
  43.                 1,
  44.                 '2500',
  45.                 'image_max_dimension',
  46.                 'Maximum dimension (width or height in pixels) for uploaded images. Images larger than this will be automatically resized. Set to 0 to disable resizing.',
  47.                 'System',
  48.                 'INPUT',
  49.                 @order_value,
  50.                 0,
  51.                 1,
  52.                 NOW(),
  53.                 NOW(),
  54.                 'Image Max Dimension (px)',
  55.                 NULL,
  56.                 ''
  57.             )
  58.         ");
  59.     }
  60.     public function down(Schema $schema): void
  61.     {
  62.         $this->addSql("DELETE FROM `std_config` WHERE `machine_name` = 'image_max_dimension'");
  63.     }
  64. }