/**
  * Function for editing a task.
  *
  * @uses ManageScheduledTasks template, edit_scheduled_tasks sub-template
  */
 public function action_edit()
 {
     global $context, $txt;
     // Just set up some lovely context stuff.
     $context[$context['admin_menu_name']]['current_subsection'] = 'tasks';
     $context['sub_template'] = 'edit_scheduled_tasks';
     $context['page_title'] = $txt['scheduled_task_edit'];
     $context['server_time'] = standardTime(time(), false, 'server');
     // We'll need this to calculate the next event.
     require_once SUBSDIR . '/ScheduledTasks.subs.php';
     // Cleaning...
     if (!isset($_GET['tid'])) {
         fatal_lang_error('no_access', false);
     }
     $_GET['tid'] = (int) $_GET['tid'];
     // Saving?
     if (isset($_GET['save'])) {
         checkSession();
         validateToken('admin-st');
         // Do we have a valid offset?
         preg_match('~(\\d{1,2}):(\\d{1,2})~', $_POST['offset'], $matches);
         // If a half is empty then assume zero offset!
         if (!isset($matches[2]) || $matches[2] > 59) {
             $matches[2] = 0;
         }
         if (!isset($matches[1]) || $matches[1] > 23) {
             $matches[1] = 0;
         }
         // Now the offset is easy; easy peasy - except we need to offset by a few hours...
         $offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z');
         // The other time bits are simple!
         $interval = max((int) $_POST['regularity'], 1);
         $unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd';
         // Don't allow one minute intervals.
         if ($interval == 1 && $unit == 'm') {
             $interval = 2;
         }
         // Is it disabled?
         $disabled = !isset($_POST['enabled']) ? 1 : 0;
         // Do the update!
         $_GET['tid'] = (int) $_GET['tid'];
         updateTask($_GET['tid'], $disabled, $offset, $interval, $unit);
         // Check the next event.
         calculateNextTrigger($_GET['tid'], true);
         // Return to the main list.
         redirectexit('action=admin;area=scheduledtasks');
     }
     // Load the task, understand? Que? Que?
     $_GET['tid'] = (int) $_GET['tid'];
     $context['task'] = loadTaskDetails($_GET['tid']);
     createToken('admin-st');
 }
