Performs the common tasks when displaying a form.

@param string $task
434610
protected function displayFormCommon($task)
    {
        // This will initialize the form translations.
        $this->container->getForm($task);

        $this->registry->document->addStyle('view/stylesheet/acumulus.css');

        $this->data['success_messages'] = array();
        $this->data['warning_messages'] = array();
        $this->data['error_messages'] = array();

        // Set the page title.
        $this->registry->document->setTitle($this->t("{$task}_form_title"));
        $this->data["page_title"] = $this->t("{$task}_form_title");
        $this->data["heading_title"] = $this->t("{$task}_form_header");
        $this->data["text_edit"] = $this->t("{$task}_form_header");

        // Set up breadcrumb.
        $this->data['breadcrumbs'] = array();
        $this->data['breadcrumbs'][] = array(
            'text' => $this->t('text_home'),
            'href' => $this->registry->getLink('common/dashboard'),
            'separator' => false
        );

        $this->displayCommonParts();
    }
445653
public function startTask($task, array $options = [])
    {
        ob_start() && $this->taskStack[] = $task;

        $this->taskOptions[$task] = $this->mergeDefaultOptions($options);
    }
86636
public function set_task($task)
    {
        if (php_sapi_name() == 'cli') {
            $task = 'cli';
        }
        else if (!$this->user || !$this->user->ID) {
            $task = 'login';
        }
        else {
            $task = asciiwords($task, true) ?: 'mail';
        }

        $this->task      = $task;
        $this->comm_path = $this->url(array('task' => $this->task));

        if (!empty($_REQUEST['_framed'])) {
            $this->comm_path .= '&_framed=1';
        }

        if ($this->output) {
            $this->output->set_env('task', $this->task);
            $this->output->set_env('comm_path', $this->comm_path);
        }
    }
576377
public static function action($task)
    {
        //====================================================================//
        // Stack Trace
        Splash::log()->trace();
        Splash::log()->deb("Widgets => ".$task->name);
        //====================================================================//
        // Initial Response
        $response = self::getEmptyResponse($task);

        //====================================================================//
        // Execute Requested Task
        //====================================================================//
        switch ($task->name) {
            //====================================================================//
            //  READING OF SERVER WIDGETS LIST
            case SPL_F_WIDGET_LIST:
                $response->data = Splash::widgets();

                break;
            //====================================================================//
            //  READING A WIDGET DEFINITION
            case SPL_F_WIDGET_DEFINITION:
                $response->data = Splash::widget($task->params->type)->description();

                break;
            //====================================================================//
            //  READING A WIDGET CONTENTS
            case SPL_F_WIDGET_GET:
                $response->data = Splash::widget($task->params->type)->get($task->params->params);

                break;
            default:
                Splash::log()->err(
                    "Info Router - Requested task was not found => ".$task->name." (".$task->desc.")"
                );

                break;
        }

        //====================================================================//
        // Task results post treatment
        if (false != $response->data) {
            $response->result = true;
        }

        return $response;
    }
