Skip to content

Commit

Permalink
Merge pull request #56 from mrrobot47/cleanup/migration
Browse files Browse the repository at this point in the history
Remove crons of deleted sites
  • Loading branch information
mrrobot47 committed Nov 10, 2023
2 parents 7cfcc29 + 9cb9c83 commit 9f69a63
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions migrations/db/20231110154339_cron-command_cleanup_old_entries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace EE\Migration;

use EE;
use EE\Migration\Base;
use EE\Model\Cron;
use EE\Model\Site;

class CleanupOldEntries extends Base {

public function __construct() {

parent::__construct();
$this->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() {

}

}

0 comments on commit 9f69a63

Please sign in to comment.