diff --git a/migrations/db/20231110154339_cron-command_cleanup_old_entries.php b/migrations/db/20231110154339_cron-command_cleanup_old_entries.php new file mode 100644 index 0000000..282d92a --- /dev/null +++ b/migrations/db/20231110154339_cron-command_cleanup_old_entries.php @@ -0,0 +1,51 @@ +sites = Site::all(); + if ( $this->is_first_execution || ! $this->sites ) { + $this->skip_this_migration = true; + } + } + + /** + * @throws EE\ExitException + */ + public function up() { + + if ( $this->skip_this_migration ) { + EE::debug( 'Skipping cron-cleanup migration as it is not needed.' ); + + return; + } + + $crons = Cron::all(); + + foreach ( $crons as $cron ) { + $site = Site::find( $cron->site_url ); + if ( ! $site ) { + $cron->delete(); + } + } + + EE\Cron\Utils\update_cron_config(); + } + + /** + * @throws EE\ExitException + */ + public function down() { + + } + +}