Missing tables – how to recreate?
-
I have a WP multisite where some of the child sites are missing the *_tec_events and *_tec_occurrences tables. So I’m trying to write a code-snippet to detect when these are missing and re-create the them, since the the-events-calendar plugin is not doing this on plugin activation.
So far I have this code below, but the call is not actually creating the tables: \TEC\Events\Custom_Tables\V1\Schema_Builder\Schema_Builder::class)->up(true)
Any suggestions how I can accomplish my goal of re-creating the missing tables on plugin activation?$debug = true;
$target = 'the-events-calendar/the-events-calendar.php';
add_action('activated_plugin', function($plugin, $network_activation) use ($debug, $target) {
if(strcmp($plugin, $target) !== 0) {
// do nothing
} else {
add_action('shutdown', function () use ($debug, $target) {
$include1 = include (WP_PLUGIN_DIR . '/the-events-calendar/src/Events/Custom_Tables/V1/Models/Event.php');
$include2 = include (WP_PLUGIN_DIR . '/the-events-calendar/src/Events/Custom_Tables/V1/Models/Occurrence.php');
if( !$include1
|| !$include2
|| !class_exists('\TEC\Events\Custom_Tables\V1\Tables\Events')
|| !class_exists('\TEC\Events\Custom_Tables\V1\Tables\Occurrences')
) {
error_log("Failed to find required file or class");
return;
}
$table1 = \TEC\Events\Custom_Tables\V1\Tables\Events::table_name();
$table2 = \TEC\Events\Custom_Tables\V1\Tables\Occurrences::table_name();
global $wpdb;
$count1 = $wpdb->get_var( "SELECT COUNT(*) FROM $table1" );
$count2 = $wpdb->get_var( "SELECT COUNT(*) FROM $table2" );
if(!is_numeric($count1) || !is_numeric($count2)) {
$result = tribe( \TEC\Events\Custom_Tables\V1\Schema_Builder\Schema_Builder::class)->up(true);
} else {
// do nothing
}
});
}
}, 10, 2 );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Missing tables – how to recreate?’ is closed to new replies.