File: vacation-cron.php

package info (click to toggle)
postfixadmin 4.0.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,888 kB
  • sloc: php: 12,256; perl: 1,156; sh: 717; python: 142; xml: 63; sql: 3; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download
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
#!/bin/env php
<?php

/**
 * This script is intended to be run through cron.
 * It should look through the postfixadmin vacation table for vacation entries that should no longer be active. If it
 * finds one that's expired, it should update the alias record to remove the autoreply alias, as well as deactivating the vacation entry.
 * @see https://github.com/postfixadmin/postfixadmin/issues/832
 *
 * How you link it into your cron routine is up to you - you 'could' have an entry in /etc/cron.hourly/postfixadmin that contains something like :
 *
 * #!/bin/bash
 * cd /path/to/postfixadmin/scripts/examples
 * php vacation-cron.php
 *
 *
 * might work.
 */
require_once(__DIR__ . '/../../public/common.php');

define('POSTFIXADMIN_CLI', 1);

$table_vacation = table_by_key('vacation');

$active = db_get_boolean(1);

$vacations_that_need_deactivating = db_query_all("SELECT * FROM $table_vacation WHERE activeuntil <= NOW() AND active = :active ", ['active' => $active]);

foreach ($vacations_that_need_deactivating as $row) {

    try {
        $vh = new VacationHandler($row['email']);
        error_log(__FILE__ . " - I need to disable the postfixadmin vacation stuff for : {$row['email']} as it should end at {$row['activeuntil']}");
        $vh->remove();

    } catch (\Exception $e) {
        error_log(__FILE__ . " - failed to remove postfixadmin vacation settings for user." . $e->getMessage());
    }
}