AnsPress_Upgrader::question_tasks( integer $id )

Description #

Process question tasks.

Parameters #

  • $id
    integer (Required) Question ID.

Source #

File: lib/class-anspress-upgrader.php

	private function question_tasks( $id ) {
		global $wpdb;

		$question = get_post( $id );

		$last_active = get_post_meta( $id, '_ap_updated', true );
		$views       = get_post_meta( $id, '_views', true );

		// Get all answers associated with current question.
		$this->answer_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} p WHERE post_type = 'answer' AND post_parent = %d ORDER BY post_date ASC", $id ) ); // phpcs:ignore WordPress.DB

		foreach ( (array) $this->answer_ids as $answer_id ) {
			$this->answer_tasks( $answer_id );
		}

		$answers_counts     = ap_count_published_answers( $id );
		$answer_id          = (int) get_post_meta( $id, '_ap_selected', true );
		$featured_questions = (array) get_option( 'featured_questions' );

		ap_insert_qameta(
			$id,
			array(
				'answers'      => $answers_counts,
				'views'        => (int) get_post_meta( $id, '_views', true ),
				'subscribers'  => (int) get_post_meta( $id, '_ap_subscriber', true ),
				'closed'       => ( 'closed' === $question->post_status ? 1 : 0 ),
				'flags'        => (int) get_post_meta( $id, '_ap_flag', true ),
				'selected_id'  => $answer_id,
				'featured'     => in_array( $id, $featured_questions ), // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
				'last_updated' => empty( $last_active ) ? $question->post_date : $last_active,
			)
		);

		ap_update_qameta_terms( $id );
		ap_update_post_attach_ids( $id );

		$this->migrate_votes( $id );
		$this->restore_last_activity( $id );

		delete_post_meta( $id, '_ap_answers' );
		delete_post_meta( $id, '_ap_participants' );
		delete_post_meta( $id, '_views' );
		delete_post_meta( $id, '_ap_subscriber' );
		delete_post_meta( $id, '_ap_selected' );
		delete_post_meta( $id, '_ap_vote' );
		delete_post_meta( $id, '_ap_flag' );
		delete_post_meta( $id, '_ap_selected' );

		$this->delete_question_metatables( $id );
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment