plugin_directory . '/migrations/*.php' ); if ( ! is_array( $migration_files ) ) { return; } $migrations = []; foreach ( $migration_files as $file ) { $class_name = pathinfo( $file, PATHINFO_FILENAME ); if ( Migration_Table_Manager::is_migrated( $class_name ) ) { continue; } require_once $file; if ( ! class_exists( $class_name ) ) { continue; } $migration = new $class_name(); if ( $migration instanceof Migration ) { $migrations[] = [ 'name' => $class_name, 'instance' => $migration, ]; } } usort( $migrations, function ( $a, $b ) { return $a['instance']->get_serial() - $b['instance']->get_serial(); } ); $batch = Migration_Table_Manager::get_latest_batch() + 1; foreach ( $migrations as $entry ) { $entry['instance']->up(); Migration_Table_Manager::mark_as_migrated( $entry['name'], $batch ); } } /** * Rollback the latest batch of migrations. * * This method loads migrations from the latest batch in reverse order, * calls their down() method, and removes them from the tracking table. * * @return void */ public static function rollback() { Migration_Table_Manager::ensure_table_exists(); $migrations = Migration_Table_Manager::get_latest_batch_migrations(); if ( empty( $migrations ) ) { return; } $migrations_dir = Aisentic()->plugin_directory . '/migrations/'; foreach ( $migrations as $record ) { $file = $migrations_dir . $record->migration . '.php'; if ( ! file_exists( $file ) ) { continue; } require_once $file; $class_name = $record->migration; if ( ! class_exists( $class_name ) ) { continue; } $migration = new $class_name(); if ( $migration instanceof Migration ) { $migration->down(); } Migration_Table_Manager::remove_migration( $record->migration ); } } }