Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ jQuery(document).ready(function ($) {

var $that = $(this);
var $formData = $(this).serialize() + '&action=' + $that.attr('action');

// console.log(this);
// console.log($that.attr('action'));


let final_types = 'lp';
Expand Down Expand Up @@ -182,8 +179,8 @@ jQuery(document).ready(function ($) {
}

const res = data.data;
const {totalCourseCount = 0, failed = []} = res || {};
if (Number(totalCourseCount) > 0) {
const { total_course_count = 0, failed = []} = res || {};
if (Number(total_course_count) > 0) {
if (failed.length > 0) {
tutor_toast(__('Partially Migrated', 'tutor-lms-migration-tool'), __('Some courses failed to migrate', 'tutor-lms-migration-tool'), 'error');
} else {
Expand Down Expand Up @@ -403,4 +400,4 @@ const getFilesAndUpdateDOM = (files, inputEl, dropZone) => {
dropZone.classList.remove('file-attached');
dropZone.querySelector('.file-info').innerHTML = '';
}
};
};
83 changes: 42 additions & 41 deletions classes/LDtoTutorMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,61 +177,62 @@ public function ld_migrate_course_to_tutor( $return_type = false ) {
$total_courses = tutils()->count( $ld_courses );
$course_type = tutor()->course_post_type;

if ( $total_courses ) {
MigrationLogger::update_migration_log( $total_courses );

$course_i = (int) get_option( '_tutor_migrated_items_count' );
foreach ( $ld_courses as $ld_course ) {
++$course_i;
$course_id = $this->update_post( $ld_course->ID, $course_type, 0, '' );
if ( $course_id ) {
try {
$this->migrate_course( $ld_course->ID, $course_id );
if ( empty( $total_courses ) ) {
throw new Exception( __( 'No course available for migration', 'tutor-lms-migration-tool' ) );
}

do_action( 'tlmt_course_migrated', $course_id, MigrationTypes::LD_TO_TUTOR );
MigrationLogger::update_migration_log( $total_courses );

update_option( '_tutor_migrated_items_count', $course_i );
$course_i = (int) get_option( '_tutor_migrated_items_count' );

// Attached Product
do_action( 'tlmt_attach_product', $course_id, MigrationTypes::LD_TO_TUTOR );
foreach ( $ld_courses as $ld_course ) {
++$course_i;
$course_id = $this->update_post( $ld_course->ID, $course_type, 0, '' );
if ( $course_id ) {
try {
$this->migrate_course( $ld_course->ID, $course_id );

// Attached Prerequisite.
$this->attached_prerequisite( $course_id );
do_action( 'tlmt_course_migrated', $course_id, MigrationTypes::LD_TO_TUTOR );

// Add Enrollments.
$this->insert_enrollment( $course_id );
update_option( '_tutor_migrated_items_count', $course_i );

// Attached thumbnail.
$this->insert_thumbnail( $ld_course->ID, $course_id );
// Attached Product
do_action( 'tlmt_attach_product', $course_id, MigrationTypes::LD_TO_TUTOR );

/**
* Insert Student Progress
*
* @since 2.3.0
*/
do_action( 'tlmt_student_progress_migrated', MigrationTypes::LD_TO_TUTOR );
// Attached Prerequisite.
$this->attached_prerequisite( $course_id );

MigrationLogger::update_course_migration_log( $course_id, true );
} catch ( \Throwable $th ) {
// Revert the status if failed to migrate.
$revert = array(
'ID' => $course_id,
'post_status' => self::LD_COURSE_TYPE,
);
// Add Enrollments.
$this->insert_enrollment( $course_id );

wp_update_post( $revert );
// Attached thumbnail.
$this->insert_thumbnail( $ld_course->ID, $course_id );

MigrationLogger::update_course_migration_log( $course_id, true );
throw $th;
}
/**
* Insert Student Progress
*
* @since 2.3.0
*/
do_action( 'tlmt_student_progress_migrated', MigrationTypes::LD_TO_TUTOR );

MigrationLogger::update_course_migration_log( $course_id, true );
} catch ( \Throwable $th ) {
// Revert the status if failed to migrate.
$revert = array(
'ID' => $course_id,
'post_status' => self::LD_COURSE_TYPE,
);

wp_update_post( $revert );

MigrationLogger::update_course_migration_log( $course_id, true );
throw $th;
}
}

// Migrate Assignment Files.
tlmt_get_post_obj( ContentTypes::ASSIGNMENT, MigrationTypes::LD_TO_TUTOR )->migrate_assignment_files();
}

throw new Exception( __( 'No course available for migration', 'tutor-lms-migration-tool' ) );
// Migrate Assignment Files.
tlmt_get_post_obj( ContentTypes::ASSIGNMENT, MigrationTypes::LD_TO_TUTOR )->migrate_assignment_files();
}

public function attached_prerequisite( $course_id ) {
Expand Down
2 changes: 1 addition & 1 deletion inc/LDMigration/PostMeta/AssignmentMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function migrate( int $post_id, string $post_type = 'sfwd-lessons' ) {
}

try {
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta, true, false );
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta );
} catch ( \Throwable $th ) {
throw $th;
}
Expand Down
4 changes: 2 additions & 2 deletions inc/LDMigration/PostMeta/CourseMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Themeum\TutorLMSMigrationTool\LDMigration\PostMeta;

use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
use Tutor\Helpers\QueryHelper;
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;

/**
* Handle course meta migration
Expand Down Expand Up @@ -52,7 +52,7 @@ public function migrate( int $post_id ) {
$meta = $this->ld_to_tutor_meta_map( $migrate_able_meta );
if ( is_array( $meta ) && count( $meta ) ) {
try {
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta, true, false );
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta );
} catch ( \Throwable $th ) {
throw $th;
}
Expand Down
4 changes: 2 additions & 2 deletions inc/LDMigration/PostMeta/LessonMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Themeum\TutorLMSMigrationTool\LDMigration\PostMeta;

use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
use Tutor\Helpers\QueryHelper;
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;

/**
* Handle course meta migration
Expand Down Expand Up @@ -47,7 +47,7 @@ public function migrate( int $post_id ) {

if ( is_array( $meta ) && count( $meta ) ) {
try {
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta, true, false );
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta );
} catch ( \Throwable $th ) {
throw $th;
}
Expand Down
4 changes: 2 additions & 2 deletions inc/LDMigration/PostMeta/QuizMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Themeum\TutorLMSMigrationTool\LDMigration\PostMeta;

use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;
use Tutor\Helpers\QueryHelper;
use Themeum\TutorLMSMigrationTool\Interfaces\PostMeta;

/**
* Handle quiz meta migration
Expand Down Expand Up @@ -56,7 +56,7 @@ public function migrate( int $post_id ) {
}

try {
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta, true, false );
QueryHelper::insert_multiple_rows( $wpdb->postmeta, $meta );
} catch ( \Throwable $th ) {
throw $th;
}
Expand Down
Loading