public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/classes/import.php
/**
		 * Function that performs the actual course import.
		 * @return Integer The ID of the newly imported course.
		 */
Function that performs the actual course import.
@return Integer The ID of the newly imported course.
Function that performs the actual course import . @return Integer The ID of the newly imported course .
public function importCourseIntoDatabase() {
			if ( ! current_user_can( 'manage_options' ) ) {
				return $this->returnErrorList( __( 'Sorry, you\'re not allowed to import courses into WordPress.', 'wp-courseware' ) );
			}
			$courseData = $this->loadCourseData();
			$coursePostData     = $courseData;
			$coursePostDataKeys = array( 'course_status' );
			if ( count( $courseData ) == 0 ) {
				return $this->returnErrorList( __( 'There was no course data to import.', 'wp-courseware' ) );
			}
			$this->questionData = $this->loadQuestionData();
			$moduleData         = $this->loadModuleData();
			global $wpdb, $wpcwdb;
			$wpdb->show_errors();
			foreach ( $courseData as $courseDataKey => $courseDataItem ) {
				if ( in_array( $courseDataKey, $coursePostDataKeys ) ) {
					unset( $courseData[ $courseDataKey ] );
				}
			}
			$queryResult = $wpdb->query( arrayToSQLInsert( $wpcwdb->courses, $courseData ) );
			if ( $queryResult === false ) {
				return $this->returnErrorList( __( 'Could not create course in database.', 'wp-courseware' ) );
			}
			$this->course_id = $wpdb->insert_id;
			$course_object = new \WPCW\Models\Course( absint( $this->course_id ) );
			if ( $course_object instanceof \WPCW\Models\Course ) {
				$post_id = $course_object->get_course_post_id();
				if ( empty( $post_id ) || 0 === $post_id ) {
					$this->course_post_id = $course_object->create_post();
				}
			}
			$unitCount        = 0;
			$this->unit_order = 0;
			if ( $moduleData ) {
				$moduleCount = 0;
				foreach ( $moduleData as $moduleItem ) {
					$unitData = $moduleItem['units'];
					unset( $moduleItem['units'] );
					$moduleCount ++;
					$moduleItem['parent_course_id'] = $this->course_id;
					$moduleItem['module_order']     = $moduleCount;
					$moduleItem['module_number']    = $moduleCount;
					$queryResult = $wpdb->query( arrayToSQLInsert( $wpcwdb->modules, $moduleItem ) );
					if ( $queryResult === false ) {
						return $this->returnErrorList( __( 'There was a problem inserting the module into the database.', 'wp-courseware' ) );
					}
					$currentModuleID = $wpdb->insert_id;
					$unitCount += $this->addUnitsToDatabase( $unitData, $currentModuleID );
				}
			} 
			$courseDetails = WPCW_courses_getCourseDetails( $this->course_id );
			do_action( 'wpcw_course_details_updated', $courseDetails );
			return $this->errorList;
		}
public function importCourseIntoDatabase ( ) { if ( ! current_user_can ( 'manage_options' ) ) { return $ this -> returnErrorList ( __ ( 'Sorry, you\'re not allowed to import courses into WordPress.' , 'wp-courseware' ) ) ; } $ courseData = $ this -> loadCourseData ( ) ; $ coursePostData = $ courseData ; $ coursePostDataKeys = array ( 'course_status' ) ; if ( count ( $ courseData ) == 0 ) { return $ this -> returnErrorList ( __ ( 'There was no course data to import.' , 'wp-courseware' ) ) ; } $ this -> questionData = $ this -> loadQuestionData ( ) ; $ moduleData = $ this -> loadModuleData ( ) ; global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; foreach ( $ courseData as $ courseDataKey => $ courseDataItem ) { if ( in_array ( $ courseDataKey , $ coursePostDataKeys ) ) { unset ( $ courseData [ $ courseDataKey ] ) ; } } $ queryResult = $ wpdb -> query ( arrayToSQLInsert ( $ wpcwdb -> courses , $ courseData ) ) ; if ( $ queryResult === false ) { return $ this -> returnErrorList ( __ ( 'Could not create course in database.' , 'wp-courseware' ) ) ; } $ this -> course_id = $ wpdb -> insert_id ; $ course_object = new \ WPCW \ Models \ Course ( absint ( $ this -> course_id ) ) ; if ( $ course_object instanceof \ WPCW \ Models \ Course ) { $ post_id = $ course_object -> get_course_post_id ( ) ; if ( empty ( $ post_id ) || 0 === $ post_id ) { $ this -> course_post_id = $ course_object -> create_post ( ) ; } } $ unitCount = 0 ; $ this -> unit_order = 0 ; if ( $ moduleData ) { $ moduleCount = 0 ; foreach ( $ moduleData as $ moduleItem ) { $ unitData = $ moduleItem [ 'units' ] ; unset ( $ moduleItem [ 'units' ] ) ; $ moduleCount ++ ; $ moduleItem [ 'parent_course_id' ] = $ this -> course_id ; $ moduleItem [ 'module_order' ] = $ moduleCount ; $ moduleItem [ 'module_number' ] = $ moduleCount ; $ queryResult = $ wpdb -> query ( arrayToSQLInsert ( $ wpcwdb -> modules , $ moduleItem ) ) ; if ( $ queryResult === false ) { return $ this -> returnErrorList ( __ ( 'There was a problem inserting the module into the database.' , 'wp-courseware' ) ) ; } $ currentModuleID = $ wpdb -> insert_id ; $ unitCount += $ this -> addUnitsToDatabase ( $ unitData , $ currentModuleID ) ; } } $ courseDetails = WPCW_courses_getCourseDetails ( $ this -> course_id ) ; do_action ( 'wpcw_course_details_updated' , $ courseDetails ) ; return $ this -> errorList ; }
Function that performs the actual course import.
Function that performs the actual course import .
// ### 1) Extract XML data into a clean array of information. // The functions below may handle detailed verification of data in // future releases. // Course Post Data Keys. // ### 2) Turn the course into an actual database entry // ### 3) Now try to load module and question data. Most load question data first, as the load module data // 		  function relies on it. // Check query succeeded. // Attempt to Create Course Post. // Track how many units we add // ### 4) Check for the module data, and then try to add this to the system // Extract Unit Data from module info, so it doesn't interfere with database add // Add parent course details, plus order details. // Check query succeeded. // ### 4) Check for any units // end if $moduleData // Update unit counts // 31st May 2013 - V1.26 - Fix - Incorrectly referring to $course_id - which is empty. // Changed to $this->course_id to fix issue. // Return any errors if there are any