MDL-41266 improve naming of log reader interfaces

This commit is contained in:
Petr Škoda 2014-02-27 16:42:44 +08:00
parent 43d91d7665
commit 993d8d838f
10 changed files with 77 additions and 42 deletions

View File

@ -25,7 +25,7 @@
namespace logstore_database\log;
defined('MOODLE_INTERNAL') || die();
class store implements \tool_log\log\writer, \core\log\reader {
class store implements \tool_log\log\writer, \core\log\sql_select_reader {
use \tool_log\helper\store,
\tool_log\helper\reader,
\tool_log\helper\buffered_writer {
@ -166,7 +166,7 @@ class store implements \tool_log\log\writer, \core\log\reader {
*
* @return array|\core\event\base[] array of events.
*/
public function get_events($selectwhere, array $params, $sort, $limitfrom, $limitnum) {
public function get_events_select($selectwhere, array $params, $sort, $limitfrom, $limitnum) {
if (!$this->init()) {
return array();
}
@ -205,7 +205,7 @@ class store implements \tool_log\log\writer, \core\log\reader {
*
* @return int Number of events available for the given conditions
*/
public function get_events_count($selectwhere, array $params) {
public function get_events_select_count($selectwhere, array $params) {
if (!$this->init()) {
return 0;
}

View File

@ -150,7 +150,8 @@ class logstore_database_store_testcase extends advanced_testcase {
$this->assertEquals($data, $log3);
// Test reading.
$events = $store->get_events('', array(), 'id', 0, 0);
$this->assertSame(3, $store->get_events_select_count('', array()));
$events = $store->get_events_select('', array(), 'id', 0, 0);
$this->assertCount(3, $events);
$resev1 = array_shift($events);
array_shift($events);

View File

@ -26,7 +26,7 @@ namespace logstore_legacy\log;
defined('MOODLE_INTERNAL') || die();
class store implements \tool_log\log\store, \core\log\reader {
class store implements \tool_log\log\store, \core\log\sql_select_reader {
use \tool_log\helper\store,
\tool_log\helper\reader;
@ -42,7 +42,7 @@ class store implements \tool_log\log\store, \core\log\reader {
'origin' => 'ip'
);
public function get_events($selectwhere, array $params, $sort, $limitfrom, $limitnum) {
public function get_events_select($selectwhere, array $params, $sort, $limitfrom, $limitnum) {
global $DB;
// Replace db field names to make it compatible with legacy log.
@ -71,7 +71,7 @@ class store implements \tool_log\log\store, \core\log\reader {
return $events;
}
public function get_events_count($selectwhere, array $params) {
public function get_events_select_count($selectwhere, array $params) {
global $DB;
// Replace db field names to make it compatible with legacy log.

View File

@ -49,7 +49,7 @@ class logstore_legacy_store_testcase extends advanced_testcase {
$this->assertEquals(array('logstore_legacy'), array_keys($stores));
$store = $stores['logstore_legacy'];
$this->assertInstanceOf('logstore_legacy\log\store', $store);
$this->assertInstanceOf('core\log\reader', $store);
$this->assertInstanceOf('core\log\sql_select_reader', $store);
$this->assertTrue($store->is_logging());
$logs = $DB->get_records('log', array(), 'id ASC');

View File

@ -26,7 +26,7 @@ namespace logstore_standard\log;
defined('MOODLE_INTERNAL') || die();
class store implements \tool_log\log\writer, \core\log\sql_reader {
class store implements \tool_log\log\writer, \core\log\sql_internal_reader {
use \tool_log\helper\store,
\tool_log\helper\buffered_writer,
\tool_log\helper\reader;
@ -75,7 +75,7 @@ class store implements \tool_log\log\writer, \core\log\sql_reader {
$DB->insert_records('logstore_standard_log', $dataobj);
}
public function get_events($selectwhere, array $params, $sort, $limitfrom, $limitnum) {
public function get_events_select($selectwhere, array $params, $sort, $limitfrom, $limitnum) {
global $DB;
$events = array();
@ -100,12 +100,12 @@ class store implements \tool_log\log\writer, \core\log\sql_reader {
return $events;
}
public function get_events_count($selectwhere, array $params) {
public function get_events_select_count($selectwhere, array $params) {
global $DB;
return $DB->count_records_select('logstore_standard_log', $selectwhere, $params);
}
public function get_log_table() {
public function get_internal_log_table_name() {
return 'logstore_standard_log';
}

View File

@ -111,8 +111,13 @@ class logstore_standard_store_testcase extends advanced_testcase {
$data['realuserid'] = 2;
$this->assertEquals($data, $log3);
// Test table exists.
$tablename = $store->get_internal_log_table_name();
$this->assertTrue($DB->get_manager()->table_exists($tablename));
// Test reading.
$events = $store->get_events('', array(), 'id', 0, 0);
$this->assertSame(3, $store->get_events_select_count('', array()));
$events = $store->get_events_select('', array(), 'id', 0, 0);
$this->assertCount(3, $events);
$resev1 = array_shift($events);
array_shift($events);

View File

@ -48,24 +48,24 @@ class tool_log_manager_testcase extends advanced_testcase {
$this->assertCount(2, $stores);
foreach ($stores as $key => $store) {
$this->assertInternalType('string', $key);
$this->assertInstanceOf('core\log\reader', $store);
$this->assertInstanceOf('core\log\sql_select_reader', $store);
}
$stores = $manager->get_readers('core\log\sql_reader');
$stores = $manager->get_readers('core\log\sql_internal_reader');
$this->assertInternalType('array', $stores);
$this->assertCount(1, $stores);
foreach ($stores as $key => $store) {
$this->assertInternalType('string', $key);
$this->assertSame('logstore_standard', $key);
$this->assertInstanceOf('core\log\sql_reader', $store);
$this->assertInstanceOf('core\log\sql_internal_reader', $store);
}
$stores = $manager->get_readers('core\log\reader');
$stores = $manager->get_readers('core\log\sql_select_reader');
$this->assertInternalType('array', $stores);
$this->assertCount(2, $stores);
foreach ($stores as $key => $store) {
$this->assertInternalType('string', $key);
$this->assertInstanceOf('core\log\reader', $store);
$this->assertInstanceOf('core\log\sql_select_reader', $store);
}
}
}

View File

@ -49,27 +49,6 @@ interface reader {
*/
public function can_access(\context $context);
/**
* Fetch records using given criteria.
*
* @param string $selectwhere
* @param array $params
* @param string $sort
* @param int $limitfrom
* @param int $limitnum
* @return \core\event\base[]
*/
public function get_events($selectwhere, array $params, $sort, $limitfrom, $limitnum);
/**
* Return number of events matching given criteria.
*
* @param string $selectwhere
* @param array $params
* @return int
*/
public function get_events_count($selectwhere, array $params);
/**
* Are the new events appearing in the reader?
*

View File

@ -18,7 +18,7 @@
* Log storage sql reader interface.
*
* @package core
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -26,7 +26,7 @@ namespace core\log;
defined('MOODLE_INTERNAL') || die();
interface sql_reader extends reader {
interface sql_internal_reader extends sql_select_reader {
/**
* Returns name of the table or database view that
@ -37,5 +37,5 @@ interface sql_reader extends reader {
*
* @return string
*/
public function get_log_table();
public function get_internal_log_table_name();
}

View File

@ -0,0 +1,50 @@
<?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/>.
/**
* Log storage reader interface.
*
* @package core
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\log;
defined('MOODLE_INTERNAL') || die();
interface sql_select_reader extends reader {
/**
* Fetch records using given criteria.
*
* @param string $selectwhere
* @param array $params
* @param string $sort
* @param int $limitfrom
* @param int $limitnum
* @return \core\event\base[]
*/
public function get_events_select($selectwhere, array $params, $sort, $limitfrom, $limitnum);
/**
* Return number of events matching given criteria.
*
* @param string $selectwhere
* @param array $params
* @return int
*/
public function get_events_select_count($selectwhere, array $params);
}