@@ -176,61 +176,62 @@ public function ld_migrate_course_to_tutor( $return_type = false ) {
176176 $ total_courses = tutils ()->count ( $ ld_courses );
177177 $ course_type = tutor ()->course_post_type ;
178178
179- if ( $ total_courses ) {
180- MigrationLogger::update_migration_log ( $ total_courses );
181-
182- $ course_i = (int ) get_option ( '_tutor_migrated_items_count ' );
183- foreach ( $ ld_courses as $ ld_course ) {
184- ++$ course_i ;
185- $ course_id = $ this ->update_post ( $ ld_course ->ID , $ course_type , 0 , '' );
186- if ( $ course_id ) {
187- try {
188- $ this ->migrate_course ( $ ld_course ->ID , $ course_id );
179+ if ( empty ( $ total_courses ) ) {
180+ throw new Exception ( __ ( 'No course available for migration ' , 'tutor-lms-migration-tool ' ) );
181+ }
189182
190- do_action ( ' tlmt_course_migrated ' , $ course_id , MigrationTypes:: LD_TO_TUTOR );
183+ MigrationLogger:: update_migration_log ( $ total_courses );
191184
192- update_option ( '_tutor_migrated_items_count ' , $ course_i );
185+ $ course_i = ( int ) get_option ( '_tutor_migrated_items_count ' );
193186
194- // Attached Product
195- do_action ( 'tlmt_attach_product ' , $ course_id , MigrationTypes::LD_TO_TUTOR );
187+ foreach ( $ ld_courses as $ ld_course ) {
188+ ++$ course_i ;
189+ $ course_id = $ this ->update_post ( $ ld_course ->ID , $ course_type , 0 , '' );
190+ if ( $ course_id ) {
191+ try {
192+ $ this ->migrate_course ( $ ld_course ->ID , $ course_id );
196193
197- // Attached Prerequisite.
198- $ this ->attached_prerequisite ( $ course_id );
194+ do_action ( 'tlmt_course_migrated ' , $ course_id , MigrationTypes::LD_TO_TUTOR );
199195
200- // Add Enrollments.
201- $ this ->insert_enrollment ( $ course_id );
196+ update_option ( '_tutor_migrated_items_count ' , $ course_i );
202197
203- // Attached thumbnail.
204- $ this -> insert_thumbnail ( $ ld_course -> ID , $ course_id );
198+ // Attached Product
199+ do_action ( ' tlmt_attach_product ' , $ course_id, MigrationTypes:: LD_TO_TUTOR );
205200
206- /**
207- * Insert Student Progress
208- *
209- * @since 2.3.0
210- */
211- do_action ( 'tlmt_student_progress_migrated ' , MigrationTypes::LD_TO_TUTOR );
201+ // Attached Prerequisite.
202+ $ this ->attached_prerequisite ( $ course_id );
212203
213- MigrationLogger::update_course_migration_log ( $ course_id , true );
214- } catch ( \Throwable $ th ) {
215- // Revert the status if failed to migrate.
216- $ revert = array (
217- 'ID ' => $ course_id ,
218- 'post_status ' => self ::LD_COURSE_TYPE ,
219- );
204+ // Add Enrollments.
205+ $ this ->insert_enrollment ( $ course_id );
220206
221- wp_update_post ( $ revert );
207+ // Attached thumbnail.
208+ $ this ->insert_thumbnail ( $ ld_course ->ID , $ course_id );
222209
223- MigrationLogger::update_course_migration_log ( $ course_id , true );
224- throw $ th ;
225- }
210+ /**
211+ * Insert Student Progress
212+ *
213+ * @since 2.3.0
214+ */
215+ do_action ( 'tlmt_student_progress_migrated ' , MigrationTypes::LD_TO_TUTOR );
216+
217+ MigrationLogger::update_course_migration_log ( $ course_id , true );
218+ } catch ( \Throwable $ th ) {
219+ // Revert the status if failed to migrate.
220+ $ revert = array (
221+ 'ID ' => $ course_id ,
222+ 'post_status ' => self ::LD_COURSE_TYPE ,
223+ );
224+
225+ wp_update_post ( $ revert );
226+
227+ MigrationLogger::update_course_migration_log ( $ course_id , true );
228+ throw $ th ;
226229 }
227230 }
228-
229- // Migrate Assignment Files.
230- tlmt_get_post_obj ( ContentTypes::ASSIGNMENT , MigrationTypes::LD_TO_TUTOR )->migrate_assignment_files ();
231231 }
232232
233- throw new Exception ( __ ( 'No course available for migration ' , 'tutor-lms-migration-tool ' ) );
233+ // Migrate Assignment Files.
234+ tlmt_get_post_obj ( ContentTypes::ASSIGNMENT , MigrationTypes::LD_TO_TUTOR )->migrate_assignment_files ();
234235 }
235236
236237 public function attached_prerequisite ( $ course_id ) {
0 commit comments