ed_items() { return (int) $this->get_value( self::FAILED_ITEMS ); } /** * Set failed items count (fixes bug in original where it was setting PROCESSED_ITEMS). * * @param int $failed_items Failed items count. */ public function set_failed_items( $failed_items ) { $this->set_value( self::FAILED_ITEMS, $failed_items ); } /** * Check if process is cancelled * * @return bool */ public function is_cancelled() { return $this->get_value( self::CANCELLED ); } /** * Set cancelled state. * * @param bool $is_cancelled Cancelled state. */ public function set_is_cancelled( $is_cancelled ) { $this->set_value( self::CANCELLED, $is_cancelled ); } /** * Check if process is dead. * * @return bool */ public function is_dead() { return $this->get_value( self::DEAD ); } /** * Check if process is completed. * * @return bool */ public function is_completed() { return $this->get_value( self::COMPLETED ); } /** * Set completed state * * @param bool $is_completed Completed state. */ public function set_is_completed( $is_completed ) { $this->set_value( self::COMPLETED, $is_completed ); } /** * Start the process with thread-safe operations. * * @param int $total_items Total number of items to process. */ public function start( $total_items ) { $this->set_data( array( self::PROCESSING => true, self::CANCELLED => false, self::DEAD => false, self::COMPLETED => false, self::TOTAL_ITEMS => $total_items, self::PROCESSED_ITEMS => 0, self::FAILED_ITEMS => 0, ) ); } /** * Mark task as successful using atomic increment. */ public function task_successful() { // Use atomic increment with automatic initialization - no race condition. $this->thread_safe_options->increment_values( $this->get_option_id(), array( self::PROCESSED_ITEMS ) ); } /** * Mark task as failed using atomic increment. */ public function task_failed() { // Use atomic increment with automatic initialization - no race condition. $this->thread_safe_options->increment_values( $this->get_option_id(), array( self::PROCESSED_ITEMS, self::FAILED_ITEMS ) ); } /** * Complete the process */ public function complete() { $this->set_data( array( self::PROCESSING => false, self::CANCELLED => false, self::DEAD => false, self::COMPLETED => true, ) ); } /** * Cancel the process */ public function cancel() { $this->set_data( array( self::PROCESSING => false, self::CANCELLED => true, self::DEAD => false, self::COMPLETED => false, ) ); } /** * Mark process as dead */ public function mark_as_dead() { $this->set_data( array( self::PROCESSING => false, self::CANCELLED => false, self::DEAD => true, self::COMPLETED => false, ) ); } /** * Clear status */ public function clear() { $this->thread_safe_options->delete_option( $this->get_option_id() ); } /** * Check if process is running (compatibility method) * * @return bool */ public function is_running() { return $this->is_in_processing(); } /** * Get status option key (compatibility method) * * @return string */ private function get_status_key() { return $this->get_option_id(); } }