llms_update_300_migrate_lesson_postmeta()

Update keys of lesson meta fields for consistency


Return Return

(void)


Top ↑

Source Source

File: includes/functions/updates/llms-functions-updates-300.php

function llms_update_300_migrate_lesson_postmeta() {

	global $wpdb;

	llms_update_util_rekey_meta( 'lesson', '_llms_audio_embed', '_audio_embed' );
	llms_update_util_rekey_meta( 'lesson', '_llms_video_embed', '_video_embed' );
	llms_update_util_rekey_meta( 'lesson', '_llms_has_prerequisite', '_has_prerequisite' );
	llms_update_util_rekey_meta( 'lesson', '_llms_prerequisite', '_prerequisite' );
	llms_update_util_rekey_meta( 'lesson', '_llms_days_before_available', '_days_before_avalailable' );

	// Convert numeric has_preqeq to "yes".
	// Convert numeric free_lesson to "yes".
	// Convert numeric require_passing_grade to "yes".
	$wpdb->query(
		"UPDATE {$wpdb->prefix}postmeta AS m
		 INNER JOIN {$wpdb->prefix}posts AS p ON p.ID = m.post_ID
		 SET m.meta_value = 'yes'
	 	 WHERE p.post_type = 'lesson' AND (
	 	 	   ( m.meta_key = '_llms_has_prerequisite' AND m.meta_value = 1 )
	 	 	OR ( m.meta_key = '_llms_free_lesson' AND m.meta_value = 1 )
	 	 	OR ( m.meta_key = '_llms_require_passing_grade' AND m.meta_value = 1 )
	 	 );"
	); // db call ok; no-cache ok.

	// Convert empty has_prereq to "no".
	// Convert empty free_lesson to "no".
	// Convert empty require_passing_grade to "no".
	$wpdb->query(
		"UPDATE {$wpdb->prefix}postmeta AS m
		 INNER JOIN {$wpdb->prefix}posts AS p ON p.ID = m.post_ID
		 SET m.meta_value = 'no'
	 	 WHERE p.post_type = 'lesson' AND (
	 	 	   ( m.meta_key = '_llms_has_prerequisite' AND m.meta_value = '' )
	 	 	OR ( m.meta_key = '_llms_free_lesson' AND m.meta_value = '' )
	 	 	OR ( m.meta_key = '_llms_require_passing_grade' AND m.meta_value = '' )
	 	 );"
	); // db call ok; no-cache ok.

	// Updates course enrollment settings and reformats existing dates.
	$drips = $wpdb->get_results(
		"SELECT m.post_id
		 FROM {$wpdb->postmeta} AS m
		 INNER JOIN {$wpdb->posts} AS p ON p.ID = m.post_ID
	 	 WHERE p.post_type = 'lesson' AND m.meta_key = '_llms_days_before_available';"
	); // db call ok; no-cache ok.
	foreach ( $drips as $r ) {
		add_post_meta( $r->post_id, '_llms_drip_method', 'enrollment' );
	}

}


Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.