forked from tjaehnel/pipresentationmanager
/
prepareTesting.php
55 lines (51 loc) · 1.22 KB
/
prepareTesting.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
<?php
$command = $_GET['command'];
try {
switch ($command) {
case "init":
doInit();
echo '<p id="success">Successfully initialized test</p>';
break;
case "cleanup":
doCleanup();
echo '<p id="success">Successfully cleaned up test</p>';
break;
default:
throw new Exception("Invalid command");
}
} catch(Exception $e) {
header($_SERVER['SERVER_PROTOCOL'].' Internal Server Error');
header($e->getMessage());
echo $e->getMessage();
}
function doInit() {
if(file_exists('test'))
doCleanup();
if(file_exists('test'))
throw new Exception("Test directory exists - clean up first");
//exec("cp -r testenvironment test", $dummy, $res);
$res = recurse_copy('testenvironment', 'test');
if(!$res)
throw new Exception("Unable to copy directory");
}
function doCleanup() {
exec("rm -rf test", $dummy, $res);
}
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
if(!recurse_copy($src . '/' . $file,$dst . '/' . $file))
return false;
}
else {
if(!copy($src . '/' . $file,$dst . '/' . $file))
return false;
}
}
}
closedir($dir);
return true;
}