llms_update_3160_update_attempt_question_data()
Update question data to new formats & match question choice indexes to new choice IDs
Return Return
(void)
Source Source
File: includes/functions/updates/llms-functions-updates-3160.php
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | function llms_update_3160_update_attempt_question_data() { if ( 'complete' !== get_transient( 'llms_update_3160_update_question_data' ) ) { return true; } $skip = get_transient( 'llms_update_3160_skipper' ); if ( ! $skip ) { $skip = 0; } set_transient( 'llms_update_3160_skipper' , $skip + 500, DAY_IN_SECONDS ); global $wpdb ; $res = $wpdb ->get_col( $wpdb ->prepare( "SELECT id FROM {$wpdb->prefix}lifterlms_quiz_attempts ORDER BY id ASC LIMIT %d, 500" , $skip ) ); // db call ok; no-cache ok. // Finished. if ( ! $res ) { set_transient( 'llms_update_3160_update_attempt_question_data' , 'complete' , DAY_IN_SECONDS ); return false; } foreach ( $res as $att_id ) { $attempt = new LLMS_Quiz_Attempt( $att_id ); $questions = $attempt ->get_questions(); foreach ( $questions as & $question ) { $question [ 'earned' ] = empty ( $question [ 'correct' ] ) ? 0 : $question [ 'points' ]; if ( ! isset( $question [ 'answer' ] ) ) { $question [ 'answer' ] = array (); } elseif ( ! is_array ( $question [ 'answer' ] ) && is_numeric ( $question [ 'answer' ] ) ) { $obj = llms_get_post( $question [ 'id' ] ); if ( $obj ) { $choices = $obj ->get_choices(); if ( isset( $choices [ $question [ 'answer' ] ] ) ) { $question [ 'answer' ] = array ( $choices [ $question [ 'answer' ] ]->get( 'id' ) ); } } } } $attempt ->set_questions( $questions , true ); } return true; } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.16.0 | Introduced. |