Exemplo n.º 2
0
    /**
     * Recount many forum totals that can be recounted automatically without harm.
     *
     * What it does:
     * - it requires the admin_forum permission.
     * - It shows the maintain_forum admin area.
     * - The function redirects back to ?action=admin;area=maintain when complete.
     * - It is accessed via ?action=admin;area=maintain;sa=database;activity=recount.
     *
     * Totals recounted:
     * - fixes for topics with wrong num_replies.
     * - updates for num_posts and num_topics of all boards.
     * - recounts personal_messages but not unread_messages.
     * - repairs messages pointing to boards with topics pointing to other boards.
     * - updates the last message posted in boards and children.
     * - updates member count, latest member, topic count, and message count.
     */
    public function action_recount_display()
    {
        global $txt, $context, $modSettings, $time_start;
        isAllowedTo('admin_forum');
        checkSession();
        // Functions
        require_once SUBSDIR . '/Maintenance.subs.php';
        // Validate the request or the loop
        if (!isset($_REQUEST['step'])) {
            validateToken('admin-maint');
        } else {
            validateToken('admin-boardrecount');
        }
        // For the loop template
        $context['page_title'] = $txt['not_done_title'];
        $context['continue_post_data'] = '';
        $context['continue_countdown'] = 3;
        $context['sub_template'] = 'not_done';
        // Try for as much time as possible.
        @set_time_limit(600);
        // Step the number of topics at a time so things don't time out...
        $max_topics = getMaxTopicID();
        $increment = min(max(50, ceil($max_topics / 4)), 2000);
        if (empty($_REQUEST['start'])) {
            $_REQUEST['start'] = 0;
        }
        $total_steps = 8;
        // Get each topic with a wrong reply count and fix it - let's just do some at a time, though.
        if (empty($_REQUEST['step'])) {
            $_REQUEST['step'] = 0;
            while ($_REQUEST['start'] < $max_topics) {
                recountApprovedMessages($_REQUEST['start'], $increment);
                recountUnapprovedMessages($_REQUEST['start'], $increment);
                $_REQUEST['start'] += $increment;
                if (microtime(true) - $time_start > 3) {
                    createToken('admin-boardrecount');
                    $context['continue_post_data'] = '
						<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '" />
						<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />';
                    $context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=0;start=' . $_REQUEST['start'];
                    $context['continue_percent'] = round(100 * $_REQUEST['start'] / $max_topics / $total_steps);
                    $context['not_done_title'] = $txt['not_done_title'] . ' (' . $context['continue_percent'] . '%)';
                    return;
                }
            }
            $_REQUEST['start'] = 0;
        }
        // Update the post count of each board.
        if ($_REQUEST['step'] <= 1) {
            if (empty($_REQUEST['start'])) {
                resetBoardsCounter('num_posts');
            }
            while ($_REQUEST['start'] < $max_topics) {
                // Recount the posts
                updateBoardsCounter('posts', $_REQUEST['start'], $increment);
                $_REQUEST['start'] += $increment;
                if (microtime(true) - $time_start > 3) {
                    createToken('admin-boardrecount');
                    $context['continue_post_data'] = '
						<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '" />
						<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />';
                    $context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=1;start=' . $_REQUEST['start'];
                    $context['continue_percent'] = round((200 + 100 * $_REQUEST['start'] / $max_topics) / $total_steps);
                    $context['not_done_title'] = $txt['not_done_title'] . ' (' . $context['continue_percent'] . '%)';
                    return;
                }
            }
            $_REQUEST['start'] = 0;
        }
        // Update the topic count of each board.
        if ($_REQUEST['step'] <= 2) {
            if (empty($_REQUEST['start'])) {
                resetBoardsCounter('num_topics');
            }
            while ($_REQUEST['start'] < $max_topics) {
                updateBoardsCounter('topics', $_REQUEST['start'], $increment);
                $_REQUEST['start'] += $increment;
                if (microtime(true) - $time_start > 3) {
                    createToken('admin-boardrecount');
                    $context['continue_post_data'] = '
						<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '" />
						<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />';
                    $context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=2;start=' . $_REQUEST['start'];
                    $context['continue_percent'] = round((300 + 100 * $_REQUEST['start'] / $max_topics) / $total_steps);
                    $context['not_done_title'] = $txt['not_done_title'] . ' (' . $context['continue_percent'] . '%)';
                    return;
                }
            }
            $_REQUEST['start'] = 0;
        }
        // Update the unapproved post count of each board.
        if ($_REQUEST['step'] <= 3) {
            if (empty($_REQUEST['start'])) {
                resetBoardsCounter('unapproved_posts');
            }
            while ($_REQUEST['start'] < $max_topics) {
                updateBoardsCounter('unapproved_posts', $_REQUEST['start'], $increment);
                $_REQUEST['start'] += $increment;
                if (microtime(true) - $time_start > 3) {
                    createToken('admin-boardrecount');
                    $context['continue_post_data'] = '
						<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '" />
						<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />';
                    $context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=3;start=' . $_REQUEST['start'];
                    $context['continue_percent'] = round((400 + 100 * $_REQUEST['start'] / $max_topics) / $total_steps);
                    $context['not_done_title'] = $txt['not_done_title'] . ' (' . $context['continue_percent'] . '%)';
                    return;
                }
            }
            $_REQUEST['start'] = 0;
        }
        // Update the unapproved topic count of each board.
        if ($_REQUEST['step'] <= 4) {
            if (empty($_REQUEST['start'])) {
                resetBoardsCounter('unapproved_topics');
            }
            while ($_REQUEST['start'] < $max_topics) {
                updateBoardsCounter('unapproved_topics', $_REQUEST['start'], $increment);
                $_REQUEST['start'] += $increment;
                if (microtime(true) - $time_start > 3) {
                    createToken('admin-boardrecount');
                    $context['continue_post_data'] = '
						<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '" />
						<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />';
                    $context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=4;start=' . $_REQUEST['start'];
                    $context['continue_percent'] = round((500 + 100 * $_REQUEST['start'] / $max_topics) / $total_steps);
                    $context['not_done_title'] = $txt['not_done_title'] . ' (' . $context['continue_percent'] . '%)';
                    return;
                }
            }
            $_REQUEST['start'] = 0;
        }
        // Get all members with wrong number of personal messages.
        if ($_REQUEST['step'] <= 5) {
            updatePersonalMessagesCounter();
            if (microtime(true) - $time_start > 3) {
                createToken('admin-boardrecount');
                $context['continue_post_data'] = '
					<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '" />
					<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />';
                $context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=6;start=0';
                $context['continue_percent'] = round(700 / $total_steps);
                $context['not_done_title'] = $txt['not_done_title'] . ' (' . $context['continue_percent'] . '%)';
                return;
            }
        }
        // Any messages pointing to the wrong board?
        if ($_REQUEST['step'] <= 6) {
            while ($_REQUEST['start'] < $modSettings['maxMsgID']) {
                updateMessagesBoardID($_REQUEST['start'], $increment);
                $_REQUEST['start'] += $increment;
                if (microtime(true) - $time_start > 3) {
                    createToken('admin-boardrecount');
                    $context['continue_post_data'] = '
						<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '" />
						<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />';
                    $context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=6;start=' . $_REQUEST['start'];
                    $context['continue_percent'] = round((700 + 100 * $_REQUEST['start'] / $modSettings['maxMsgID']) / $total_steps);
                    $context['not_done_title'] = $txt['not_done_title'] . ' (' . $context['continue_percent'] . '%)';
                    return;
                }
            }
            $_REQUEST['start'] = 0;
        }
        updateBoardsLastMessage();
        // Update all the basic statistics.
        updateStats('member');
        updateStats('message');
        updateStats('topic');
        // Finally, update the latest event times.
        require_once SUBSDIR . '/ScheduledTasks.subs.php';
        calculateNextTrigger();
        redirectexit('action=admin;area=maintain;sa=routine;done=recount');
    }
