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