PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.2.0
Kubio AI Page Builder v2.2.0
2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / Migrations.php
kubio / lib / src Last commit date
CLI 2 years ago Core 2 years ago DemoSites 2 years ago AssetsDependencyInjector.php 3 years ago Config.php 3 years ago FileLog.php 2 years ago Flags.php 2 years ago GoogleFontsLocalLoader.php 2 years ago Migrations.php 4 years ago NotificationsManager.php 2 years ago PluginsManager.php 2 years ago
Migrations.php
108 lines
1 <?php
2
3 namespace Kubio;
4
5 use Kubio\Core\Utils as CoreUtils;
6
7 /**
8 *
9 * Kubio migration purpose is to apply certain changes to existing sites besides new ones.
10 * The migrations that are available inside the /migrations folder in kubio plugin have the following nameing scheme: {index}-{callback}.php
11 * The {index} is to ensure the migration execution order.
12 * The {callback} is the function that will be called to execute the migration.
13 *
14 */
15 class Migrations {
16
17
18 private static function getMigrations() {
19 $files = glob( KUBIO_ROOT_DIR . '/migrations/*.php' );
20
21 $migrations = array();
22 foreach ( $files as $file ) {
23 $migration = preg_replace( '#(.*)/migrations/(.*).php#', '$2', wp_normalize_path( $file ) );
24 $migration = Migrations::parseMigration( $migration );
25
26 if ( $migration ) {
27 $migrations[] = $migration;
28 }
29 }
30
31 return apply_filters( 'kubio/available_migrations', $migrations );
32
33 }
34
35 private static function parseMigration( $migration ) {
36 preg_match( '#(\d+?)-(.*$)#', $migration, $matches );
37
38 if ( count( $matches ) === 3 ) {
39 return array(
40 'slug' => $migration,
41 'callback' => $matches[2],
42 );
43 }
44
45 return null;
46
47 }
48 public static function loadMissingMigrations() {
49
50 $is_actived = Flags::get( 'kubio_activation_time' ) || Flags::get( 'kubio_pro_activation_time' );
51 if ( ! $is_actived ) {
52 return;
53 }
54
55 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
56 return;
57 }
58
59 if ( defined( 'REST_REQUEST ' ) && REST_REQUEST ) {
60 return;
61 }
62
63 Migrations::executeMigrations();
64 }
65
66 private static function executeMigrations() {
67 $available_migrations = Migrations::getMigrations();
68 $executed_migrations = kubio_get_global_data( 'migrations', array() );
69
70 $callbacks = array();
71
72 foreach ( $available_migrations as $migration ) {
73 $slug = $migration['slug'];
74 $callback = $migration['callback'];
75
76 if ( ! isset( $executed_migrations[ $slug ] ) ) {
77 require_once KUBIO_ROOT_DIR . "/migrations/{$slug}.php";
78 if ( ! function_exists( $callback ) ) {
79 if ( CoreUtils::isDebug() ) {
80 wp_die( "Migrations functon kubio_{$callback} does not exists" );
81 }
82 return; // leave migration process
83 }
84 $callbacks[ $slug ] = $callback;
85 }
86 }
87
88 foreach ( $callbacks as $slug => $callback ) {
89 try {
90 call_user_func( $callback );
91 } catch ( \Exception $e ) {
92 if ( CoreUtils::isDebug() ) {
93 wp_die( "Migrations {$callback} error" );
94 }
95 }
96 $executed_migrations [ $slug ] = true;
97 }
98
99 kubio_set_global_data( 'migrations', $executed_migrations );
100
101 }
102
103
104 public static function load() {
105 add_action( 'admin_init', array( Migrations::class, 'loadMissingMigrations' ) );
106 }
107 }
108