get('cron_error_message'); if ($error) { $i18n = $this->getContext()->getI18N(); $this->setFlash('warning', $i18n->__($error['message'], $error['params']), false); } } public function executeList() { if ($this->checkPHPVersion()) { stTaskScheluder::initialize(); } $ret = parent::executeList(); $this->pager->setPeerCountMethod(array($this, 'doCountTasks')); $this->pager->init(); if (SF_ENVIRONMENT != 'dev') { $this->hideField('task_id'); } return $ret; } public function executeConfig() { $this->checkPHPVersion(); return parent::executeConfig(); } public function executeClean() { if (Propel::getConnection()->executeQuery(sprintf('TRUNCATE TABLE %s', TaskLogPeer::TABLE_NAME))) { $i18n = $this->getContext()->getI18N(); $this->setFlash('notice', $i18n->__('Logi zostały wyczyszczone pomyślnie')); } return $this->redirect($this->getRequest()->getReferer()); } public function executeEdit() { parent::executeEdit(); if ($this->task->getIsSystemDefault()) { $i18n = $this->getContext()->getI18N(); $this->setFlash('warning', $i18n->__('Zadania systemowe nie mogą być zmieniane')); return $this->redirect('@stTaskScheluderBackend'); } } protected function addSortCriteria($c) { parent::addSortCriteria($c); $c->addAscendingOrderByColumn(TaskPeer::TASK_PRIORITY); } protected function addLogFiltersCriteria($c) { /** * @var Criteria $c */ if ($this->getRequestParameter('id')) { $c->add(TaskLogPeer::TASK_ID, $this->getRequestParameter('id')); } if (isset($this->filters['type']) && "" !== $this->filters['type']) { $c->add(TaskLogPeer::TYPE, $this->filters['type']); } $c->addDescendingOrderByColumn(TaskLogPeer::ID); parent::addLogFiltersCriteria($c); } public function executeExecuteTasks() { if (floatval(phpversion()) < 7.1) { return $this->redirect('@stTaskScheluderBackend'); } $taskPool = array(); $totalCount = 0; $i18n = $this->getContext()->getI18N(); $progressBarTask = new stTaskScheluderProgressBar($this->getContext()); $progressBarTask->clearParameters(); $taskId = $this->getRequestParameter('task_id'); $tasks = null !== $taskId ? [stTaskScheluder::getTask($taskId)] : stTaskScheluder::getTasks(); foreach ($tasks as $task) { if ($task->isReadyToExecute(false)) { if (false === $task->doInitialize(true)) { continue; } $count = $task->doCount(); if ($count > 0) { $taskPool[] = ['id' => $task->getId(), 'offset' => $totalCount]; $totalCount += $count; } elseif (null !== $taskId) { $this->setFlash('notice', $i18n->__('Zadanie %%task%% nie wymagało wykonania.', [ '%%task%%' => $task->getName(), ])); return $this->redirect('@stTaskScheluderBackend'); } } elseif (null !== $taskId) { $this->setFlash('warning', $i18n->__('Zadanie %%task%% jest już w trakcie wykonywania.', [ '%%task%%' => $task->getName(), ])); return $this->redirect('@stTaskScheluderBackend'); } } if (!$totalCount) { $this->setFlash('notice', $i18n->__('Zadania nie wymagają wykonania.')); return $this->redirect('@stTaskScheluderBackend'); } $taskPool = array_reverse($taskPool); $progressBarTask->setParameter('task_pool', $taskPool); $progressBarTask->setParameter('count', $totalCount); $this->getBreadcrumbsBuilder()->getDefaultBreadcrumbs()->add($i18n->__('Wykonaj ręcznie')); $this->progress_bar_task = $progressBarTask; } public function doCountTasks(Criteria $c) { return floatval(phpversion()) < 7.1 ? 0 : TaskPeer::doCount($c); } protected function checkPHPVersion() { if (floatval(phpversion()) < 7.1) { $i18n = $this->getContext()->getI18N(); $this->setFlash('warning', $i18n->__('Do poprawnego działania moduł wymaga wersji PHP 7.1.x (aktualnie ustawiona wersja PHP: %version%)', array('%version%' => phpversion())), false); return false; } return true; } }