Skip to content

Fix core crawler reserved SQL keyword and regex to get version #8

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

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
2 changes: 1 addition & 1 deletion classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function render_tab_viewtable() {
foreach ($result_siteswithcoreinformation as $site) {

// Get information from DB.
$result_coreversion = $DB->get_field('local_sitestats_core', 'value', array('site' => $site->site, 'key' => 'coreversion'), IGNORE_MISSING);
$result_coreversion = $DB->get_field('local_sitestats_core', 'value', array('site' => $site->site, 'name' => 'coreversion'), IGNORE_MISSING);

// If we have this information
if ($result_coreversion !== false) {
Expand Down
21 changes: 14 additions & 7 deletions classes/task/crawl.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function execute()
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200) {

// Find first occurence of a version number heading.
$versionfound = preg_match('/=== ([0-9]\.[0-9])\.?[0-9]? ===/', $curldoc3, $matches);
$versionfound = preg_match('/=== ([0-9]\.[0-9]{1,2}(\.[0-9]{1,2})?) ===/', $curldoc3, $matches);

// If we found a version, process it.
if ($versionfound == 1) {
Expand All @@ -375,11 +375,12 @@ public function execute()
// Create database record.
$coreversion_record = new \stdClass();
$coreversion_record->site = $site->id;
$coreversion_record->key = 'coreversion';
$coreversion_record->name = 'coreversion';
$coreversion_record->value = $coreversion;

// Check if we have recorded this information before in DB.
$coreversionbefore_result = $DB->get_record('local_sitestats_core', array('site' => $site->id, 'key' => get_string('coreversion', 'local_sitestats')));
$coreversionbefore_result = $DB->get_record('local_sitestats_core',
array('site' => $coreversion_record->site, 'name' => $coreversion_record->name));

// If there is already a record.
if ($coreversionbefore_result !== false) {
Expand All @@ -392,18 +393,23 @@ public function execute()
}
if ($ret === true) {
// Output log.
echo get_string('crawl_coreinformationfound', 'local_sitestats', array('site' => $site->title, 'key' => get_string('coreversion', 'local_sitestats'), 'value' => $coreversion)) . PHP_EOL;
echo get_string('crawl_coreinformationfound', 'local_sitestats',
array('site' => $site->title, 'name' => get_string('coreversion', 'local_sitestats'),
'value' => $coreversion)) . PHP_EOL;
} else {
// Quit
echo get_string('crawl_coreinformationfounderror', 'local_sitestats', array('key' => get_string('coreversion', 'local_sitestats'))) . PHP_EOL;
echo get_string('crawl_coreinformationfounderror', 'local_sitestats',
array('name' => get_string('coreversion', 'local_sitestats'))) . PHP_EOL;
return false;
}
unset ($ret);
}
// Otherwise we have to say that we did not get this information.
else {
// Output log.
echo get_string('crawl_coreinformationnotfound', 'local_sitestats', array('site' => $site->title, 'key' => get_string('coreversion', 'local_sitestats'))).PHP_EOL;
echo get_string('crawl_coreinformationnotfound', 'local_sitestats',
array('site' => $site->title, 'name' => get_string('coreversion', 'local_sitestats'))) .
PHP_EOL;
}

// If there was a timeout, head over to next site.
Expand All @@ -414,7 +420,8 @@ public function execute()
// Otherwise we have to say that we did not get this information.
else {
// Output log.
echo get_string('crawl_coreinformationnotfound', 'local_sitestats', array('site' => $site->title, 'key' => get_string('coreversion', 'local_sitestats'))).PHP_EOL;
echo get_string('crawl_coreinformationnotfound', 'local_sitestats',
array('site' => $site->title, 'name' => get_string('coreversion', 'local_sitestats'))) . PHP_EOL;
}

// Curl close
Expand Down
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="site" TYPE="int" LENGTH="5" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="key" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="name" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="value" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
Expand Down
52 changes: 52 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This file keeps track of upgrades to the "Site statistics" plugin
*
* @package local_sitestats
* @copyright 2019 Alexander Bias, Ulm University <[email protected]>
* @author 2021 Adrian Perez, Fernfachhochschule Schweiz (FFHS) <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Upgrade the sitestats plugin.
*
* @param int $oldversion
* @return bool
*/
function xmldb_local_sitestats_upgrade($oldversion) {
global $DB;

$dbman = $DB->get_manager();

if ($oldversion < 2019080108) {
// Rename field key on table local_sitestats_core to name.
$table = new xmldb_table('local_sitestats_core');
$field = new xmldb_field('key', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null, 'site');

// Launch rename field key.
$dbman->rename_field($table, $field, 'name');

// Sitestats savepoint reached.
upgrade_plugin_savepoint(true, 2019080108, 'local', 'sitestats');
}

return true;
}
6 changes: 3 additions & 3 deletions lang/en/local_sitestats.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
$string['chart_pluginusedpersiteaxis'] = '{$a->from} - {$a->to} plugins';
$string['chart_pluginusedpersiteabsolutelabel'] = 'Sites with the given amount of plugins used';
$string['crawl_corefinish'] = 'CORE FINISH: Site "{$a->site}" has been crawled for core information completely';
$string['crawl_coreinformationfounderror'] = 'Database problem when storing core information {$a->key} to database';
$string['crawl_coreinformationfound'] = 'CORE INFORMATION FOUND: Site "{$a->site}" did tell us this core information: {$a->key} = {$a->value}';
$string['crawl_coreinformationnotfound'] = 'CORE INFORMATION NOT FOUND: Site "{$a->site}" did not tell us this core information: {$a->key}';
$string['crawl_coreinformationfounderror'] = 'Database problem when storing core information {$a->name} to database';
$string['crawl_coreinformationfound'] = 'CORE INFORMATION FOUND: Site "{$a->site}" did tell us this core information: {$a->name} = {$a->value}';
$string['crawl_coreinformationnotfound'] = 'CORE INFORMATION NOT FOUND: Site "{$a->site}" did not tell us this core information: {$a->name}';
$string['crawl_corestart'] = 'CORE START: Site "{$a->site}" is now being crawled for core information';
$string['crawl_coreskipped'] = 'CORE SKIPPED: Site "{$a->site}" has being crawled for core information recently';
$string['crawl_crawlfinish'] = 'CRAWL FINISH: Configured sites have been crawled completely';
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'local_sitestats';
$plugin->version = 2019080106;
$plugin->version = 2019080108;
$plugin->release = 'v3.7-r1';
$plugin->requires = 2019052000;
$plugin->maturity = MATURITY_RC;