public function settingsAction() { // Get navigation $this->view->navigation = $this->getNavigation(); // Make form $this->view->form = $form = new Core_Form_Admin_Tasks_Settings(); // Get settings $current = Engine_Api::_()->getApi('settings', 'core')->core_tasks; // Don't allow cron mode on windows if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $form->addError('Cronjob triggering of tasks is not currently supported on Windows.'); if ($current['mode'] == 'cron') { if (extension_loaded('curl')) { Engine_Api::_()->getApi('settings', 'core')->core_tasks_mode = $current['mode'] = 'curl'; } else { Engine_Api::_()->getApi('settings', 'core')->core_tasks_mode = $current['mode'] = 'socket'; } } } // Make sure it's not set to curl if they don't have it if (!extension_loaded('curl') && $current['mode'] == 'curl') { Engine_Api::_()->getApi('settings', 'core')->core_tasks_mode = $current['mode'] = 'socket'; } // Populate form $form->populate($current); /* // Add description $form->getElement('mode') ->setDescription('test') ->getDecorator('Description') ->setOption('placement', 'append') ; * */ if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $values = $form->getValues(); if ($values['mode'] == 'cron') { $values['pid'] = ''; } Engine_Api::_()->getApi('settings', 'core')->core_tasks = $values; $current = array_merge($current, $values); } if ($current['mode'] == 'cron') { $minutes = ceil($current['interval'] / 60); $executeUrl = (_ENGINE_SSL ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->view->url(array('controller' => 'utility', 'action' => 'tasks'), 'default', true) . '?' . http_build_query(array('key' => $current['key'])); $logFile = APPLICATION_PATH . '/temporary/log/tasks.log'; $commandTemplate = 'echo Cron Execute Result: $(wget -O - %1$s) >> %2$s 2>&1'; $command = sprintf($commandTemplate, $executeUrl, $logFile); $form->getDecorator('Description')->setOption('escape', false); $form->addNotice($this->view->translate(array('Please set the following command to run in crontab about every %1$s minute: <br />"%2$s"', 'Please set the following command to run in crontab about every %1$s minutes: <br />"%2$s"', $minutes), $minutes, $command)); } }
public function settingsAction() { // Get navigation $this->view->navigation = $this->getNavigation(); // Make form $this->view->form = $form = new Core_Form_Admin_Tasks_Settings(); // Get settings $current = Engine_Api::_()->getApi('settings', 'core')->core_tasks; // Make sure it's not set to curl if they don't have it if (!extension_loaded('curl') && $current['mode'] == 'curl') { Engine_Api::_()->getApi('settings', 'core')->core_tasks_mode = $current['mode'] = 'socket'; } // Populate form $form->populate($current); if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $values = $form->getValues(); if ($values['mode'] == 'cron') { $values['pid'] = ''; } Engine_Api::_()->getApi('settings', 'core')->core_tasks = $values; $current = array_merge($current, $values); } // Add a notice for cron (wget) if ($current['mode'] == 'cron') { $minutes = ceil($current['interval'] / 60); // wget $executeUrl = (_ENGINE_SSL ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->view->url(array('controller' => 'utility', 'action' => 'tasks'), 'default', true) . '?' . http_build_query(array('key' => $current['key'], 'notrigger' => 1)); $executeUrl = escapeshellarg($executeUrl); $logFile = escapeshellarg(APPLICATION_PATH . '/temporary/log/tasks.log'); $commandTemplate = 'echo $(wget -O - %1$s) 2>&1 >> %2$s'; $command = sprintf($commandTemplate, $executeUrl, $logFile); $command = $this->view->escape($command); // cli $executeCliArgs = escapeshellarg(APPLICATION_PATH . '/application/cli.php') . ' ' . escapeshellarg('controller=utility,action=tasks,key=' . $current['key'] . ',notrigger=1'); $command2Template = 'echo $(php -f %1$s) 2>&1 >> %2$s'; $command2 = sprintf($command2Template, $executeCliArgs, $logFile); $command2 = $this->view->escape($command2); $form->getDecorator('Description')->setOption('escape', false); $minuteString = $this->view->translate(array('%1$s minute', '%1$s minutes', $minutes), $minutes); $form->addNotice($this->view->translate('Please set one of the the ' . 'following commands to run in crontab or the windows task scheduler ' . 'about every %1$s: <br /><br />' . 'Requires wget command line utility (Linux-only):<br /> ' . '"%2$s"<br /><br /> ' . 'Requires php command line utility (check that php-cli is installed and set up correctly):<br /> ' . '"%3$s"', $minuteString, $command, $command2)); } }