Skip to content

Commit

Permalink
Fix url filtering (uniques), sort urls, readme update (tasks)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierbouwman committed Mar 17, 2024
1 parent 7360ee4 commit 223ae0b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 1 addition & 3 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
ToDo:
- Add type to output (node/doctor, media/video, etc.)
- Add a way to do an initial run, show results, maybe with checkboxes for each line pre-checked, ability for future runs to exclude those urls with the same code and/or the same error message.
- Way to exclude certain urls
- Way to include certain urls
- Count success/fail and write at end of run.
- Add configuration screen where you can enable different plugins etc.
- Consider sitemap and menus for url sources.
- Consider sitemap for url sources.
- Should I cache bust by clearing all cache at the start of the run or by including url parameters? Which is more reliable/faster?
- Add javascript console errors. Would have to use a headless browser like Puppeteer, Playwright or https://github.com/chrome-php/chrome. We should test speed and see if it makes sense to move our current url get logic over.
20 changes: 18 additions & 2 deletions src/Commands/LazyTestCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,31 @@ public function __construct(LazyTestService $lazyTestService) {
*/
public function run() {
$urls = $this->lazyTestService->getAllURLs();

// Filter out empty urls.
$urls = array_filter($urls, function($item) {
return !empty($item['url']);
});
$urls = array_map('unserialize', array_unique(array_map('serialize', $urls), SORT_REGULAR));
// Filter the URLs to only include those that have the same scheme and host as the current site

// Filter out non-unique urls.
array_multisort(array_column($urls, 'url'), SORT_ASC, $urls);
$urls = array_intersect_key(
$urls,
array_unique(array_column($urls, 'url'))
);

// Filter out external urls.
$current_scheme_and_host = \Drupal::request()->getSchemeAndHttpHost();
$urls = array_filter($urls, function($item) use ($current_scheme_and_host) {
return parse_url($item['url'], PHP_URL_SCHEME) . '://' . parse_url($item['url'], PHP_URL_HOST) === $current_scheme_and_host;
});

// Sort.
$source = array_column($urls, 'source');
$subsource = array_column($urls, 'subsource');
$url = array_column($urls, 'url');
array_multisort($source, SORT_ASC, $subsource, SORT_ASC, $url, SORT_ASC, $urls);

$this->lazyTestService->checkURLs($urls);
}

Expand Down
4 changes: 2 additions & 2 deletions src/LazyTestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function checkURLs($urls) {
if (!empty($log_messages) || $code != 200) {
$message = [
'source' => $url["source"],
'subsource' => $url["subsource"],
'subsource' => $url["subsource"] ?? '',
'code' => $code,
'url' => $url["url"],
'message' => $log_messages,
Expand All @@ -129,7 +129,7 @@ public function checkURLs($urls) {
$log_messages = $this->getLogMessages($url, $startTimestamp);
$message = [
'source' => $url["source"],
'subsource' => $url["subsource"],
'subsource' => $url["subsource"] ?? '',
'code' => $code,
'url' => $url["url"],
'message' => $log_messages,
Expand Down
1 change: 1 addition & 0 deletions src/Plugin/URLProvider/FileURLProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function getURLs() {
$url = $stream_wrapper_manager->getViaUri($file_uri)->getExternalUrl();
$urls[] = [
'source' => "file",
'subsource' => '',
'url' => $url,
];
}
Expand Down
1 change: 1 addition & 0 deletions src/Plugin/URLProvider/UserURLProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function getURLs() {
$url_object->setAbsolute();
$urls[] = [
'source' => "user",
'subsource' => '',
'url' => $url_object->toString(),
];
}
Expand Down

0 comments on commit 223ae0b

Please sign in to comment.