-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: Avoid unnecessary loop condition in duplicate links deletio…
…n script - refs BT#22323
- Loading branch information
Showing
1 changed file
with
23 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
@@ -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) && | ||
|
@@ -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 | ||
|
@@ -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"; | ||
} |