From b0743473f11244e6405f29aaab986a01a19808b5 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Tue, 4 Mar 2014 08:07:48 +0000 Subject: [PATCH] Output bugs to bug report file Load common-settings.php and get 3 x querystring params, exploding first 2 into arrays $result is OK to start with, but if we have a file that's not available, set it to error If we don't have an error, the seen sizes aren't null and the seen and actual sizes don't match, we need to get bug lines Set $result to bugs and some vars to begin with fseek, ftell and while loop to get chunks of content using pointer movement methods. We also reduce $chars and $lines here to escape the while loop as required $output has line endings converted and trimmed, before exploding on new lines and only getting last few lines, stitched back together with imploder The bug report is written, $tmpLoc established and all data put into the $status array to feed back in the XHR response --- lib/bug-files-check.php | 91 ++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/lib/bug-files-check.php b/lib/bug-files-check.php index a4c4e88..1b0112b 100644 --- a/lib/bug-files-check.php +++ b/lib/bug-files-check.php @@ -1,30 +1,93 @@ 0 && $chars > 0 && $lines > 0) { + + // Figure out how far back we should jump + $seek = min($chars, $buffer); + + // Do the jump (backwards, relative to where we are) + fseek($f, -$seek, SEEK_CUR); + + // Read a chunk and prepend it to our output + $output = ($chunk = fread($f, $seek)).$output; + + // Jump back to where we started reading + fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR); + + // Take this seek chunk off the number of chars + $chars -= $seek; + + $lines -= substr_count($chunk, "\n"); + } + + // Close file + fclose($f); + + $output = rtrim(str_replace("\r\n","\n",$output)); + $output = explode("\n",$output); + $output = array_slice($output, -$maxLines); + $output = implode("\n",$output); + + file_put_contents("../tmp/bug-report.log", $output); + } + +} + +$tmpLoc = dirname(__FILE__); +$tmpLoc = explode(DIRECTORY_SEPARATOR,$tmpLoc); +$tmpLoc = $tmpLoc[count($tmpLoc)-2]; // Output result and status array -$result = "off"; -$status = array("result" => $result); +$status = array( + "files" => $files, + "filesSizesSeen" => $filesSizesSeen, + "maxLines" => $maxLines, + "chars" => (isset($chars) ? $chars : null), + "lines" => substr_count($output, "\n"), + "seek" => (isset($seek) ? $seek : null), + "bugReportPath" => "|".$tmpLoc."|tmp|bug-report.log", + "result" => $result +); // Include our process once our bug checking work is done include("../processes/on-bug-check.php");