Skip to content

Commit ee723bc

Browse files
committed
Fix(🛠) : Migration Failed error message
1 parent ce161dc commit ee723bc

File tree

6 files changed

+52
-54
lines changed

6 files changed

+52
-54
lines changed

assets/js/admin.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ jQuery(document).ready(function ($) {
6161

6262
var $that = $(this);
6363
var $formData = $(this).serialize() + '&action=' + $that.attr('action');
64-
65-
// console.log(this);
66-
// console.log($that.attr('action'));
6764

6865

6966
let final_types = 'lp';
@@ -182,8 +179,8 @@ jQuery(document).ready(function ($) {
182179
}
183180

184181
const res = data.data;
185-
const {totalCourseCount = 0, failed = []} = res || {};
186-
if (Number(totalCourseCount) > 0) {
182+
const { total_course_count = 0, failed = []} = res || {};
183+
if (Number(total_course_count) > 0) {
187184
if (failed.length > 0) {
188185
tutor_toast(__('Partially Migrated', 'tutor-lms-migration-tool'), __('Some courses failed to migrate', 'tutor-lms-migration-tool'), 'error');
189186
} else {
@@ -403,4 +400,4 @@ const getFilesAndUpdateDOM = (files, inputEl, dropZone) => {
403400
dropZone.classList.remove('file-attached');
404401
dropZone.querySelector('.file-info').innerHTML = '';
405402
}
406-
};
403+
};

classes/LDtoTutorMigration.php

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ) {

inc/LDMigration/PostMeta/AssignmentMeta.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function migrate( int $post_id, string $post_type = 'sfwd-lessons' ) {
7373
}
7474

7575
try {
76-
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta, true, false );
76+
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta );
7777
} catch ( \Throwable $th ) {
7878
throw $th;
7979
}

inc/LDMigration/PostMeta/CourseMeta.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace Themeum\TutorLMSMigrationTool\LDMigration\PostMeta;
1212

13-
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
1413
use Tutor\Helpers\QueryHelper;
14+
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
1515

1616
/**
1717
* Handle course meta migration
@@ -52,7 +52,7 @@ public function migrate( int $post_id ) {
5252
$meta = $this->ld_to_tutor_meta_map( $migrate_able_meta );
5353
if ( is_array( $meta ) && count( $meta ) ) {
5454
try {
55-
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta, true, false );
55+
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta );
5656
} catch ( \Throwable $th ) {
5757
throw $th;
5858
}

inc/LDMigration/PostMeta/LessonMeta.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace Themeum\TutorLMSMigrationTool\LDMigration\PostMeta;
1212

13-
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
1413
use Tutor\Helpers\QueryHelper;
14+
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
1515

1616
/**
1717
* Handle course meta migration
@@ -47,7 +47,7 @@ public function migrate( int $post_id ) {
4747

4848
if ( is_array( $meta ) && count( $meta ) ) {
4949
try {
50-
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta, true, false );
50+
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta );
5151
} catch ( \Throwable $th ) {
5252
throw $th;
5353
}

inc/LDMigration/PostMeta/QuizMeta.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace Themeum\TutorLMSMigrationTool\LDMigration\PostMeta;
1212

13-
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
1413
use Tutor\Helpers\QueryHelper;
14+
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
1515

1616
/**
1717
* Handle quiz meta migration
@@ -56,7 +56,7 @@ public function migrate( int $post_id ) {
5656
}
5757

5858
try {
59-
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta, true, false );
59+
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta );
6060
} catch ( \Throwable $th ) {
6161
throw $th;
6262
}

0 commit comments

Comments
 (0)