forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.php
173 lines (155 loc) · 4.93 KB
/
import.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/*=========================================================================
Program: CDash - Cross-Platform Dashboard System
Module: $Id$
Language: PHP
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
include("cdash/config.php");
require_once("cdash/pdo.php");
include('login.php');
include("cdash/version.php");
if($session_OK)
{
include_once('cdash/common.php');
include_once("cdash/ctestparser.php");
set_time_limit(0);
$db = pdo_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
pdo_select_db("$CDASH_DB_NAME",$db);
checkUserPolicy(@$_SESSION['cdash']['loginid'],0); // only admin
//get date info here
@$dayFrom = $_POST["dayFrom"];
if(!isset($dayFrom))
{
$dayFrom = date('d', strtotime("yesterday"));
$monthFrom = date('m', strtotime("yesterday"));
$yearFrom = date('Y', strtotime("yesterday"));
$dayTo = date('d');
$yearTo = date('Y');
$monthTo = date('m');
}
else
{
$dayFrom = pdo_real_escape_numeric($dayFrom);
$monthFrom = pdo_real_escape_numeric($_POST["monthFrom"]);
$yearFrom = pdo_real_escape_numeric($_POST["yearFrom"]);
$dayTo = pdo_real_escape_numeric($_POST["dayTo"]);
$monthTo = pdo_real_escape_numeric($_POST["monthTo"]);
$yearTo = pdo_real_escape_numeric($_POST["yearTo"]);
}
$xml = begin_XML_for_XSLT();
$xml .= "<backurl>manageBackup.php</backurl>";
$xml .= "<title>CDash - Import</title>";
$xml .= "<menutitle>CDash</menutitle>";
$xml .= "<menusubtitle>Import Dart1</menusubtitle>";
$project = pdo_query("SELECT name,id FROM project ORDER BY id");
$projName = "";
while($project_array = pdo_fetch_array($project))
{
$projName = $project_array["name"];
$xml .= "<project>";
$xml .= "<name>".$projName."</name>";
$xml .= "<id>".$project_array["id"]."</id>";
$xml .= "</project>";
}
$xml .= "<dayFrom>".$dayFrom."</dayFrom>";
$xml .= "<monthFrom>".$monthFrom."</monthFrom>";
$xml .= "<yearFrom>".$yearFrom."</yearFrom>";
$xml .= "<dayTo>".$dayTo."</dayTo>";
$xml .= "<monthTo>".$monthTo."</monthTo>";
$xml .= "<yearTo>".$yearTo."</yearTo>";
$xml .= "</cdash>";
@$Submit = $_POST["Submit"];
if($Submit)
{
$directory = htmlspecialchars(pdo_real_escape_string($_POST["directory"]));
$projectid = pdo_real_escape_numeric($_POST["project"]);
// Checks
if(!isset($projectid) || !is_numeric($projectid))
{
echo "Not a valid projectid!";
return;
}
// Checks
if(!isset($directory) || strlen($directory)<3)
{
echo "Not a valid directory!";
return;
}
if($projectid == 0)
{
echo("Use your browsers Back button, and select a valid project.<br>");
ob_flush();
return;
}
echo("Import for Project: ");
echo(get_project_name($projectid));
echo("<br>");
ob_flush();
if(strlen($directory)>0 )
{
$directory = str_replace('\\\\','/',$directory);
if(!file_exists($directory) || strpos($directory, "Sites") === FALSE)
{
echo("Error: $directory is not a valid path to Dart XML data on the server.<br>\n");
generate_XSLT($xml,"import_dart_classic");
return;
}
$startDate = mktime(0,0,0,$monthFrom,$dayFrom,$yearFrom);
$endDate = mktime(0,0,0,$monthTo,$dayTo,$yearTo);
$numDays = ($endDate - $startDate) / (24 * 3600) + 1;
for($i=0;$i<$numDays;$i++)
{
$currentDay = date(FMT_DATE, mktime(0,0,0,$monthFrom,$dayFrom+$i,$yearFrom));
echo("Gathering XML files for $currentDay... $directory/*/*/$currentDay-*/XML/*.xml <br>\n");
flush();
ob_flush();
$files = glob($directory."/*/*/$currentDay-*/XML/*.xml");
$numFiles = count($files);
echo("$numFiles found<br>\n");
flush();
ob_flush();
$numDots = 0;
foreach($files as $file)
{
if(strlen($file)==0)
{
continue;
}
$handle = fopen($file,"r");
//$contents = fread($handle,filesize($file));
echo ".";
flush();
ob_flush();
$numDots++;
if($numDots > 79)
{
echo "<br>\n";
flush();
ob_flush();
$numDots = 0;
}
//$xml_array = parse_XML($contents);
//ctest_parse($xml_array,$projectid);
ctest_parse($handle,$projectid, false);
fclose($handle);
unset($handle);
}
echo "<br>Done for the day".$currentDay."<br>\n";
flush();
ob_flush();
}
} // end strlen(directory)>0
echo("<a href=index.php?project=".urlencode($projName).">Back to $projName dashboard</a>\n");
return;
}
// Now doing the xslt transition
generate_XSLT($xml,"import");
} // end session
?>