public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Migrate the enrolement dates for the users on the system for courses.
 *
 * @since 1.0.0
 */
Migrate the enrolement dates for the users on the system for courses.
Migrate the enrolement dates for the users on the system for courses .
function WPCW_database_migration_enrolementDates() {
	global $wpdb, $wpcwdb;
	$findCoursesToUpdateSQL = "
		SELECT *
		FROM $wpcwdb->user_courses
		WHERE course_enrolment_date = '0000-00-00 00:00:00'
		GROUP BY user_id
		LIMIT 200
	";
	$rowsToUpdate           = $wpdb->get_results( $findCoursesToUpdateSQL );
	while ( ! empty( $rowsToUpdate ) ) {
		foreach ( $rowsToUpdate as $singleRow ) {
			$dateUpdated = false;
			$userData = get_userdata( $singleRow->user_id );
			if ( $userData ) {
				$registered = $userData->user_registered;
				if ( $registered != '0000-00-00 00:00:00' ) {
					$wpdb->query( $wpdb->prepare( "
	            		UPDATE $wpcwdb->user_courses
	            		SET course_enrolment_date = %s
	            		WHERE user_id = %d",
						$registered, $singleRow->user_id ) );
					$dateUpdated = true;
				}
			}
			if ( ! $dateUpdated ) {
				$wpdb->query( $wpdb->prepare( "
	            		UPDATE $wpcwdb->user_courses
	            		SET course_enrolment_date = %s
	            		WHERE user_id = %d",
					current_time( 'mysql' ), $singleRow->user_id ) );
			}
		}
		$rowsToUpdate = $wpdb->get_results( $findCoursesToUpdateSQL );
	}
}
function WPCW_database_migration_enrolementDates ( ) { global $ wpdb , $ wpcwdb ; $ findCoursesToUpdateSQL = " 
		SELECT *
		FROM  $ wpcwdb -> user_courses 
		WHERE course_enrolment_date = '0000-00-00 00:00:00'
		GROUP BY user_id
		LIMIT 200
	 " ; $ rowsToUpdate = $ wpdb -> get_results ( $ findCoursesToUpdateSQL ) ; while ( ! empty ( $ rowsToUpdate ) ) { foreach ( $ rowsToUpdate as $ singleRow ) { $ dateUpdated = false ; $ userData = get_userdata ( $ singleRow -> user_id ) ; if ( $ userData ) { $ registered = $ userData -> user_registered ; if ( $ registered != '0000-00-00 00:00:00' ) { $ wpdb -> query ( $ wpdb -> prepare ( " 
	            		UPDATE  $ wpcwdb -> user_courses 
	            		SET course_enrolment_date = %s
	            		WHERE user_id = %d " , $ registered , $ singleRow -> user_id ) ) ; $ dateUpdated = true ; } } if ( ! $ dateUpdated ) { $ wpdb -> query ( $ wpdb -> prepare ( " 
	            		UPDATE  $ wpcwdb -> user_courses 
	            		SET course_enrolment_date = %s
	            		WHERE user_id = %d " , current_time ( 'mysql' ) , $ singleRow -> user_id ) ) ; } } $ rowsToUpdate = $ wpdb -> get_results ( $ findCoursesToUpdateSQL ) ; } }
Migrate the enrolement dates for the users on the system for courses.
Migrate the enrolement dates for the users on the system for courses .
// 1 - Find the blank enrolement dates that need updating. Use // group by, as some users will be enroled on multiple courses, and this // saves work by updating multiple at once. // 2 - Loop through all records that need an update. Using a few records at a // time to save memory. // 3 - Iterate through each user and their progress, and get their // started date from their user meta. // 4 Try to get the meta data for this user. If the user has been deleted // but the course table still has a user, then $userData will return false. // Check date we've got is valid before we use it // end of userData // 5 - Just in case we have an invalid date from user_registered, we set today's // date. As we don't want any infinite loops from the null date loop above. // Continue the loop by looking for the next ones.