• Resolved buddywhatshisname

    (@vhmarkgmailcom)


    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)
  • Plugin Support Darian

    (@d0153)

    Hi @vhmarkgmailcom,

    Thanks for reaching out. Let me help you with this one.

    If those tables are missing, then there could be an issue during the migration of your events or you haven’t migrated your events yet.

    To troubleshoot this, would it be possible for you to set up a staging version of your live site and try to re-do the migration from there, and see if the following steps fixes the issue?

    Here are the steps to revert and re-do the migration:

    1. Update to the latest versions of The Events Calendar and Events Calendar Pro.
    2. Remove any un-needed draft events and empty the Trash.
    3. Activate only our plugins and use the 2020 theme.
    4. Make sure server-side caching is disabled temporarily while you’re migrating your events.
    5. Install and activate the Code Snippets plugin.
    6. Add this snippet and run it once (be sure it does not stay activated).
    7. Go to Events > Settings > Upgrades and go through the migration process again.

    Please re-do the migration on your staging site.

    Let me know how it goes.

    Plugin Support Darian

    (@d0153)

    Hi there,

    It appears that we haven’t heard back from you in a while, so I’ll assume that the matter has been resolved. If you need any more help, feel free to start a new thread and we’ll be happy to assist you.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Missing tables – how to recreate?’ is closed to new replies.