From efbae34f4b427a0e88917c5ca7c0db9adcf663b2 Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Thu, 16 Sep 2021 12:19:51 +0200 Subject: [PATCH] Remove stale site from statistics --- classes/task/crawl.php | 15 +++++++++++++++ lang/en/local_sitestats.php | 1 + 2 files changed, 16 insertions(+) diff --git a/classes/task/crawl.php b/classes/task/crawl.php index 3ec343c..77d23d9 100644 --- a/classes/task/crawl.php +++ b/classes/task/crawl.php @@ -106,6 +106,21 @@ public function execute() return false; } unset ($ret); + + continue; + } + + // Remove the site if it is not found any more but was installed before. + $records = $DB->get_records('local_sitestats_sites'); + foreach ($records as $record) { + $record_result = $DB->get_record('local_sitestats_sites', ['id' => $record->id]); + if ($record_result->url !== $site_url) { + $DB->delete_records('local_sitestats_sites', ['id' => $record->id]); + $DB->delete_records('local_sitestats_core', ['site' => $record->id]); + $DB->delete_records('local_sitestats_plugins_site', ['site' => $record->id]); + + echo get_string('crawl_sitedeleted', 'local_sitestats', ['site' => $record->title]) . PHP_EOL; + } } } } diff --git a/lang/en/local_sitestats.php b/lang/en/local_sitestats.php index a16d448..6bdd6c0 100644 --- a/lang/en/local_sitestats.php +++ b/lang/en/local_sitestats.php @@ -60,6 +60,7 @@ $string['crawl_sitelistremembersiteerror'] = 'Database problem when remembering site {$a->site} for crawling'; $string['crawl_siteliststartup'] = 'STARTUP: Getting site list for later use'; $string['crawl_sitefinish'] = 'SITE FINISH: Site "{$a->site}" has been crawled completely'; +$string['crawl_sitedeleted'] = 'SITE DELETED: Site "{$a->site}", core and plugin entries has being deleted'; $string['crawl_siteremembercorecrawlederror'] = 'Database problem when storing core information crawl timestamp of site {$a->site} to database'; $string['crawl_siterememberpluginscrawlederror'] = 'Database problem when storing plugins crawl timestamp of site {$a->site} to database'; $string['crawl_siteremembersitecrawlederror'] = 'Database problem when storing site crawl timestamp of site {$a->site} to database';