-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from mrrobot47/cleanup/migration
Remove crons of deleted sites
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
migrations/db/20231110154339_cron-command_cleanup_old_entries.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
|
||
} |