From 7db4582391f216dad38c1f378d38966a1588238a Mon Sep 17 00:00:00 2001 From: Nurul Umbhiya Date: Fri, 10 Nov 2023 08:32:39 +0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(Installer.php):=20add=20sc?= =?UTF-8?q?hedule=5Fcron=5Fjobs()=20method=20to=20Installer=20class=20for?= =?UTF-8?q?=20scheduling=20recurring=20cron=20jobs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Install/Installer.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/includes/Install/Installer.php b/includes/Install/Installer.php index d5458e5d7e..cfdc054f0e 100755 --- a/includes/Install/Installer.php +++ b/includes/Install/Installer.php @@ -22,6 +22,7 @@ public function do_install() { $this->create_reverse_withdrawal_base_product(); $this->product_design(); $this->add_store_name_meta_key_for_admin_users(); + $this->schedule_cron_jobs(); // does it needs any update? if ( dokan()->has_woocommerce() && dokan()->upgrades->is_upgrade_required() ) { @@ -80,6 +81,34 @@ public function add_store_name_meta_key_for_admin_users() { } } + /** + * Schedule cron jobs + * + * @since DOKAN_SINCE + * + * @return void + */ + private function schedule_cron_jobs() { + if ( ! function_exists( 'WC' ) || ! WC()->queue() ) { + return; + } + + // schedule daily cron job + $hook = 'dokan_daily_midnight_cron'; + + // check if we've defined the cron hook + $cron_schedule = as_next_scheduled_action( $hook ); // this method will return false if the hook is not scheduled + if ( ! $cron_schedule ) { + as_unschedule_all_actions( $hook ); + } + + // schedule recurring cron action + $now = dokan_current_datetime()->modify( 'midnight' )->getTimestamp(); + WC()->queue()->schedule_cron( $now, '0 0 * * *', $hook, [], 'dokan' ); + + // add cron jobs as needed + } + /** * Adds plugin installation time. *