File: bootstrap.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 (91 lines) | stat: -rw-r--r-- 2,910 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

define('POSTFIXADMIN', 1);
define('POSTFIXADMIN_CLI', 1);

require_once(dirname(__FILE__) . '/../vendor/autoload.php');
require_once(dirname(__FILE__) . '/../common.php');


$CONF['default_language'] = 'en';
$CONF['language_hook'] = '';

if (getenv('DATABASE') == 'sqlite' || getenv('DATABASE') == false) {
    $version = PHP_VERSION_ID; // try and stop different tests running at the same trying to use the same sqlite db at once
    $db_file = tempnam(sys_get_temp_dir(), 'postfixadmin-test');
    $CONF['database_type'] = 'sqlite';
    $CONF['database_name'] = $db_file;
    Config::write('database_type', 'sqlite');
    Config::write('database_name', $db_file);
    clearstatcache();
    if (file_exists($db_file)) {
        unlink($db_file);
    }
    touch($db_file);

    error_log("Using: SQLite database for tests - $db_file");
}
if (getenv('DATABASE') == 'postgresql') {
    $user = getenv('PGUSER') ?: 'postgres';
    $pass = getenv('PGPASSWORD') ?: '';
    $host = getenv('PGHOST') ?: 'localhost';

    $CONF['database_type'] = 'pgsql';
    $CONF['database_user'] = $user;
    $CONF['database_password'] = $pass;
    $CONF['database_host'] = $host;
    $CONF['database_name'] = 'postfixadmin';
    Config::write('database_type', 'pgsql');
    Config::write('database_user', $user);
    Config::write('database_password', $pass);
    Config::write('database_name', 'postfixadmin');
    Config::write('database_host', $host);

    error_log("Using: PostgreSQL database for tests\n");
}

if (getenv('DATABASE') == 'mysql') {
    $expand_tilde = function ($path) {
        if (function_exists('posix_getuid') && strpos($path, '~') !== false) {
            $info = posix_getpwuid(posix_getuid());
            $path = str_replace('~', $info['dir'], $path);
        }

        return $path;
    };

    $config = parse_ini_file($expand_tilde('~/.my.cnf'));

    if (empty($config)) {
        $config = ['user' => 'root', 'host' => '127.0.0.1', 'password' => ''];
    }

    if (isset($config['socket'])) {
        $CONF['database_socket'] = $config['socket'];
        Config::write('database_socket', $config['socket']);
    } else {
        $CONF['database_host'] = $config['host'];
        Config::write('database_host', $config['host']);
    }

    $CONF['database_type'] = 'mysql';
    $CONF['database_user'] = $config['user'];
    $CONF['database_password'] = $config['password'];
    $CONF['database_name'] = 'postfixadmin';
    Config::write('database_type', 'mysql');
    Config::write('database_user', $config['user']);
    Config::write('database_password', $config['password']);
    Config::write('database_name', 'postfixadmin');

    error_log("Using: MySQL database for tests");
}

try {
    $db = db_connect();
} catch (Exception $e) {
    echo "failed to connect to database\n";
    echo $e->getMessage();
    exit(1);
}

require_once(dirname(__FILE__) . '/../public/upgrade.php');