Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove stale site from statistics #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions classes/task/crawl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lang/en/local_sitestats.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down