PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.5.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.5.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / classes / migration / migration-manager.php

migration-manager.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.5.4, at classes/migration/migration-manager.php

74 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Classes\Migration;
4
5 use ImageOptimization\Classes\Async_Operation\{
6 Async_Operation,
7 Async_Operation_Hook,
8 Async_Operation_Queue,
9 Exceptions\Async_Operation_Exception,
10 };
11
12 use ImageOptimization\Classes\Logger;
13 use ImageOptimization\Classes\Migration\Handlers\{
14 Fix_Avif_With_Zero_Dimensions,
15 Fix_Mime_Type,
16 Fix_Optimized_Size_Keys,
17 };
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit; // Exit if accessed directly.
21 }
22
23 class Migration_Manager {
24 public static function get_migrations(): array {
25 return [
26 Fix_Optimized_Size_Keys::class,
27 Fix_Mime_Type::class,
28 Fix_Avif_With_Zero_Dimensions::class,
29 ];
30 }
31
32 /**
33 * @param $migration_name
34 *
35 * @return \class-string|null
36 */
37 public static function get_migration( $migration_name ): ?string {
38 foreach ( self::get_migrations() as $migration ) {
39 if ( $migration::get_name() === $migration_name ) {
40 return $migration;
41 }
42 }
43
44 return null;
45 }
46
47 public static function init() {
48 $migrations_passed = ( new Migration_Meta() )->get_migrations_passed();
49
50 foreach ( self::get_migrations() as $migration ) {
51 if ( in_array( $migration::get_name(), $migrations_passed, true ) ) {
52 continue;
53 }
54
55 try {
56 Async_Operation::create(
57 Async_Operation_Hook::DB_MIGRATION,
58 [ 'name' => $migration::get_name() ],
59 Async_Operation_Queue::MIGRATION,
60 0,
61 true
62 );
63 } catch ( Async_Operation_Exception $aoe ) {
64 $name = $migration::get_name();
65
66 Logger::log(
67 Logger::LEVEL_ERROR,
68 "Error while running migration `$name`: " . $aoe->getMessage()
69 );
70 }
71 }
72 }
73 }
74