Skip to content

Commit

Permalink
Partial Commit: Error @Report.php:Line#310. [PHP Parse error: syntax …
Browse files Browse the repository at this point in the history
…error, unexpected '[' in /var/www/error-reporting-server/app/Model/Report.php on line 310].

Signed-off-by: Dhananjay Nakrani <dhananjaynakrani@gmail.com>
  • Loading branch information
JayNakrani committed May 29, 2014
1 parent 58159ff commit 0fabc21
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 42 deletions.
7 changes: 5 additions & 2 deletions app/Controller/IncidentsController.php
Expand Up @@ -26,12 +26,13 @@
class IncidentsController extends AppController {

public function create() {
error_log("IncidentCreateStart:".time());
$bugReport = $this->request->input('json_decode', true);
if ($this->Incident->createIncidentFromBugReport($bugReport)) {
$response = array(
"success" => true,
"message" => "Thank you for your submission",
"incident_id" => $this->Incident->id,
"incident_id" => 5, // TODO: Return a list of report ids.
);
} else {
$response = array(
Expand All @@ -40,7 +41,9 @@ public function create() {
);
}
$this->autoRender = false;
return json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
// return json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
error_log("IncidentCreateEnd:".time());
return json_encode($response);
}

public function json($id) {
Expand Down
180 changes: 140 additions & 40 deletions app/Model/Incident.php
Expand Up @@ -146,19 +146,58 @@ public function createIncidentFromBugReport($bugReport) {
if ($bugReport == null) {
return false;
}

$schematizedIncident = $this->_getSchematizedIncident($bugReport);
$closestReport = $this->_getClosestReport($bugReport);
if($bugReport['exception_type'] == 'js'){
$closestReport = $this->_getClosestReport($bugReport);

if($closestReport) {
$schematizedIncident["report_id"] = $closestReport["Report"]["id"];
return $this->save($schematizedIncident);
if($closestReport) {
$schematizedIncident["report_id"] = $closestReport["Report"]["id"];
return $this->save($schematizedIncident);
} else {
$report = $this->_getReportDetails($bugReport);
$data = array(
'Incident' => $schematizedIncident,
'Report' => $report
);
return $this->saveAssociated($data);
}
} elseif($bugReport['exception_type'] == 'php') {
$tmpIncident = new Incident();
// $tmpReport = new Report();
foreach($schematizedIncident as $index => $si){
// find closest report. If not found, create a new report.
$closestReport = $this->_getClosestReport($bugReport, $index);
error_log('returned from _getClosestReport!!!');
$closestReport = false;
if($closestReport) {
$si["report_id"] = $closestReport["Report"]["id"];
if($tmpIncident->save($si)) {
$tmpIncident = new Incident(); // create a new incident otherwise save() overwrites the previous object.
} else {
return false;
}
} else {
//no close report. Create a new report.
$report = $this->_getReportDetails($bugReport,$index);
error_log('returned from _getReportDetails!!!');
$data = array(
'Incident' => $si,
'Report' => $report
);
// $tmpReport->save($report);

if($tmpIncident->saveAssociated($data)) {

This comment has been minimized.

Copy link
@JayNakrani

JayNakrani May 29, 2014

Author Owner

I think the mentioned error is occurring at this line.

$tmpIncident = new Incident(); // create a new incident otherwise save() overwrites the previous object.
// $tmpReport = new Report();
} else {
return false;
}
}
}
return true;
} else {
$report = $this->_getReportDetails($bugReport);
$data = array(
'Incident' => $schematizedIncident,
'Report' => $report
);
return $this->saveAssociated($data);
return false;
}
}

Expand All @@ -169,33 +208,60 @@ public function createIncidentFromBugReport($bugReport) {
* pma_version
*
* @param Array $bugReport the bug report being checked
* Integer $index: for php exception type.
* @return Array the first similar report or null
*/
protected function _getClosestReport($bugReport) {
List($location, $linenumber) =
$this->_getIdentifyingLocation($bugReport['exception']['stack']);
protected function _getClosestReport($bugReport, $index) {
if($bugReport['exception_type'] == 'js') {
List($location, $linenumber) =
$this->_getIdentifyingLocation($bugReport['exception']['stack']);
} elseif($bugReport['exception_type'] == 'php') {
$location = $bugReport['errors'][$index]['file'];
$linenumber = $bugReport['errors'][$index]['lineNum'];
} else {
return false;
}
$report = $this->Report->findByLocationAndLinenumberAndPmaVersion(
$location, $linenumber, $bugReport['pma_version']);
$location, $linenumber, $bugReport['pma_version']);
return $report;
}

/**
* creates the report data from an incident that has no related report.
*
* @param Array $bugReport the bug report the report record is being created for
* Integer $index: for php exception type.
* @return Array an array with the report fields can be used with Report->save
*/
protected function _getReportDetails($bugReport) {
List($location, $linenumber) =
protected function _getReportDetails($bugReport, $index) {

if($bugReport['exception_type'] == 'js') {
List($location, $linenumber) =
$this->_getIdentifyingLocation($bugReport["exception"]["stack"]);

$reportDetails = array(
'error_message' => $bugReport['exception']['message'],
'error_name' => $bugReport['exception']['name'],
'status' => 'new',
'location' => $location,
'linenumber' => $linenumber,
'pma_version' => $bugReport['pma_version'],
$reportDetails = array(
'error_message' => $bugReport['exception']['message'],
'error_name' => $bugReport['exception']['name'],
);
} elseif($bugReport['exception_type'] == 'php') {
$location = $bugReport['errors'][$index]['file'];
$linenumber = $bugReport['errors'][$index]['lineNum'];
$reportDetails = array(
'error_message' => $bugReport['errors'][$index]['msg'],
'error_name' => $bugReport['errors'][$index]['type'],
);
} else {
return false;
}

$reportDetails = array_merge(
$reportDetails,
array(
'status' => 'new',
'location' => $location,
'linenumber' => $linenumber,
'pma_version' => $bugReport['pma_version'],
)
);
return $reportDetails;
}
Expand All @@ -207,25 +273,59 @@ protected function _getReportDetails($bugReport) {
* @return Array an array with the incident fields can be used with ِIncident->save
*/
protected function _getSchematizedIncident($bugReport) {
// TODO: reduce duplicate code. Use $schematizedCommonReport & array merge.
$bugReport = Sanitize::clean($bugReport, array('escape' => false));
$schematizedReport = array(
'pma_version' => $bugReport['pma_version'],
'php_version' => $this->_getSimpleVersion($bugReport['php_version'], 2),
'error_message' => $bugReport['exception']['message'],
'error_name' => $bugReport['exception']['name'],
'browser' => $bugReport['browser_name'] . " "
. $this->_getSimpleVersion($bugReport['browser_version'], 1),
'user_os' => $bugReport['user_os'],
'script_name' => $bugReport['script_name'],
'configuration_storage' => $bugReport['configuration_storage'],
'server_software' => $this->_getServer($bugReport['server_software']),
'stackhash' => $this->getStackHash($bugReport['exception']['stack']),
'full_report' => json_encode($bugReport),
'stacktrace' => json_encode($bugReport['exception']['stack']),
);
if($bugReport['exception_type'] == 'js') {
$schematizedReport = array(
'pma_version' => $bugReport['pma_version'],
'php_version' => $this->_getSimpleVersion($bugReport['php_version'], 2),
'error_message' => $bugReport['exception']['message'],
'error_name' => $bugReport['exception']['name'],
'browser' => $bugReport['browser_name'] . " "
. $this->_getSimpleVersion($bugReport['browser_version'], 1),
'user_os' => $bugReport['user_os'],
'script_name' => $bugReport['script_name'],
'configuration_storage' => $bugReport['configuration_storage'],
'server_software' => $this->_getServer($bugReport['server_software']),
'stackhash' => $this->getStackHash($bugReport['exception']['stack']),
'full_report' => json_encode($bugReport),
'stacktrace' => json_encode($bugReport['exception']['stack']),
'exception_type' => 0 //'js'
);

if (isset($bugReport['steps'])) {
$schematizedReport["steps"] = $bugReport['steps'];
if (isset($bugReport['steps'])) {
$schematizedReport["steps"] = $bugReport['steps'];
}
} elseif($bugReport['exception_type'] == 'php') {
$schematizedCommonReport = array(
'exception_type' => 1, // 'php'
'pma_version' => $bugReport['pma_version'],
'php_version' => $this->_getSimpleVersion($bugReport['php_version'], 2),
'browser' => $bugReport['browser_name'] . " "
. $this->_getSimpleVersion($bugReport['browser_version'], 1),
'user_os' => $bugReport['user_os'],
'configuration_storage' => $bugReport['configuration_storage'],
'server_software' => $this->_getServer($bugReport['server_software']),
'full_report' => json_encode($bugReport)
);
$schematizedReport = array();
$counter = 0;
// for each "errors"
foreach($bugReport['errors'] as $error){
$schematizedReport[$counter] = array_merge(
$schematizedCommonReport,
array(
'error_name' => $error['type'],
'error_message' => $error['msg'],
'script_name' => $error['file'],
'stacktrace' => json_encode($error['stackTrace']),
'stackhash' => $error['stackhash']
)
);
$counter++;
}
} else {
return false;
}

return $schematizedReport;
Expand Down

0 comments on commit 0fabc21

Please sign in to comment.