$name !== '' ? $name : $command, 'Enabled' => empty($posted['Enabled']) ? 0 : 1, 'Schedule' => $schedule, 'Command' => $command, 'ServerId' => empty($posted['ServerId']) ? null : validInt($posted['ServerId']), ); $id = empty($_REQUEST['id']) ? 0 : validInt($_REQUEST['id']); $job = $id ? ZM\CronJob::find_one(array('Id'=>$id)) : new ZM\CronJob(); if (!$job) $job = new ZM\CronJob(); if ($job->Id()) { $job->save($values); ZM\Info('Updated scheduled task '.$job->Id().': '.$schedule.' '.$command); } else if ($job->insert($values)) { ZM\Info('Added scheduled task '.$job->Id().': '.$schedule.' '.$command); } else { $cron_error = $job->get_last_error(); } } } else if ($action == 'delete') { if (!empty($_REQUEST['markIds'])) { foreach ($_REQUEST['markIds'] as $id) { $id = validInt($id); if (!$id) continue; ZM\Info('Deleting scheduled task '.$id); dbQuery('DELETE FROM CronJobs WHERE Id=?', array($id)); } } } if (in_array($action, array('save', 'delete')) and ($cron_error === '')) { // The crontab is a projection of the table, rebuilt whenever the table // changes, so the two cannot drift. if (cronRebuild() === false) $cron_error = translate('CronWriteFailed'); } if ($cron_error !== '') { ZM\Error('Scheduled tasks: '.$cron_error); $redirect = '?view=cron&error='.urlencode($cron_error); } else { $redirect = '?view=cron'; } ?>