Skip to content

Commit

Permalink
[#272] Fix for fuzzy grouping, function rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Fragonite committed Aug 31, 2023
1 parent 1c5bbe2 commit 2ebcc40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions classes/script_metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,38 @@ public static function get_redactable_param_names(): array {
*
* @return string the request path for this profile.
*/
public static function get_request(): string {
global $SCRIPT, $ME, $CFG;
public static function get_normalised_relative_script_path(): string {
global $SCRIPT;

if (!isset($ME)) {
// If set, it will trim off the leading '/' to normalise web & cli requests.
$request = isset($SCRIPT) ? ltrim($SCRIPT, '/') : self::REQUEST_UNKNOWN;
return $request;
// This is from the previous iteration of the function.
if (!isset($SCRIPT)) {
return self::REQUEST_UNKNOWN;
}

$request = (new \moodle_url($ME))->out_omit_querystring();
$request = str_replace($CFG->wwwroot, '', $request);
$request = $SCRIPT;
$count = 0;

// Remove multiple consecutive slashes.
do {
$request = str_replace('//', '/', $request, $count);
} while ($count);

$request = ltrim($request, '/');
$request = rtrim($request, '/');

$indexphp = 'index.php';

// Trim "index.php" from the end of the request. Case sensitive.
if (substr($request, -(strlen($indexphp))) === $indexphp) {
$request = substr($request, 0, -(strlen($indexphp)));
}

$request = rtrim($request, '/');

if ($request === '') {
return '/';
}

return $request;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/web_processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function init(manager $manager) {
// Record and set initial memory usage at this point.
$memoryusage = memory_get_usage();

$request = script_metadata::get_request();
$request = script_metadata::get_normalised_relative_script_path();
$starttime = (int) $manager->get_starttime();
$this->sampleset = new sample_set($request, $starttime);

Expand Down

0 comments on commit 2ebcc40

Please sign in to comment.