722253
public function setTask($task)
    {
        $taskCode = filter_var($task, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
        if (strpos($taskCode, '-') !== false) {
            $taskCode = str_replace('-', '', $taskCode);
        }
        $taskCode = $this->project . $taskCode;
        $this->task = $taskCode;
    }
561933
public function addTask(Task $t)
    {
        if ($this->nestedTask !== null) {
            throw new BuildException(
                'The retry task container accepts a single nested task'
                . ' (which may be a sequential task container)'
            );
        }
        $this->nestedTask = $t;
    }
1022794
protected function submitTask(Task $task)
    {
        switch ($task->type) {
        case Task::JOB_LOW:
            $type = 'submit_job_low';
            break;
        case Task::JOB_LOW_BACKGROUND:
            $type = 'submit_job_low_bg';
            break;
        case Task::JOB_HIGH_BACKGROUND:
            $type = 'submit_job_high_bg';
            break;
        case Task::JOB_BACKGROUND:
            $type = 'submit_job_bg';
            break;
            case Task::JOB_EPOCH:
            $type = 'submit_job_epoch';
            break;
        case Task::JOB_HIGH:
            $type = 'submit_job_high';
            break;
        default:
            $type = 'submit_job';
            break;
        }

        $arg = $task->arg;

        $params = array(
            'func' => $task->func,
            'uniq' => $task->uniq,
            'arg' => $arg,
        );

        if ($task->type == Task::JOB_EPOCH) {
            $params['epoch'] = $task->epoch;
        }

        $s = $this->getConnection();
        Connection::send($s, $type, $params);

        if (!is_array(Connection::$waiting[(int) $s])) {
            Connection::$waiting[(int) $s] = array();
        }

        array_push(Connection::$waiting[(int) $s], $task);
    }
295342
function loadTasks(string $namespace, $tasks) {
        if (!is_array($tasks))
            $tasks = [$tasks];
        foreach ($tasks as &$task) {
            $class_name = $namespace.$task;
            if (!is_subclass_of($class_name, '\\Acast\\CronService\\TaskInterface')) {
                Console::warning("Invalid class \"$task\".");
                continue;
            }
            $this->addTask($class_name::init());
        }
    }
162692
public function register_task($task, $owner)
    {
        // tasks are irrelevant in framework mode
        if (!class_exists('rcmail', false)) {
            return true;
        }

        if ($task != asciiwords($task, true)) {
            rcube::raise_error(array('code' => 526, 'type' => 'php',
                'file' => __FILE__, 'line' => __LINE__,
                'message' => "Invalid task name: $task."
                    ." Only characters [a-z0-9_.-] are allowed"), true, false);
        }
        else if (in_array($task, rcmail::$main_tasks)) {
            rcube::raise_error(array('code' => 526, 'type' => 'php',
                'file' => __FILE__, 'line' => __LINE__,
                'message' => "Cannot register taks $task;"
                    ." already taken by another plugin or the application itself"), true, false);
        }
        else {
            $this->tasks[$task] = $owner;
            rcmail::$main_tasks[] = $task;
            return true;
        }

        return false;
    }
551905
public function start(string $query): void
    {
        foreach ($this->monitors as $monitor) {
            $monitor->start($query);
        }
    }
732583
public function heartbeat($task)
    {
        $current = time();
        if ($current - $this->_last_heartbeat >= $this->_heartbeat_interval) {
            $this->_last_heartbeat = $current;
            if ($redis = $this->_getRedis()) {
                $redis->hSet($this->getTaskMetaKey($task), self::FIELD_HEARTBEAT_TIME, date('c', $current));
            }
        }
    }
1209344
public function executeOnce(\Closure $task)
    {
        $isBlocked = $this->checkedLock();
        $error = null;
        try {
            if (! $isBlocked) {
                call_user_func($task);

            }
        } catch (\Exception $e) {
            $error = $e;

        }
        $this->unlock();
        if (! is_null($error)) {
            throw $error;

        }
    }
1312278
private function processTask(&$task)
    {
        $read = $write = [$task['socket']];
        $n = stream_select($read, $write, $e = null, $this->timeout);
        if ($n > 0) {
            switch ($task['status']) {
                case 0: // ready
                    fwrite($task['socket'], "GET {$task['path']} HTTP/1.1\r\nHost: {$task['host']}\r\n\r\n");
                    $task['status'] = 1;
                    break;
                case 1: // active
                    $data = fread($task['socket'], $this->readDataLen);
                    if (strlen($data) == 0) {
                        fclose($task['socket']);
                        echo "Failed to connect {$task['host']}.<br />\n";
                        $task['status'] = -1;
                    } else {
                        $task['status'] = 2;
                        $task['response'] .= $data;
                    }
                    break;
            }
        }
    }
74235
private function executeTask($task)
    {
        $this->logger->info("Scheduler: executing task {taskName}...", array(
            'taskName' => $task->getName(),
        ));

        $this->isRunningTask = true;

        $timer = new Timer();

        /**
         * Triggered directly before a scheduled task is executed
         *
         * @param Task $task  The task that is about to be executed
         */
        Piwik::postEvent('ScheduledTasks.execute', array(&$task));

        try {
            $callable = array($task->getObjectInstance(), $task->getMethodName());
            call_user_func($callable, $task->getMethodParameter());
            $message = $timer->__toString();
        } catch (Exception $e) {
            $message = 'ERROR: ' . $e->getMessage();
        }

        $this->isRunningTask = false;

        /**
         * Triggered after a scheduled task is successfully executed.
         *
         * You can use the event to execute for example another task whenever a specific task is executed or to clean up
         * certain resources.
         *
         * @param Task $task The task that was just executed
         */
        Piwik::postEvent('ScheduledTasks.execute.end', array(&$task));

        $this->logger->info("Scheduler: finished. {timeElapsed}", array(
            'timeElapsed' => $timer,
        ));

        return $message;
    }
487335
public function update(Task $task)
    {
        $this->om->persist($task);
        $this->om->flush();

        $this->notify(NotifierInterface::MESSAGE_UPDATE);

        return $task;
    }
26231
protected function listTasks($container)
    {
        $this->output->writeln('<comment>Available tasks:</comment>');

        foreach (array_keys($container->getTasks()) as $task) {
            $this->output->writeln("  <info>{$task}</info>");
        }
    }
454039
public function executeTask($tasks)
    {
        return $this->explainer->displayBelow(function () use ($tasks) {
            return $this->builder->buildTask($tasks)->fire();
        });
    }