Bladeren bron

Couple of fixes to the attachment maintenance: a) added more cases of attachments existing on disk but not in the database, b) fixed issue with maintenance looping indefinitely if the query took longer than 3 seconds

Signed-off-by: emanuele <[email protected]>
emanuele 12 jaren geleden
bovenliggende
commit
8f0bb65acb
1 gewijzigde bestanden met toevoegingen van 17 en 4 verwijderingen
  1. 17 4
      Sources/ManageAttachments.php

+ 17 - 4
Sources/ManageAttachments.php

@@ -217,7 +217,7 @@ function ManageAttachmentSettings($return_config = false)
 
 
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir']))
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir']))
 					if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments']))
 					if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments']))
-						$_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments'];				}
+						$_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments'];
 
 
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
 				{
 				{
@@ -1082,7 +1082,7 @@ function RepairAttachments()
 	@set_time_limit(600);
 	@set_time_limit(600);
 
 
 	$_GET['step'] = empty($_GET['step']) ? 0 : (int) $_GET['step'];
 	$_GET['step'] = empty($_GET['step']) ? 0 : (int) $_GET['step'];
-	$_GET['substep'] = empty($_GET['substep']) ? 0 : (int) $_GET['substep'];
+	$_SESSION['starting_substep'] = $_GET['substep'] = empty($_GET['substep']) ? 0 : (int) $_GET['substep'];
 
 
 	// Don't recall the session just in case.
 	// Don't recall the session just in case.
 	if ($_GET['step'] == 0 && $_GET['substep'] == 0)
 	if ($_GET['step'] == 0 && $_GET['substep'] == 0)
@@ -1578,7 +1578,7 @@ function RepairAttachments()
 								);
 								);
 								if ($smcFunc['db_num_rows']($request) == 0)
 								if ($smcFunc['db_num_rows']($request) == 0)
 								{
 								{
-									if ($fix_errors)
+									if ($fix_errors && in_array('files_without_attachment', $to_fix))
 									{
 									{
 										@unlink($attach_dir . '/' . $file);
 										@unlink($attach_dir . '/' . $file);
 									}
 									}
@@ -1591,8 +1591,21 @@ function RepairAttachments()
 								$smcFunc['db_free_result']($request);
 								$smcFunc['db_free_result']($request);
 							}
 							}
 						}
 						}
+						elseif ($file != 'index.php')
+						{
+							if ($fix_errors && in_array('files_without_attachment', $to_fix))
+							{
+								@unlink($attach_dir . '/' . $file);
+							}
+							else
+							{
+								$context['repair_errors']['files_without_attachment']++;
+								$to_fix[] = 'files_without_attachment';
+							}
+						}
 					}
 					}
 					$current_check++;
 					$current_check++;
+					$_GET['substep'] = $current_check;
 					if ($current_check - $files_checked >= $max_checks)
 					if ($current_check - $files_checked >= $max_checks)
 						pauseAttachmentMaintenance($to_fix);
 						pauseAttachmentMaintenance($to_fix);
 				}
 				}
@@ -1634,7 +1647,7 @@ function pauseAttachmentMaintenance($to_fix, $max_substep = 0)
 		@apache_reset_timeout();
 		@apache_reset_timeout();
 
 
 	// Have we already used our maximum time?
 	// Have we already used our maximum time?
-	if (time() - array_sum(explode(' ', $time_start)) < 3)
+	if (time() - array_sum(explode(' ', $time_start)) < 3 || $_SESSION['starting_substep'] == $_GET['substep'])
 		return;
 		return;
 
 
 	$context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id'];
 	$context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id'];