Exemplo n.º 1
0
    /**
     * Displays all available log entries according to the set filters.
     *
     * @param int $page Which page to display
     */
    public function index_action($page = 1)
    {
        $filter = $_SESSION['cronlog-filter'];
        
        $this->max_per_page   = Config::get()->ENTRIES_PER_PAGE;
        $this->total          = CronjobLog::countBySql();
        $this->total_filtered = CronjobLog::countBySql($filter['where']);
        $this->page           = max(1, min($page, ceil($this->total_filtered / $this->max_per_page)));

        $order = " ORDER BY executed DESC";
        $limit = sprintf(" LIMIT %u, %u", ($this->page - 1) * $this->max_per_page, $this->max_per_page);
        $this->logs = CronjobLog::findBySQL($filter['where'] . $order . $limit);

        // Filters
        $this->schedules  = CronjobSchedule::findBySql('1');
        $this->tasks      = CronjobTask::findBySql('1');
        $this->filter     = $filter['values'];

        // Infobox image was produced from an image by Robbert van der Steeg
        // http://www.flickr.com/photos/robbie73/5924985913/
        // Aktionen
        $sidebar = Sidebar::Get();
        $sidebar->setTitle(_('Cronjobs'));
        $sidebar->setImage('sidebar/admin-sidebar.png');

        $actions = new ViewsWidget();
        $actions->addLink(_('Cronjobs verwalten'),$this->url_for('admin/cronjobs/schedules'));
        $actions->addLink(_('Aufgaben verwalten'),$this->url_for('admin/cronjobs/tasks'));
        $actions->addLink(_('Logs anzeigen'),$this->url_for('admin/cronjobs/logs'))->setActive(true);
        $sidebar->addWidget($actions);
    }
Exemplo n.º 2
0
<?php 
/**
* cronjobs - Helper script for the cronjobs
*
* @author Jan-Hendrik Willms <*****@*****.**>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 3.1
* @todo Parameter handling!
*/
require_once 'studip_cli_env.inc.php';
$argc = $_SERVER['argc'];
$argv = $_SERVER['argv'];
$opts = getopt('hl', array('help', 'list'));
if (isset($opts['l']) || isset($opts['list'])) {
    $tasks = CronjobTask::findBySql('1');
    foreach ($tasks as $task) {
        $description = call_user_func(array($task->class, 'getDescription'));
        fwrite(STDOUT, sprintf('%s %s' . PHP_EOL, $task->id, studip_utf8encode($description)));
    }
    exit(0);
}
if ($argc < 2 || isset($opts['h']) || isset($opts['help'])) {
    fwrite(STDOUT, 'Usage: ' . basename(__FILE__) . ' [--help] [--list] <task_id> [last_result]' . PHP_EOL);
    exit(0);
}
$id = $_SERVER['argv'][1];
$last_result = $argc > 2 ? $_SERVER['argv'][2] : null;
$task = CronjobTask::find($id);
if (!$task) {
    fwrite(STDOUT, 'Unknown task id' . PHP_EOL);
Exemplo n.º 3
0
 /**
  * Edits a schedule.
  *
  * @param String $id   Id of the schedule in question (null to create)
  * @param int    $page Return to this page after editing (optional)
  */
 public function edit_action($id = null, $page = 1)
 {
     if (Request::submitted('store')) {
         $parameters = Request::getArray('parameters');
         $schedule = CronjobSchedule::find($id) ?: new CronjobSchedule();
         $schedule->title = Request::get('title');
         $schedule->description = Request::get('description');
         $schedule->active = Request::int('active', 0);
         if ($schedule->isNew()) {
             $schedule->task_id = Request::option('task_id');
         }
         $schedule->parameters = $parameters[$schedule->task_id];
         $schedule->type = Request::option('type') === 'once' ? 'once' : 'periodic';
         if ($schedule->type === 'once') {
             $temp = Request::getArray('once');
             $schedule->next_execution = strtotime($temp['date'] . ' ' . $temp['time']);
         } else {
             $temp = Request::getArray('periodic');
             $schedule->minute = $this->extractCronItem($temp['minute']);
             $schedule->hour = $this->extractCronItem($temp['hour']);
             $schedule->day = $this->extractCronItem($temp['day']);
             $schedule->month = $this->extractCronItem($temp['month']);
             $schedule->day_of_week = strlen($temp['day_of_week']['value']) ? (int) $temp['day_of_week']['value'] : null;
             if ($schedule->active) {
                 $schedule->next_execution = $schedule->calculateNextExecution();
             }
         }
         $schedule->store();
         PageLayout::postMessage(MessageBox::success(_('Die Änderungen wurden gespeichert.')));
         $this->redirect('admin/cronjobs/schedules/index/' . $page);
         return;
     }
     PageLayout::setTitle(_('Cronjob-Verwaltung') . ' - ' . _('Cronjob bearbeiten'));
     // Infobox image was produced from an image by Robbert van der Steeg
     // http://www.flickr.com/photos/robbie73/5924985913/
     $sidebar = Sidebar::Get();
     $sidebar->setImage('sidebar/date-sidebar.png');
     $sidebar->setTitle(_('Cronjobs'));
     $actions = new ActionsWidget();
     $actions->addLink(_('Zurück zur Übersicht'), $this->url_for('admin/cronjobs/schedules/index/' . $page), Icon::create('link-intern', 'clickable'));
     $sidebar->addWidget($actions);
     $this->page = $page;
     $this->tasks = CronjobTask::findBySql('1');
     $this->schedule = CronjobSchedule::find($id) ?: new CronjobSchedule();
 }