Browse Source

! Fix Mantis issue 4912: if a scheduled task throws an error, note it and pass it back in the event of running tasks manually from the ACP.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 10 years ago
parent
commit
46699b9bc9

+ 11 - 0
Sources/ManageScheduledTasks.php

@@ -157,9 +157,20 @@ function ScheduledTasks()
 			}
 		}
 		$smcFunc['db_free_result']($request);
+
+		// If we had any errors, push them to session so we can pick them up next time to tell the user.
+		if (!empty($context['scheduled_errors']))
+			$_SESSION['st_error'] = $context['scheduled_errors'];
+
 		redirectexit('action=admin;area=scheduledtasks;done');
 	}
 
+	if (isset($_SESSION['st_error']))
+	{
+		$context['scheduled_errors'] = $_SESSION['st_error'];
+		unset ($_SESSION['st_error']);
+	}
+
 	$listOptions = array(
 		'id' => 'scheduled_tasks',
 		'title' => $txt['maintain_tasks'],

+ 17 - 5
Sources/ScheduledTasks.php

@@ -1246,7 +1246,7 @@ function loadEssentialThemeData()
  */
 function scheduled_fetchSMfiles()
 {
-	global $sourcedir, $txt, $language, $settings, $forum_version, $modSettings, $smcFunc;
+	global $sourcedir, $txt, $language, $settings, $forum_version, $modSettings, $smcFunc, $context;
 
 	// What files do we want to get
 	$request = $smcFunc['db_query']('', '
@@ -1285,9 +1285,10 @@ function scheduled_fetchSMfiles()
 		// Get the file
 		$file_data = fetch_web_data($url);
 
-		// If we got an error - give up - the site might be down.
+		// If we got an error - give up - the site might be down. And if we should happen to be coming from elsewhere, let's also make a note of it.
 		if ($file_data === false)
 		{
+			$context['scheduled_errors']['fetchSMfiles'][] = sprintf($txt['st_cannot_retrieve_file'], $url);
 			log_error(sprintf($txt['st_cannot_retrieve_file'], $url));
 			return false;
 		}
@@ -1663,7 +1664,7 @@ function scheduled_paid_subscriptions()
  */
 function scheduled_remove_temp_attachments()
 {
-	global $modSettings;
+	global $modSettings, $context, $txt;
 
 	// We need to know where this thing is going.
 	if (!empty($modSettings['currentAttachmentUploadDir']))
@@ -1681,7 +1682,16 @@ function scheduled_remove_temp_attachments()
 
 	foreach ($attach_dirs as $attach_dir)
 	{
-		$dir = @opendir($attach_dir) or fatal_lang_error('cant_access_upload_path', 'critical');
+		$dir = @opendir($attach_dir);
+		if (!$dir)
+		{
+			loadEssentialThemeData();
+			loadLanguage('Post');
+			$context['scheduled_errors']['remove_temp_attachments'][] = $txt['cant_access_upload_path'] . ' (' . $attach_dir . ')';
+			log_error($txt['cant_access_upload_path'] . ' (' . $attach_dir . ')', 'critical');
+			return false;
+		}
+
 		while ($file = readdir($dir))
 		{
 			if ($file == '.' || $file == '..')
@@ -1696,6 +1706,8 @@ function scheduled_remove_temp_attachments()
 		}
 		closedir($dir);
 	}
+
+	return true;
 }
 
 /**
@@ -1747,7 +1759,7 @@ function scheduled_remove_old_drafts()
 		return true;
 
 	// init
-	$drafts= array();
+	$drafts = array();
 
 	// We need this for lanaguage items
 	loadEssentialThemeData();

+ 26 - 1
Themes/default/ManageScheduledTasks.template.php

@@ -17,10 +17,35 @@ function template_view_scheduled_tasks()
 
 	// We completed some tasks?
 	if (!empty($context['tasks_were_run']))
-		echo '
+	{
+		if (empty($context['scheduled_errors']))
+			echo '
 	<div id="task_completed">
 		', $txt['scheduled_tasks_were_run'], '
 	</div>';
+		else
+		{
+			echo '
+	<div class="errorbox" id="errors">
+			<dl>
+				<dt>
+					<strong id="error_serious">', $txt['scheduled_tasks_were_run_errors'], '</strong>
+				</dt>';
+
+			foreach ($context['scheduled_errors'] as $task => $errors)
+			{
+				echo '
+				<dd class="error">
+					<strong>', isset($txt['scheduled_task_' . $task]) ? $txt['scheduled_task_' . $task] : $task, '</strong>
+					<ul><li>', implode('</li><li>', $errors), '</li></ul>
+				</dd>';
+			}
+
+			echo '
+			</dl>
+		</div>';
+		}
+	}
 
 	template_show_list('scheduled_tasks');
 }

+ 1 - 0
Themes/default/languages/ManageScheduledTasks.english.php

@@ -11,6 +11,7 @@ $txt['scheduled_tasks_run_now'] = 'Run Now';
 $txt['scheduled_tasks_save_changes'] = 'Save Changes';
 $txt['scheduled_tasks_time_offset'] = '<strong>Note:</strong> All times given below are <em>server time</em> and do not take any time offsets setup within SMF into account.';
 $txt['scheduled_tasks_were_run'] = 'All selected tasks were completed';
+$txt['scheduled_tasks_were_run_errors'] = 'All selected tasks were completed but some had errors:';
 
 $txt['scheduled_tasks_na'] = 'N/A';
 $txt['scheduled_task_approval_notification'] = 'Approval Notifications';