Exemplo n.º 3
0
/**
 * Callback used in the core features page when the post-by-email feature
 * is enabled or disabled.
 *
 * @package Admin
 * @param bool $value the "new" status of the post-by-email
 * (true => enabled, false => disabled)
 */
function postbyemail_toggle_callback($value)
{
    require_once SUBSDIR . '/ScheduledTasks.subs.php';
    toggleTaskStatusByName('maillist_fetch_IMAP', $value);
    // Should we calculate next trigger?
    if ($value) {
        calculateNextTrigger('maillist_fetch_IMAP');
    }
}
Exemplo n.º 4
0
/**
 * For diligent people: remove scheduleTaskImmediate when done, otherwise
 * a maximum of 10 executions is allowed
 *
 * @param string $task the name of a scheduled task
 * @param bool $calculateNextTrigger if recalculate the next task to execute
 */
function removeScheduleTaskImmediate($task, $calculateNextTrigger = true)
{
    global $modSettings;
    // Not on, bail
    if (!isset($modSettings['scheduleTaskImmediate'])) {
        return;
    } else {
        $scheduleTaskImmediate = unserialize($modSettings['scheduleTaskImmediate']);
    }
    // Clear / remove the task if it was set
    if (isset($scheduleTaskImmediate[$task])) {
        unset($scheduleTaskImmediate[$task]);
        updateSettings(array('scheduleTaskImmediate' => serialize($scheduleTaskImmediate)));
        // Recalculate the next task to execute
        if ($calculateNextTrigger) {
            require_once SUBSDIR . '/ScheduledTasks.subs.php';
            calculateNextTrigger($task);
        }
    }
}