Skip to content

Commit 1f1fed0

Browse files
author
Marco Pereirinha
committed
Cleanup Cloudinary cron on deactivation and full cleanup
1 parent e171306 commit 1f1fed0

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

php/class-cron.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,12 @@ public function cleanup_failed_cron() {
448448
$this->locker->delete_lock_file( $this->init_time );
449449
}
450450

451+
/**
452+
* Allow cleanup of the locker.
453+
*
454+
* @return void
455+
*/
456+
public function cleanup_locker() {
457+
$this->locker->delete_lock_file();
458+
}
451459
}

php/class-deactivation.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ protected function cleanup() {
479479
$this->cleanup_post_type();
480480
$this->drop_tables();
481481
$this->cleanup_options();
482+
$this->cleanup_cron();
482483

483484
// If we got this far, let's remove the cron event.
484485
wp_clear_scheduled_hook( 'cloudinary_cleanup_event' );
@@ -600,4 +601,28 @@ protected function cleanup_options() {
600601
delete_transient( $key );
601602
}
602603
}
604+
605+
/**
606+
* Remove all cron-related tasks.
607+
*
608+
* @return void
609+
*/
610+
protected function cleanup_cron() {
611+
// Get the Cron instance.
612+
$cron_instance = Cron::get_instance();
613+
$schedule = $cron_instance->get_schedule();
614+
615+
// Unregister all registered schedules.
616+
if ( ! empty( $schedule ) ) {
617+
foreach ( array_keys( $schedule ) as $schedule_name ) {
618+
$cron_instance->unregister_schedule( $schedule_name );
619+
}
620+
}
621+
622+
// Remove any lock files or objects used by the Locker instance.
623+
$cron_instance->cleanup_locker();
624+
625+
// Delete the cron schedule option saved in database.
626+
delete_option( Cron::CRON_META_KEY );
627+
}
603628
}

0 commit comments

Comments
 (0)