Code Duplication    Length = 21-21 lines in 2 locations

includes/class-sensei-updates.php 2 locations

@@ 1368-1388 (lines=21) @@
1365
				// Check it doesn't already exist
1366
				$sql = $wpdb->prepare( $check_existing_sql, $lesson_id, $user_id );
1367
				$comment_ID = $wpdb->get_var( $sql );
1368
				if ( !$comment_ID ) {
1369
					// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1370
					$wpdb->insert($wpdb->comments, $data);
1371
					$comment_ID = (int) $wpdb->insert_id;
1372
1373
					if ( $comment_ID && !empty($meta_data) ) {
1374
						foreach ( $meta_data as $key => $value ) {
1375
							// Bypassing WP add_comment_meta(() so no actions/filters are run
1376
							if ( $wpdb->get_var( $wpdb->prepare(
1377
									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1378
									$comment_ID, $key ) ) ) {
1379
									continue; // Found the meta data already
1380
							}
1381
							$result = $wpdb->insert( $wpdb->commentmeta, array(
1382
								'comment_id' => $comment_ID,
1383
								'meta_key' => $key,
1384
								'meta_value' => $value
1385
							) );
1386
						}
1387
					}
1388
				}
1389
			}
1390
		}
1391
		$wpdb->flush();
@@ 1507-1527 (lines=21) @@
1504
				// Check it doesn't already exist
1505
				$sql = $wpdb->prepare( $check_existing_sql, $course_id, $user_id );
1506
				$comment_ID = $wpdb->get_var( $sql );
1507
				if ( !$comment_ID ) {
1508
					// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1509
					$wpdb->insert($wpdb->comments, $data);
1510
					$comment_ID = (int) $wpdb->insert_id;
1511
1512
					if ( $comment_ID && !empty($meta_data) ) {
1513
						foreach ( $meta_data as $key => $value ) {
1514
							// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1515
							if ( $wpdb->get_var( $wpdb->prepare(
1516
									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1517
									$comment_ID, $key ) ) ) {
1518
									continue; // Found the meta data already
1519
							}
1520
							$result = $wpdb->insert( $wpdb->commentmeta, array(
1521
								'comment_id' => $comment_ID,
1522
								'meta_key' => $key,
1523
								'meta_value' => $value
1524
							) );
1525
						}
1526
					}
1527
				}
1528
			}
1529
		}
1530
		$wpdb->flush();