120 lines
3.5 KiB
PHP
120 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Sandpiper\Actions;
|
|
|
|
use \Yosymfony\Toml\Toml;
|
|
|
|
use \SBRL\Utilities\SimpleXmlWriter;
|
|
|
|
class Report extends \Sandpiper\AbstractAction
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
|
|
}
|
|
|
|
public function handle() {
|
|
global $settings;
|
|
|
|
header("content-type: text/plain");
|
|
|
|
if(!$this->param_exists("place_id"))
|
|
exit("Error: No place id provided.\n");
|
|
if(!$this->param_exists("summary"))
|
|
exit("Error: No summary provided.\n");
|
|
if(!$this->param_exists("version"))
|
|
exit("No version provided.\n");
|
|
|
|
/******************************************************/
|
|
|
|
$place = null;
|
|
foreach($settings->get("places") as $current_place) {
|
|
var_dump($current_place);
|
|
if($current_place["key"] == $this->param_get("place_id", null)) {
|
|
$place = $current_place;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if($place == null)
|
|
exit("Error: Place id doesn't match.\n");
|
|
|
|
$new_report = new \stdClass();
|
|
$new_report->version = escape4xml($this->param_get("version", "?"));
|
|
$new_report->summary = escape4xml($this->param_get("summary", "(Unknown error)"));
|
|
$new_report->details = escape4xml($this->param_get("details", ""));
|
|
$new_report->stack_trace = escape4xml($this->get_post_body());
|
|
|
|
$report_dir = ROOT_DIR . "/{$settings->get("data_dir")}/places/" . slugify($place["name"]);
|
|
$report_filename = "$report_dir/" . slugify($new_report->summary) . ".xml";
|
|
|
|
// Create the directory if it doesn't exist already
|
|
if(!file_exists($report_dir))
|
|
mkdir($report_dir, 0750, true);
|
|
|
|
// Save the individual report
|
|
|
|
if(!file_exists($report_filename)) {
|
|
$writer = new \SBRL\Utilities\SimpleXmlWriter(); // It's started automagically
|
|
$writer->prettyprint = true;
|
|
$writer->add_xslt("/theme/stack_traces.xslt");
|
|
$writer->open("error_info");
|
|
$writer->addtag("project_name", [], $place["name"]); // For aesthetic purposes
|
|
$writer->addtag("summary", [], $new_report->summary);
|
|
$writer->open("reports");
|
|
$writer->close();
|
|
$writer->close();
|
|
file_put_contents($report_filename, $writer->render());
|
|
}
|
|
|
|
$report_xml = simplexml_load_file($report_filename);
|
|
|
|
if($report_xml === false)
|
|
exit("Error: invalid XML generated when creating a new report file.\n");
|
|
|
|
$report_node = $report_xml->reports->addChild("report");
|
|
$report_node->addChild("timestamp", date(DATE_ATOM));
|
|
$report_node->addChild("version", $new_report->version);
|
|
$report_node->addChild("details", $new_report->details);
|
|
$report_node->addChild("stack_trace", $new_report->stack_trace);
|
|
|
|
file_put_contents($report_filename, $report_xml->asXML());
|
|
|
|
// Update the place index
|
|
$place_index_filename = "$report_dir/index.xml";
|
|
|
|
if(!file_exists($place_index_filename)) {
|
|
$writer = new SimpleXmlWriter();
|
|
$writer->prettyprint = true;
|
|
|
|
$writer->add_xslt(ROOT_DIR . "/theme/place_index.xslt");
|
|
$writer->open("errors");
|
|
$writer->close();
|
|
file_put_contents($place_index_filename, $writer->render());
|
|
}
|
|
$index_xml = simplexml_load_file($place_index_filename);
|
|
|
|
$index_entry = null;
|
|
foreach($index_xml as $entry) {
|
|
if($entry->summary->__toString() != $new_report->summary)
|
|
continue;
|
|
$index_entry = $entry;
|
|
break;
|
|
}
|
|
|
|
if($index_entry == null) {
|
|
$index_entry = $index_xml->addChild("error");
|
|
$index_entry->summary = $new_report->summary;
|
|
$index_entry->last_report = date(DATE_ATOM);
|
|
$index_entry->report_count = 0;
|
|
}
|
|
|
|
$index_entry->report_count = intval($index_entry->report_count) + 1;
|
|
|
|
file_put_contents($place_index_filename, $index_xml->asXML());
|
|
|
|
http_response_code(200);
|
|
exit("Report submitted successfully!\n");
|
|
}
|
|
}
|