diff --git a/communication/provider/matrix/classes/communication_feature.php b/communication/provider/matrix/classes/communication_feature.php index a7070f38aed..81637438425 100644 --- a/communication/provider/matrix/classes/communication_feature.php +++ b/communication/provider/matrix/classes/communication_feature.php @@ -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, ); diff --git a/communication/provider/matrix/classes/matrix_rooms.php b/communication/provider/matrix/classes/matrix_room.php similarity index 88% rename from communication/provider/matrix/classes/matrix_rooms.php rename to communication/provider/matrix/classes/matrix_room.php index 157351cd352..4ebb0d92ddd 100644 --- a/communication/provider/matrix/classes/matrix_rooms.php +++ b/communication/provider/matrix/classes/matrix_room.php @@ -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 * @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); } diff --git a/communication/provider/matrix/db/install.xml b/communication/provider/matrix/db/install.xml index 3fa23eb7b24..787f06bacb7 100644 --- a/communication/provider/matrix/db/install.xml +++ b/communication/provider/matrix/db/install.xml @@ -4,7 +4,7 @@ xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd" > - +
diff --git a/communication/provider/matrix/db/upgrade.php b/communication/provider/matrix/db/upgrade.php index e1704b43d13..07f40633a4f 100644 --- a/communication/provider/matrix/db/upgrade.php +++ b/communication/provider/matrix/db/upgrade.php @@ -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; } diff --git a/communication/provider/matrix/tests/communication_feature_test.php b/communication/provider/matrix/tests/communication_feature_test.php index b937ccc41f7..7b81f24775f 100644 --- a/communication/provider/matrix/tests/communication_feature_test.php +++ b/communication/provider/matrix/tests/communication_feature_test.php @@ -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()); diff --git a/communication/provider/matrix/tests/matrix_rooms_test.php b/communication/provider/matrix/tests/matrix_room_test.php similarity index 81% rename from communication/provider/matrix/tests/matrix_rooms_test.php rename to communication/provider/matrix/tests/matrix_room_test.php index 7f9788252ba..a017d0f0602 100644 --- a/communication/provider/matrix/tests/matrix_rooms_test.php +++ b/communication/provider/matrix/tests/matrix_room_test.php @@ -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 * @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')); } } diff --git a/communication/provider/matrix/version.php b/communication/provider/matrix/version.php index 85d7306dc69..645865504d0 100644 --- a/communication/provider/matrix/version.php +++ b/communication/provider/matrix/version.php @@ -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;