mirrored from git://git.moodle.org/moodle.git
/
init.php
98 lines (83 loc) · 2.74 KB
/
init.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
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
92
93
94
95
96
97
98
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* CLI script to set up all the behat test environment.
*
* @package tool_behat
* @copyright 2013 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (isset($_SERVER['REMOTE_ADDR'])) {
die(); // No access from web!
}
// Is not really necessary but adding it as is a CLI_SCRIPT.
define('CLI_SCRIPT', true);
// Basic functions.
require_once(__DIR__ . '/../../../../lib/clilib.php');
require_once(__DIR__ . '/../../../../lib/behat/lib.php');
// Changing the cwd to admin/tool/behat/cli.
chdir(__DIR__);
$output = null;
exec("php util.php --diag", $output, $code);
if ($code == 0) {
echo "Behat test environment already installed\n";
} else if ($code == BEHAT_EXITCODE_INSTALL) {
// Behat and dependencies are installed and we need to install the test site.
passthru("php util.php --install", $code);
if ($code != 0) {
exit($code);
}
} else if ($code == BEHAT_EXITCODE_REINSTALL) {
// Test site data is outdated.
passthru("php util.php --drop", $code);
if ($code != 0) {
exit($code);
}
passthru("php util.php --install", $code);
if ($code != 0) {
exit($code);
}
} else if ($code == BEHAT_EXITCODE_COMPOSER) {
// Missing Behat dependencies.
// Changing to moodle dirroot to run composer related commands at project level.
chdir(__DIR__ . '/../../../..');
if (!file_exists(__DIR__ . '/../../../../composer.phar')) {
passthru("curl http://getcomposer.org/install | php", $code);
if ($code != 0) {
exit($code);
}
}
passthru("php composer.phar update --dev", $code);
if ($code != 0) {
exit($code);
}
// Returning to admin/tool/behat/cli.
chdir(__DIR__);
passthru("php util.php --install", $code);
if ($code != 0) {
exit($code);
}
} else {
// Generic error, we just output it.
echo implode("\n", $output)."\n";
exit($code);
}
// Enable editing mode according to config.php vars.
passthru("php util.php --enable", $code);
if ($code != 0) {
exit($code);
}
exit(0);