Skip to content

Commit

Permalink
add lock mechanism to migrations runner to prevent it from running if…
Browse files Browse the repository at this point in the history
… other process is already running it. see #269
  • Loading branch information
dannyvankooten committed Nov 18, 2024
1 parent 4d14d46 commit cc1d82c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,23 @@ public function maybe_run_db_migrations(): void
return;
}

// check if migrations not already running
if (get_transient('koko_analytics_migrations_running')) {
return;
}

// set transient to prevent migrations from running simultaneously
set_transient('koko_analytics_migrations_running', true, 120);

// run upgrade migrations (if any)
$migrations_dir = KOKO_ANALYTICS_PLUGIN_DIR . '/migrations/';
$migrations = new Migrations($from_version, $to_version, $migrations_dir);
$migrations->run();
update_option('koko_analytics_version', $to_version, true);

// delete transient once done
delete_transient('koko_analytics_migrations_running');

// make sure scheduled event is set up correctly
$this->aggregator->setup_scheduled_event();
}
Expand Down

0 comments on commit cc1d82c

Please sign in to comment.