Skip to content

Commit

Permalink
Merge pull request moodlehq#4 from andrewnicols/singularisePlurals
Browse files Browse the repository at this point in the history
Singularise plurals
  • Loading branch information
andrewnicols authored Aug 1, 2023
2 parents aedc4f4 + dba7088 commit e556abf
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 215 deletions.
58 changes: 29 additions & 29 deletions application/src/Controller/BackOfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace App\Controller;

use App\Entity\Externalids;
use App\Entity\Medias;
use App\Entity\Passwords;
use App\Entity\ExternalId;
use App\Entity\Media;
use App\Entity\Password;
use App\Entity\RoomMember;
use App\Entity\Rooms;
use App\Entity\Threepids;
use App\Entity\Tokens;
use App\Entity\Users;
use App\Entity\Room;
use App\Entity\ThreePID;
use App\Entity\Token;
use App\Entity\User;
use App\Traits\GeneralTrait;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -36,21 +36,21 @@ public function backOfficeCreateAdmin(string $serverID, Request $request) : Json
if ($method === 'POST') {
$entityManager = $this->getDoctrine()->getManager();

$user = $entityManager->getRepository(Users::class)->findOneBy(['userid' => '@admin:synapse']);
$user = $entityManager->getRepository(User::class)->findOneBy(['userid' => '@admin:synapse']);
if (!$user) {
$user = new Users();
$user = new User();
$user->setServerid($serverID);
$user->setUserid('@admin:synapse');
$user->setDisplayname('Admin User');
$user->setAdmin(true);
}

// Process tokens.
$token = $entityManager->getRepository(Tokens::class)
$token = $entityManager->getRepository(Token::class)
->findOneBy(['userid' => $user->getId()]);
if (!$token) {
// New user, or existing user without any associated Tokens.
$token = new Tokens();
$token = new Token();
$token->setAccesstoken($this->generateToken('access-token'));
$token->setRefreshtoken($this->generateToken('refresh-token'));
$token->setExpiresinms();
Expand All @@ -62,22 +62,22 @@ public function backOfficeCreateAdmin(string $serverID, Request $request) : Json
}

// Process password.
$passwords = $entityManager->getRepository(Passwords::class)
$password = $entityManager->getRepository(Password::class)
->findOneBy(['userid' => $user->getId()]);
if (!$passwords) {
if (!$password) {
// 1. Generates and returns token as password.
// 2. Generates and returns token pattern.
$password = $this->hashPassword('password', null, true);
$newpassword = $this->hashPassword('password', null, true);

// New user, or existing user without any associated Tokens.
$passwords = new Passwords();
$passwords->setPassword($password['token']);
$passwords->setServerid($serverID);
$password = new Password();
$password->setPassword($newpassword['token']);
$password->setServerid($serverID);

$user->addPasswords($passwords);
$user->setPasswordpattern($password['pattern']);
$passwords->setUserid($user);
$entityManager->persist($passwords);
$user->addPassword($password);
$user->setPasswordpattern($newpassword['pattern']);
$password->setUserid($user);
$entityManager->persist($password);
}
$entityManager->persist($user);
$entityManager->flush();
Expand All @@ -102,9 +102,9 @@ public function backOfficeCreateAdmin(string $serverID, Request $request) : Json
public function backOfficeReset(string $serverID) : JsonResponse
{
$entities = [
Users::class,
Rooms::class,
Medias::class
User::class,
Room::class,
Media::class
];

$entityManager = $this->getDoctrine()->getManager();
Expand All @@ -128,7 +128,7 @@ public function backOfficeReset(string $serverID) : JsonResponse
public function getAllRooms(string $serverID): JSONResponse
{
$rooms = $this->getDoctrine()
->getRepository(Rooms::class)
->getRepository(Room::class)
->findBy(['serverid' => $serverID]);

$responsedata = (object) [
Expand Down Expand Up @@ -161,7 +161,7 @@ function (RoomMember $membership): bool {
public function getAllUsers(string $serverID): JSONResponse
{
$users = $this->getDoctrine()
->getRepository(Users::class)
->getRepository(User::class)
->findBy(['serverid' => $serverID]);

return new JsonResponse(
Expand Down Expand Up @@ -190,7 +190,7 @@ public function setData(
'rooms' => [],
];

$userRepository = $entityManager->getRepository(Users::class);
$userRepository = $entityManager->getRepository(User::class);
$admin = $userRepository->findOneBy(
[
'admin' => true,
Expand All @@ -200,7 +200,7 @@ public function setData(

if (property_exists($payload, 'users')) {
foreach ($payload->users as $userdata) {
$user = new Users();
$user = new User();
$user->setServerid($serverID);
$user->setDisplayname($userdata->fullname);
$user->setUserid($userdata->id);
Expand All @@ -223,7 +223,7 @@ public function setData(
$host,
);

$room = new Rooms();
$room = new Room();
$room->setRoomid($roomID);
$room->setName($roomName);
$room->setTopic($roomdata->topic ?? null);
Expand Down
26 changes: 13 additions & 13 deletions application/src/Controller/MatrixController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Controller;

use App\Entity\Passwords;
use App\Entity\Rooms;
use App\Entity\Password;
use App\Entity\Room;
use App\Entity\RoomMember;
use App\Entity\Tokens;
use App\Entity\Users;
use App\Entity\Token;
use App\Entity\User;
use App\Traits\GeneralTrait;
use App\Traits\MatrixSynapseTrait;
use stdClass;
Expand Down Expand Up @@ -126,18 +126,18 @@ public function login(string $serverID, Request $request): JsonResponse {
}

$entityManager = $this->getDoctrine()->getManager();
$user = $entityManager->getRepository(Users::class)->findOneBy($check['loginidentifier']);
$user = $entityManager->getRepository(User::class)->findOneBy($check['loginidentifier']);

$passwordpatter = $user ? $user->getPasswordpattern() : null;
$userid = $user ? $user->getId() : null;
$password = $entityManager->getRepository(Passwords::class)->findOneBy([
$password = $entityManager->getRepository(Password::class)->findOneBy([
'password' => $this->hashPassword($payload->password, $passwordpatter)['token'],
'userid' => $userid
]);

// Check if user with its password is found.
if ($user && $password) {
$token = $entityManager->getRepository(Tokens::class)->findOneBy(['userid' => $user->getId()]);
$token = $entityManager->getRepository(Token::class)->findOneBy(['userid' => $user->getId()]);

// Assign client server id if the server id is NULL.
if (is_null($token->getServerid())) {
Expand Down Expand Up @@ -245,7 +245,7 @@ public function createRoom(string $serverID, Request $request):JsonResponse {

// Store the room in the DB.
$entityManager = $this->getDoctrine()->getManager();
$room = new Rooms();
$room = new Room();

$room->setRoomid($roomID);
$room->setName($roomName);
Expand All @@ -254,7 +254,7 @@ public function createRoom(string $serverID, Request $request):JsonResponse {
$room->setCreator($accessCheck['user_id']);
if (isset($payload->room_alias_name) && !empty($payload->room_alias_name)) {
$room_alias = "#{$payload->room_alias_name}:{$host}";
$check_alias = $entityManager->getRepository(Rooms::class)->findOneBy(['roomalias' => $room_alias]);
$check_alias = $entityManager->getRepository(Room::class)->findOneBy(['roomalias' => $room_alias]);
if (empty($check_alias)) {
$room->setRoomAlias($room_alias);
$response['room_alias'] = $room_alias;
Expand Down Expand Up @@ -295,7 +295,7 @@ public function kick(
$entityManager = $this->getDoctrine()->getManager();

// Check room exists.
$room = $entityManager->getRepository(Rooms::class)->findOneBy([
$room = $entityManager->getRepository(Room::class)->findOneBy([
'serverid' => $serverID,
'roomid' => $roomID,
]);
Expand All @@ -309,7 +309,7 @@ public function kick(
return $check['message'];
}

$user = $entityManager->getRepository(Users::class)->findOneBy([
$user = $entityManager->getRepository(User::class)->findOneBy([
'serverid' => $serverID,
'userid' => $payload->user_id,
]);
Expand Down Expand Up @@ -363,7 +363,7 @@ public function roomState(string $serverID, string $roomID, string $eventType, R
$entityManager = $this->getDoctrine()->getManager();

// Check room exists.
$room = $entityManager->getRepository(Rooms::class)->findOneBy([
$room = $entityManager->getRepository(Room::class)->findOneBy([
'serverid' => $serverID,
'roomid' => $roomID,
]);
Expand Down Expand Up @@ -441,7 +441,7 @@ public function getJoinedMembers(string $serverID, string $roomID, Request $requ
}

$entityManager = $this->getDoctrine()->getManager();
$room = $entityManager->getRepository(Rooms::class)->findOneBy([
$room = $entityManager->getRepository(Room::class)->findOneBy([
'serverid' => $serverID,
'roomid' => $roomID,
]);
Expand Down
4 changes: 2 additions & 2 deletions application/src/Controller/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Controller;

use App\Entity\Medias;
use App\Entity\Media;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
Expand Down Expand Up @@ -58,7 +58,7 @@ public function uploadMedia(string $serverID, Request $request) : JsonResponse {
$filesystem = new Filesystem();
$filesystem->dumpFile($filepath, file_get_contents("php://input"));

$medias = new Medias();
$medias = new Media();
$medias->setContenturi($contenturi);
$medias->setServerid($serverID);

Expand Down
Loading

0 comments on commit e556abf

Please sign in to comment.