function my_shutdown() { global $script_stage, $reload; # processQueueOutput( "Script status: ".connection_status(),0); # with PHP 4.2.1 buggy. http://bugs.php.net/bug.php?id=17774 processQueueOutput(s('Script stage') . ': ' . $script_stage, 0, 'progress'); global $counters, $report, $send_process_id, $tables, $nothingtodo, $processed, $notsent, $unconfirmed, $batch_period; $some = $processed; $delaytime = 0; if (!$some) { processQueueOutput($GLOBALS['I18N']->get('Finished, Nothing to do'), 0, 'progress'); $nothingtodo = 1; } $totaltime = $GLOBALS['processqueue_timer']->elapsed(1); if ($totaltime > 0) { $msgperhour = 3600 / $totaltime * $counters['sent']; } else { $msgperhour = s('Calculating'); } if ($counters['sent']) { processQueueOutput(sprintf('%d %s %01.2f %s (%d %s)', $counters['sent'], $GLOBALS['I18N']->get('messages sent in'), $totaltime, $GLOBALS['I18N']->get('seconds'), $msgperhour, $GLOBALS['I18N']->get('msgs/hr')), $counters['sent'], 'progress'); } if ($counters['invalid']) { processQueueOutput(s('%d invalid email addresses', $counters['invalid']), 1, 'progress'); } if ($counters['failed_sent']) { processQueueOutput(s('%d failed (will retry later)', $counters['failed_sent']), 1, 'progress'); foreach ($counters as $label => $value) { # processQueueOutput(sprintf('%d %s',$value,$GLOBALS['I18N']->get($label)),1,'progress'); cl_output(sprintf('%d %s', $value, $GLOBALS['I18N']->get($label))); } } if ($unconfirmed) { processQueueOutput(sprintf($GLOBALS['I18N']->get('%d emails unconfirmed (not sent)'), $unconfirmed), 1, 'progress'); } foreach ($GLOBALS['plugins'] as $pluginname => $plugin) { $plugin->processSendStats($counters['sent'], $counters['invalid'], $counters['failed_sent'], $unconfirmed, $counters); } flushClickTrackCache(); releaseLock($send_process_id); finish('info', $report, $script_stage); if ($script_stage < 5 && !$nothingtodo) { processQueueOutput($GLOBALS['I18N']->get('Warning: script never reached stage 5') . "\n" . $GLOBALS['I18N']->get('This may be caused by a too slow or too busy server') . " \n"); } elseif ($script_stage == 5 && (!$nothingtodo || isset($GLOBALS['wait']))) { # if the script timed out in stage 5, reload the page to continue with the rest ++$reload; if (!$GLOBALS['commandline'] && $counters['num_per_batch'] && $batch_period) { if ($counters['sent'] + 10 < $GLOBALS['original_num_per_batch']) { processQueueOutput($GLOBALS['I18N']->get('Less than batch size were sent, so reloading imminently'), 1, 'progress'); $counters['delaysend'] = 10; } else { $counters['delaysend'] = (int) ($batch_period - $totaltime); $delaytime = 30; ## actually with the iframe we can reload fairly quickly processQueueOutput(s('Waiting for %d seconds before reloading', $delaytime), 1, 'progress'); } } $counters['delaysend'] = (int) ($batch_period - $totaltime); if (empty($GLOBALS['inRemoteCall']) && empty($GLOBALS['commandline'])) { sleep($delaytime); printf('<script type="text/javascript"> document.location = "./?page=pageaction&action=processqueue&ajaxed=true&reload=%d&lastsent=%d&lastskipped=%d%s"; </script></body></html>', $reload, $counters['sent'], $notsent, addCsrfGetToken()); } } elseif ($script_stage == 6 || $nothingtodo) { foreach ($GLOBALS['plugins'] as $pluginname => $plugin) { $plugin->messageQueueFinished(); } processQueueOutput($GLOBALS['I18N']->get('Finished, All done'), 0); print '<script type="text/javascript"> var parentJQuery = window.parent.jQuery; window.parent.allDone("' . s('All done') . '"); </script>'; } else { processQueueOutput(s('Script finished, but not all messages have been sent yet.')); } if (!empty($GLOBALS['inRemoteCall'])) { ob_end_clean(); print outputCounters(); @ob_start(); } if (empty($GLOBALS['inRemoteCall']) && empty($GLOBALS['commandline']) && empty($_GET['ajaxed'])) { return; } elseif (!empty($GLOBALS['inRemoteCall']) || !empty($GLOBALS['commandline'])) { @ob_end_clean(); } exit; }
function my_shutdown() { global $script_stage, $reload; # output( "Script status: ".connection_status(),0); # with PHP 4.2.1 buggy. http://bugs.php.net/bug.php?id=17774 output($GLOBALS['I18N']->get('Script stage') . ': ' . $script_stage, 0, 'progress'); global $counters, $report, $send_process_id, $tables, $nothingtodo, $invalid, $processed, $failed_sent, $notsent, $sent, $unconfirmed, $num_per_batch, $batch_period, $counters; $some = $processed; #$sent;# || $invalid || $notsent; if (!$some) { output($GLOBALS['I18N']->get('Finished, Nothing to do'), 0, 'progress'); $nothingtodo = 1; } $totaltime = $GLOBALS['processqueue_timer']->elapsed(1); if ($totaltime > 0) { $msgperhour = 3600 / $totaltime * $sent; } else { $msgperhour = s('Calculating'); } if ($sent) { output(sprintf('%d %s %01.2f %s (%d %s)', $sent, $GLOBALS['I18N']->get('messages sent in'), $totaltime, $GLOBALS['I18N']->get('seconds'), $msgperhour, $GLOBALS['I18N']->get('msgs/hr')), $sent, 'progress'); } if ($invalid) { output(s('%d invalid email addresses', $invalid), 1, 'progress'); } if ($failed_sent) { output(s('%d failed (will retry later)', $failed_sent), 1, 'progress'); foreach ($counters as $label => $value) { # output(sprintf('%d %s',$value,$GLOBALS['I18N']->get($label)),1,'progress'); cl_output(sprintf('%d %s', $value, $GLOBALS['I18N']->get($label))); } } if ($unconfirmed) { output(sprintf($GLOBALS['I18N']->get('%d emails unconfirmed (not sent)'), $unconfirmed), 1, 'progress'); } foreach ($GLOBALS['plugins'] as $pluginname => $plugin) { $plugin->processSendStats($sent, $invalid, $failed_sent, $unconfirmed, $counters); } flushClickTrackCache(); releaseLock($send_process_id); finish("info", $report, $script_stage); if ($script_stage < 5 && !$nothingtodo) { output($GLOBALS['I18N']->get('Warning: script never reached stage 5') . "\n" . $GLOBALS['I18N']->get('This may be caused by a too slow or too busy server') . " \n"); } elseif ($script_stage == 5 && (!$nothingtodo || isset($GLOBALS["wait"]))) { # if the script timed out in stage 5, reload the page to continue with the rest $reload++; if (!$GLOBALS["commandline"] && $num_per_batch && $batch_period) { if ($sent + 10 < $GLOBALS["original_num_per_batch"]) { output($GLOBALS['I18N']->get('Less than batch size were sent, so reloading imminently'), 1, 'progress'); $delaytime = 10; } else { // we should actually want batch perion minus time already spent. // might be nice to calculate that at some point output(sprintf($GLOBALS['I18N']->get('Waiting for %d seconds before reloading'), $batch_period), 1, 'progress'); $delaytime = $batch_period; } sleep($delaytime); printf('<script type="text/javascript"> document.location = "./?page=pageaction&action=processqueue&ajaxed=true&reload=%d&lastsent=%d&lastskipped=%d"; </script>', $reload, $sent, $notsent); } else { printf('<script type="text/javascript"> document.location = "./?page=pageaction&action=processqueue&ajaxed=true&reload=%d&lastsent=%d&lastskipped=%d"; </script>', $reload, $sent, $notsent); } } elseif ($script_stage == 6 || $nothingtodo) { foreach ($GLOBALS['plugins'] as $pluginname => $plugin) { $plugin->messageQueueFinished(); } output($GLOBALS['I18N']->get('Finished, All done'), 0); print '<script type="text/javascript"> var parentJQuery = window.parent.jQuery; window.parent.allDone("' . s('All done') . '"); </script>'; } else { output(s('Script finished, but not all messages have been sent yet.')); } if (empty($GLOBALS['commandline']) && empty($_GET['ajaxed'])) { include_once "footer.inc"; } elseif (!empty($GLOBALS['commandline'])) { @ob_end_clean(); } exit; }