Skip to content

Commit

Permalink
Internal: Avoid unnecessary loop condition in duplicate links deletio…
Browse files Browse the repository at this point in the history
…n script - refs BT#22323
  • Loading branch information
ywarnier committed Jan 15, 2025
1 parent 13dbffa commit e050721
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions tests/scripts/delete_duplicate_links.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* first place (they were probably duplicated through a short/broken process) and
* this is where most of the time is spent during deletion.
* @author Yannick Warnier <[email protected]>
* @author Christian Fasanando <[email protected]>
*/
exit; //remove this line to execute from the command line

Expand Down Expand Up @@ -62,6 +63,9 @@
if (empty($course['id'])) {
continue; // Skip invalid course IDs
}
if ($debug) {
echo "\n-= Course ".$course['id']." (".$course['code'].") =-\n----\n";
}

$sql2 = "SELECT iid, url, title, description, category_id, on_homepage, target, session_id
FROM c_link
Expand All @@ -84,7 +88,14 @@

foreach ($links as $key => $original) {
$originalsCount++;
// Make sure we don't use a just-deleted link as original
if (in_array($original['iid'], $processedDuplicates)) {
continue;
}
foreach ($links as $key2 => $duplicate) {
if ($debug) {
echo "Checking potential duplicate link ".$duplicate['iid']." against original ".$original['iid']."\n";
}
if (
$key !== $key2 &&
!in_array($duplicate['iid'], $processedDuplicates) &&
Expand All @@ -99,8 +110,8 @@
) {
$duplicatesCount++;
if ($debug) {
echo "\nDuplicate found in Course ID: " . $course['id'] . "\n";
echo "Original IID=" . $original['iid'] . ", Duplicate IID=" . $duplicate['iid'] . "\n";
echo "\n[".date('Y-m-d h:i:s')."]\nDuplicate found in Course ID: " . $course['id'] . "\n";
echo "Original IID=" . $original['iid'] . ", Duplicate IID=" . $duplicate['iid'] . " ($duplicatesCount)\n";
}

// Check if duplicate exists in c_lp_item
Expand Down Expand Up @@ -129,12 +140,16 @@
}
}
}
if ($debug) {
echo "Ending course ".$course['id']."\n\n";
}
}

// Summary
echo "\nSummary:\n";
echo "- Total duplicates detected: $duplicatesCount\n";
echo "- Duplicates ignored (in learning paths): $itemsInLP\n";
echo "- Duplicates deleted: $deletedCount\n";

echo "[" . time() . "] Process complete.\n";
if ($debug) {
echo "\nSummary:\n";
echo "- Total duplicates detected: $duplicatesCount\n";
echo "- Duplicates ignored (in learning paths): $itemsInLP\n";
echo "- Duplicates deleted: $deletedCount\n";
echo "[".time()."] Process complete.\n";
}

0 comments on commit e050721

Please sign in to comment.