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
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. |