diff --git a/includes/TaskManagers/AbstractTaskManager.php b/includes/TaskManagers/AbstractTaskManager.php new file mode 100644 index 0000000..c017000 --- /dev/null +++ b/includes/TaskManagers/AbstractTaskManager.php @@ -0,0 +1,70 @@ +to_array() ); } - - /** - * Get the status of a given plugin slug from the queue. - * - * @param string $plugin The slug of the plugin. - * @return boolean - */ - public static function status( $plugin ) { - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - return array_search( $plugin, array_column( $plugins, 'slug' ), true ); - } } diff --git a/includes/TaskManagers/PluginDeactivationTaskManager.php b/includes/TaskManagers/PluginDeactivationTaskManager.php index ccbe835..3f78d06 100644 --- a/includes/TaskManagers/PluginDeactivationTaskManager.php +++ b/includes/TaskManagers/PluginDeactivationTaskManager.php @@ -1,4 +1,5 @@ to_array() ); } - - /** - * Get the status of a given plugin slug from the queue. - * - * @param string $plugin The slug of the plugin. - * @return boolean - */ - public static function status( $plugin ) { - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - return array_search( $plugin, array_column( $plugins, 'slug' ), true ); - } } diff --git a/includes/TaskManagers/PluginInstallTaskManager.php b/includes/TaskManagers/PluginInstallTaskManager.php index f09c9c2..2605ceb 100644 --- a/includes/TaskManagers/PluginInstallTaskManager.php +++ b/includes/TaskManagers/PluginInstallTaskManager.php @@ -1,4 +1,5 @@ to_array() ); } + /** - * Get the status of a given plugin slug from the queue. + * Clear all the hook scheduling and update the status option * - * @param string $plugin The slug of the plugin. - * @return boolean + * @return bool */ - public static function status( $plugin ) { - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - return array_search( $plugin, array_column( $plugins, 'slug' ), true ); + private static function complete() { + wp_clear_scheduled_hook( 'nfd_module_installer_plugin_install_cron' ); + return \update_option( Options::get_option_name( 'plugins_init_status' ), 'completed' ); } /** diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index 61bd8c9..f584aa4 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -1,4 +1,5 @@ to_array() ); } - - /** - * Returns the status of given plugin slug - uninstalling/completed. - * - * @param string $plugin Plugin Slug - * @return string|false - */ - public static function status( $plugin ) { - $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); - return array_search( $plugin, array_column( $plugins, 'slug' ), true ); - } } diff --git a/includes/TaskManagers/TaskManager.php b/includes/TaskManagers/TaskManager.php index 0576e05..185813a 100644 --- a/includes/TaskManagers/TaskManager.php +++ b/includes/TaskManagers/TaskManager.php @@ -1,4 +1,5 @@ task_managers as $task_manager ) { - if ( ! empty( get_option( Options::get_option_name( $task_manager::get_queue_name() ), array() ) ) ) { + if ( wp_next_scheduled( $task_manager::get_hook_name() ) || ! empty( get_option( Options::get_option_name( $task_manager::get_queue_name() ), array() ) ) ) { new $task_manager(); } } diff --git a/includes/TaskManagers/TaskManagerSchedules.php b/includes/TaskManagers/TaskManagerSchedules.php new file mode 100644 index 0000000..912b8c4 --- /dev/null +++ b/includes/TaskManagers/TaskManagerSchedules.php @@ -0,0 +1,47 @@ + array( + 'interval' => 30, + 'display' => __( 'Once Every Thirty Seconds' ), + ), + 'ten_seconds' => array( + 'interval' => 10, + 'display' => __( 'Once Every Ten Seconds' ), + ), + ); + + foreach ( $schedules_to_add as $schedule_slug => $schedule_data ) { + if ( ! array_key_exists( $schedule_slug, $schedules ) || $schedule_data['interval'] !== $schedules[ $schedule_slug ]['interval'] ) { + $schedules[ $schedule_slug ] = $schedule_data; + } + } + + return $schedules; + } +} diff --git a/includes/TaskManagers/ThemeInstallTaskManager.php b/includes/TaskManagers/ThemeInstallTaskManager.php index 4dee92c..5582b04 100644 --- a/includes/TaskManagers/ThemeInstallTaskManager.php +++ b/includes/TaskManagers/ThemeInstallTaskManager.php @@ -1,4 +1,5 @@ 10, - 'display' => __( 'Once Every Ten Seconds' ), - ); - } - - return $schedules; - } - /** * Expedites an existing ThemeInstallTask with a given slug. * @@ -106,7 +80,7 @@ public static function expedite( $theme_slug ) { then re-queue the task at the end of the queue to be retried. */ if ( $theme_install_task->get_retries() <= self::$retry_limit ) { - array_push( $themes, $theme_install_task->to_array() ); + array_push( $themes, $theme_install_task->to_array() ); } } @@ -138,6 +112,7 @@ public function install() { */ $theme_to_install = array_shift( $themes ); if ( ! $theme_to_install ) { + self::complete(); return true; } @@ -164,13 +139,13 @@ public function install() { then re-queue the task at the end of the queue to be retried. */ if ( $theme_install_task->get_retries() <= self::$retry_limit ) { - array_push( $themes, $theme_install_task->to_array() ); + array_push( $themes, $theme_install_task->to_array() ); } } // If there are no more themes to be installed then change the status to completed. if ( empty( $themes ) ) { - \update_option( Options::get_option_name( 'theme_init_status' ), 'completed' ); + self::complete(); } // Update the theme install queue. @@ -213,14 +188,14 @@ public static function add_to_queue( ThemeInstallTask $theme_install_task ) { return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); } + /** - * Returns the status of given plugin slug - installing/completed. + * Clear all the hook scheduling and update the status option * - * @param string $theme Theme Slug - * @return string|false + * @return bool */ - public static function status( $theme ) { - $themes = \get_option( Options::get_option_name( self::$queue_name ), array() ); - return array_search( $theme, array_column( $themes, 'slug' ), true ); + private static function complete() { + wp_clear_scheduled_hook( self::get_hook_name() ); + return \update_option( Options::get_option_name( 'theme_init_status' ), 'completed' ); } }