43 private function load()
46 if ($this->
user != NULL) {
47 $cmd.=
' -u ' . escapeshellarg($this->
user);
49 $cmd.=
' 2> /dev/null';
51 $ph = popen(
$cmd,
'r');
53 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error popen");
59 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error stream_get_contents");
68 private function save()
70 include_once (
'WHAT/Lib.System.php');
74 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error creating temporary file");
78 $ret = file_put_contents($tmp, $this->crontab);
80 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error writing content to file '" . $tmp .
"'");
85 if ($this->
user != NULL) {
86 $cmd.=
' -u ' . escapeshellarg($this->
user);
88 $cmd.=
' ' . escapeshellarg($tmp);
89 $cmd.=
' > /dev/null 2>&1';
93 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error saving crontab '" . $tmp .
"'");
100 public function registerFile(
$file)
102 include_once (
'WHAT/Lib.Prefix.php');
106 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading content from file '" .
$file .
"'");
111 $newSectionElement->appendChild(
new \Dcp\CrontabTextElement(sprintf(
"CONTEXT_ROOT=%s",
DEFAULT_PUBDIR)));
112 $newSectionElement->appendChild(
new \Dcp\CrontabTextElement(
$crontab));
114 $crontabData = $this->load();
115 if ($crontabData === FALSE) {
116 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading active crontab");
120 $parser = new \Dcp\CrontabParser();
121 $crontabDocument = $parser->parse($crontabData);
123 $crontabDocument->childs = array_filter($crontabDocument->childs, function ($element) use (
$file)
125 if (is_a($element,
'\Dcp\CrontabSectionElement')) {
136 $crontabDocument->appendChild($newSectionElement);
138 $this->crontab = (string)$crontabDocument;
140 printf(
"Saving crontab...\n");
141 $ret = $this->save();
142 if (
$ret === FALSE) {
143 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error saving crontab");
151 public function unregisterFile(
$file)
153 include_once (
'WHAT/Lib.Prefix.php');
155 $crontabData = $this->load();
156 if ($crontabData === FALSE) {
157 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading active crontab");
161 $parser = new \Dcp\CrontabParser();
162 $crontabDocument = $parser->parse($crontabData);
164 $crontabDocument->childs = array_filter($crontabDocument->childs, function (\Dcp\CrontabElement & $element) use (
$file)
166 if (is_a($element,
'\Dcp\CrontabSectionElement')) {
177 $this->crontab = (string)$crontabDocument;
179 printf(
"Saving crontab...\n");
180 $ret = $this->save();
181 if (
$ret === FALSE) {
182 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error saving crontab");
192 $crontabs = $this->getActiveCrontab();
193 if ($crontabs === FALSE) {
194 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error retrieving active crontabs");
199 print "Active crontabs\n";
200 print "---------------\n";
203 print "Crontab: " . $crontab[
'file'] .
"\n";
204 print "--8<--\n" . $crontab[
'content'] .
"\n-->8--\n\n";
210 public function getActiveCrontab()
212 include_once (
'WHAT/Lib.Prefix.php');
214 $crontabData = $this->load();
215 if ($crontabData === FALSE) {
216 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading active crontab");
220 $parser = new \Dcp\CrontabParser();
221 $crontabDocument = $parser->parse($crontabData);
224 foreach ($crontabDocument->childs as & $element) {
228 if (is_a($element,
'\Dcp\CrontabSectionElement') && $element->matchContextRoot(
DEFAULT_PUBDIR)) {
229 array_push($crontabs, array(
230 'file' => $element->file,
231 'content' => (
string)$element
240 public function unregisterAll()
242 include_once (
'WHAT/Lib.Prefix.php');
244 $crontabData = $this->load();
245 if ($crontabData === FALSE) {
246 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading active crontab");
250 $parser = new \Dcp\CrontabParser();
251 $crontabDocument = $parser->parse($crontabData);
253 $crontabDocument->childs = array_filter($crontabDocument->childs, function (\Dcp\CrontabElement & $element)
255 if (is_a($element,
'\Dcp\CrontabSectionElement')) {
266 $this->crontab = (string)$crontabDocument;
268 printf(
"Saving crontab...\n");
269 $ret = $this->save();
270 if (
$ret === FALSE) {
271 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error saving crontab");
foreach($argv as $arg) $cmd