⌈⌋ ⎇ branch:  freshcode


Check-in [2b7b9307c4]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Automated cronjob re-registration from `x-cron:` plugin meta fields.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2b7b9307c432706a4242066037746f507bde1178
User & Date: mario 2014-11-22 21:29:22
Context
2014-11-22
21:29
Rename QPL to QtPL check-in: e86d921713 user: mario tags: trunk
21:29
Automated cronjob re-registration from `x-cron:` plugin meta fields. check-in: 2b7b9307c4 user: mario tags: trunk
21:28
Switch to raw `twurl` requests for Twitter updates, as that allows to embed screenshots easily. check-in: d9a13a9d82 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added cron.daily/_cronjobs.php.





















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
#
# title: cronjob collector
# description: parses out cron: specifiers from plugins and installs crontab
# version: 0.1
# cron: 0 0 * * *
# type: cron
# 
# Reregisters cronjobs from current dir (cron.daily/) into crontab
# according to x-cron: specifiers.


// keep previous crontab entries not pointing to current __DIR__
$dir = preg_quote(__DIR__, "~");
$CRONTAB = preg_replace(
    "~((?<=\n)\R+)?(^#.+\R+)*^.*$dir.*\R~m",
    "",
    `crontab -l`
);


// traverse all files in cron.d/
foreach (glob(__DIR__."/*.*") as $fn) {

    // coarse plugin meta data extraction
    preg_match_all("~ ^ [#/*\h]+ (?:x-)? (cron|title|description|version|type): \h* (\V+)  ~mix", file_get_contents($fn), $m);
    $m = array_change_key_case(array_combine($m[1], $m[2] ));

    // assert existing `cron:` specifier
    if (!empty($m["cron"]) and preg_match("~^([*/\d-]+(\h+|$)){5}$|^@(daily|hourly|midnight)$~", $m["cron"] = stripcslashes($m["cron"]))) {
       $CRONTAB .= "\n"
                .  "#-- $m[title]\n#   ($m[description])\n"
                .  "$m[cron] "
                .  "nice "
                .  pathinfo($fn, PATHINFO_EXTENSION)
                .  " $fn\n";
    }
    
}

// install new crontab
fwrite(popen("crontab", "w"), $CRONTAB);