MDL-78747 communication_matrix: Correct table name

Note: This feature is currently master-only, and alpha. I have therefore
decided not to migrate data and am just dumping and re-crating the
table.
This commit is contained in:
Andrew Nicols
2023-08-26 14:46:53 +08:00
parent 9bfcd77d51
commit e7b5d97c9a
7 changed files with 44 additions and 32 deletions
@@ -50,8 +50,8 @@ class communication_feature implements
\core_communication\room_user_provider,
\core_communication\form_provider {
/** @var matrix_rooms $room The matrix room object to update room information */
private ?matrix_rooms $room = null;
/** @var matrix_room $room The matrix room object to update room information */
private ?matrix_room $room = null;
/** @var string|null The URI of the home server */
protected ?string $homeserverurl = null;
@@ -124,11 +124,11 @@ class communication_feature implements
/**
* Get the stored room configuration.
* @return null|matrix_rooms
* @return null|matrix_room
*/
public function get_room_configuration(): ?matrix_rooms {
public function get_room_configuration(): ?matrix_room {
if ($this->room === null) {
$this->room = matrix_rooms::load_by_processor_id($this->processor->get_id());
$this->room = matrix_room::load_by_processor_id($this->processor->get_id());
}
return $this->room;
@@ -480,7 +480,7 @@ class communication_feature implements
topic: $matrixroomtopic,
);
} else {
$this->room = matrix_rooms::create_room_record(
$this->room = matrix_room::create_room_record(
processorid: $this->processor->get_id(),
topic: $matrixroomtopic,
);
@@ -19,13 +19,15 @@ namespace communication_matrix;
use stdClass;
/**
* Class matrix_rooms to manage the updates to the room information in db.
* Class to manage the updates to the room information in db.
*
* @package communication_matrix
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class matrix_rooms {
class matrix_room {
private const TABLE = 'matrix_room';
/** @var \stdClass|null $record The matrix room record from db */
@@ -39,7 +41,7 @@ class matrix_rooms {
): ?self {
global $DB;
$record = $DB->get_record('matrix_rooms', ['commid' => $processorid]);
$record = $DB->get_record(self::TABLE, ['commid' => $processorid]);
if (!$record) {
return null;
@@ -48,7 +50,7 @@ class matrix_rooms {
}
/**
* Matrix rooms constructor to load the matrix room information from matrix_rooms table.
* Matrix rooms constructor to load the matrix room information from matrix_room table.
*
* @param stdClass $record
*/
@@ -77,7 +79,7 @@ class matrix_rooms {
'roomid' => $roomid,
'topic' => $topic,
];
$roomrecord->id = $DB->insert_record('matrix_rooms', $roomrecord);
$roomrecord->id = $DB->insert_record(self::TABLE, $roomrecord);
return self::load_by_processor_id($processorid);
}
@@ -102,7 +104,7 @@ class matrix_rooms {
$this->record->topic = $topic;
}
$DB->update_record('matrix_rooms', $this->record);
$DB->update_record(self::TABLE, $this->record);
}
/**
@@ -110,7 +112,8 @@ class matrix_rooms {
*/
public function delete_room_record(): void {
global $DB;
$DB->delete_records('matrix_rooms', ['commid' => $this->record->commid]);
$DB->delete_records(self::TABLE, ['commid' => $this->record->commid]);
unset($this->record);
}
+1 -1
View File
@@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="matrix_rooms" COMMENT="Stores the matrix room information associated with the communication instance.">
<TABLE NAME="matrix_room" COMMENT="Stores the matrix room information associated with the communication instance.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="commid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="ID of the communication record"/>
@@ -38,10 +38,19 @@ function xmldb_communication_matrix_upgrade($oldversion) {
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Plugin savepoint reached.
upgrade_plugin_savepoint(true, 2023060101, 'communication', 'matrix');
}
if ($oldversion < 2023071900) {
$table = new xmldb_table('matrix_rooms');
$dbman->rename_table($table, 'matrix_room');
// Plugin savepoint reached.
upgrade_plugin_savepoint(true, 2023071900, 'communication', 'matrix');
}
return true;
}
@@ -202,13 +202,13 @@ class communication_feature_test extends \advanced_testcase {
$processor = $communication->get_processor();
$provider = $communication->get_room_provider();
$room = matrix_rooms::load_by_processor_id($processor->get_id());
$room = matrix_room::load_by_processor_id($processor->get_id());
// Run the delete method.
$this->assertTrue($provider->delete_chat_room());
// The record of the room should have been removed.
$this->assertNull(matrix_rooms::load_by_processor_id($processor->get_id()));
$this->assertNull(matrix_room::load_by_processor_id($processor->get_id()));
// But the room itself shoudl exist.
$matrixroomdata = $this->get_matrix_room_data($room->get_room_id());
@@ -17,15 +17,15 @@
namespace communication_matrix;
/**
* Class matrix_rooms_test to test the matrix room data in db.
* Tests for the matrix_room class.
*
* @package communication_matrix
* @category test
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \communication_matrix\matrix_rooms
* @coversDefaultClass \communication_matrix\matrix_room
*/
class matrix_rooms_test extends \advanced_testcase {
class matrix_room_test extends \advanced_testcase {
/**
* Test for load_by_processor_id with no record.
@@ -33,7 +33,7 @@ class matrix_rooms_test extends \advanced_testcase {
* @covers ::load_by_processor_id
*/
public function test_load_by_processor_id_none(): void {
$this->assertNull(matrix_rooms::load_by_processor_id(999999999));
$this->assertNull(matrix_room::load_by_processor_id(999999999));
}
/**
@@ -49,38 +49,38 @@ class matrix_rooms_test extends \advanced_testcase {
public function test_create_room_record(): void {
$this->resetAfterTest();
$room = matrix_rooms::create_room_record(
$room = matrix_room::create_room_record(
processorid: 10000,
topic: null,
);
$this->assertInstanceOf(matrix_rooms::class, $room);
$this->assertInstanceOf(matrix_room::class, $room);
$this->assertEquals(10000, $room->get_processor_id());
$this->assertNotNull('', $room->get_topic());
$this->assertEquals('', $room->get_topic());
$this->assertNull($room->get_room_id());
$room = matrix_rooms::create_room_record(
$room = matrix_room::create_room_record(
processorid: 12345,
topic: 'The topic of this room is thusly',
);
$this->assertInstanceOf(matrix_rooms::class, $room);
$this->assertInstanceOf(matrix_room::class, $room);
$this->assertEquals(12345, $room->get_processor_id());
$this->assertEquals('The topic of this room is thusly', $room->get_topic());
$this->assertNull($room->get_room_id());
$room = matrix_rooms::create_room_record(
$room = matrix_room::create_room_record(
processorid: 54321,
topic: 'The topic of this room is thusly',
roomid: 'This is a roomid',
);
$this->assertInstanceOf(matrix_rooms::class, $room);
$this->assertInstanceOf(matrix_room::class, $room);
$this->assertEquals(54321, $room->get_processor_id());
$this->assertEquals('The topic of this room is thusly', $room->get_topic());
$this->assertEquals('This is a roomid', $room->get_room_id());
$reloadedroom = matrix_rooms::load_by_processor_id(54321);
$reloadedroom = matrix_room::load_by_processor_id(54321);
$this->assertEquals(54321, $reloadedroom->get_processor_id());
$this->assertEquals('The topic of this room is thusly', $reloadedroom->get_topic());
$this->assertEquals('This is a roomid', $reloadedroom->get_room_id());
@@ -95,7 +95,7 @@ class matrix_rooms_test extends \advanced_testcase {
public function test_update_room_record(): void {
$this->resetAfterTest();
$room = matrix_rooms::create_room_record(
$room = matrix_room::create_room_record(
processorid: 12345,
topic: 'The topic of this room is that',
);
@@ -130,13 +130,13 @@ class matrix_rooms_test extends \advanced_testcase {
$this->resetAfterTest();
$room = matrix_rooms::create_room_record(
$room = matrix_room::create_room_record(
processorid: 12345,
topic: 'The topic of this room is that',
);
$this->assertCount(1, $DB->get_records('matrix_rooms'));
$this->assertCount(1, $DB->get_records('matrix_room'));
$room->delete_room_record();
$this->assertCount(0, $DB->get_records('matrix_rooms'));
$this->assertCount(0, $DB->get_records('matrix_room'));
}
}
+1 -1
View File
@@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'communication_matrix';
$plugin->version = 2023060101;
$plugin->version = 2023071900;
$plugin->requires = 2023011300;
$plugin->maturity = MATURITY_ALPHA;