Skip to content
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

Remove deprecated use of $this->getDoctrine() #770

Merged
merged 1 commit into from
Feb 24, 2022
Merged
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
12 changes: 10 additions & 2 deletions src/Controller/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Services\LmsUserService;
use App\Services\SessionService;
use App\Services\UtilityService;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -25,6 +26,13 @@ class AuthController extends AbstractController
/** @var LmsApiService $lmsApi */
private $lmsApi;

private ManagerRegistry $doctrine;

public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

/**
* @Route("/authorize", name="authorize")
*/
Expand Down Expand Up @@ -108,7 +116,7 @@ public function encryptDeveloperKey(Request $request, UtilityService $util)
$instId = $request->query->get('id');
$institution = $util->getInstitutionById($instId);
$institution->encryptDeveloperKey();
$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();

return new Response('Updated.');
}
Expand All @@ -127,7 +135,7 @@ protected function requestApiKeyFromLms()

if (empty($clientSecret)) {
$institution->encryptDeveloperKey();
$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();
$clientSecret = $institution->getApiClientSecret();
}

Expand Down
14 changes: 11 additions & 3 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Services\LmsUserService;
use App\Services\SessionService;
use App\Services\UtilityService;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -23,6 +24,13 @@ class DashboardController extends AbstractController
/** @var LmsApiService $lmsApi */
protected $lmsApi;

private ManagerRegistry $doctrine;

public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

/**
* @Route("/dashboard", name="dashboard")
*/
Expand Down Expand Up @@ -57,7 +65,7 @@ public function index(
$this->util->exitWithMessage('Missing LMS course ID.');
}

$courseRepo = $this->getDoctrine()->getRepository(Course::class);
$courseRepo = $this->doctrine->getRepository(Course::class);
/** @var Course $course */
$course = $courseRepo->findOneBy(['lmsCourseId' => $lmsCourseId]);

Expand Down Expand Up @@ -134,8 +142,8 @@ protected function createCourse(Institution $institution, $lmsCourseId)
$course->setActive(true);
$course->setDirty(false);

$this->getDoctrine()->getManager()->persist($course);
$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->persist($course);
$this->doctrine->getManager()->flush();

return $course;
}
Expand Down
12 changes: 10 additions & 2 deletions src/Controller/FileItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
use App\Response\ApiResponse;
use App\Services\LmsPostService;
use App\Services\UtilityService;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class FileItemsController extends ApiController
{
private ManagerRegistry $doctrine;

public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

/**
* @Route("/api/files/{file}/review", name="review_file")
*/
Expand All @@ -35,7 +43,7 @@ public function reviewFile(FileItem $file, Request $request, UtilityService $uti
// Update report stats
$report = $course->getUpdatedReport();

$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();

// Create response
if ($file->getReviewed()) {
Expand Down Expand Up @@ -81,7 +89,7 @@ public function postFile(FileItem $file, Request $request, UtilityService $util,
// Update report stats
$report = $course->getUpdatedReport();

$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();

// Create response
$apiResponse->addMessage('form.msg.success_replaced', 'success', 5000);
Expand Down
18 changes: 13 additions & 5 deletions src/Controller/IssuesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
use App\Services\LmsPostService;
use App\Services\PhpAllyService;
use App\Services\UtilityService;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class IssuesController extends ApiController
{
private ManagerRegistry $doctrine;

public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

/**
* Save change to issue HTML to LMS
*
Expand Down Expand Up @@ -62,7 +70,7 @@ public function saveIssue(

// Update issue HTML
$issue->setNewHtml($newHtml);
$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();

// Save content to LMS
$lmsPost->saveContentToLms($issue, $user);
Expand All @@ -77,7 +85,7 @@ public function saveIssue(
$issue->setStatus(Issue::$issueStatusFixed);
$issue->setFixedBy($user);
$issue->setFixedOn($util->getCurrentTime());
$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();

// Update report stats
$report = $course->getUpdatedReport();
Expand Down Expand Up @@ -121,7 +129,7 @@ public function markAsReviewed(Request $request, LmsPostService $lmsPost, Utilit
$issueUpdate = \json_decode($request->getContent(), true);

$issue->setNewHtml($issueUpdate['newHtml']);
$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();

// Save content to LMS
$response = $lmsPost->saveContentToLms($issue, $user);
Expand All @@ -138,7 +146,7 @@ public function markAsReviewed(Request $request, LmsPostService $lmsPost, Utilit
// Update report stats
$report = $course->getUpdatedReport();

$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();

if ($issue->getStatus() == Issue::$issueStatusResolved) {
$apiResponse->addMessage('form.msg.success_resolved', 'success');
Expand Down Expand Up @@ -188,7 +196,7 @@ public function scanIssue(Issue $issue, PhpAllyService $phpAlly, UtilityService
'report' => $report
]);

$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();
$apiResponse->addMessage('form.msg.manually_fixed', 'success');
}
else {
Expand Down
28 changes: 18 additions & 10 deletions src/Controller/LtiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Services\LmsApiService;
use App\Services\SessionService;
use App\Services\UtilityService;
use Doctrine\Persistence\ManagerRegistry;
use Firebase\JWT\JWK;
use \Firebase\JWT\JWT;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -26,14 +27,21 @@ class LtiController extends AbstractController
/** @var \App\Services\LmsApiService $lmsApi */
private $lmsApi;

private ManagerRegistry $doctrine;

public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

/**
* @Route("/lti/authorize", name="lti_authorize")
*/
public function ltiAuthorize(
Request $request,
SessionService $sessionService,
UtilityService $util,
LmsApiService $lmsApi
LmsApiService $lmsApi,
) {

$this->request = $request;
Expand Down Expand Up @@ -278,7 +286,7 @@ protected function saveRequestToSession()
$this->session->set('lms_api_domain', str_replace('https://', '', $domain));
}

$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();
} catch (\Exception $e) {
print_r($e->getMessage());
}
Expand Down Expand Up @@ -341,13 +349,13 @@ protected function getInstitutionFromSession()

if ($domain) {
$institution = $this
->getDoctrine()
->doctrine
->getRepository(Institution::class)
->findOneBy(['lmsDomain' => $domain]);

if (!$institution) {
$institution = $this
->getDoctrine()
->doctrine
->getRepository(Institution::class)
->findOneBy(['vanityUrl' => $domain]);
}
Expand All @@ -359,13 +367,13 @@ protected function getInstitutionFromSession()

if ($cleanedDomain) {
$institution = $this
->getDoctrine()
->doctrine
->getRepository(Institution::class)
->findOneBy(['lmsDomain' => $cleanedDomain]);

if (!$institution) {
$institution = $this
->getDoctrine()
->doctrine
->getRepository(Institution::class)
->findOneBy(['vanityUrl' => $cleanedDomain]);
}
Expand Down Expand Up @@ -397,8 +405,8 @@ protected function createUser()
$user->setName($this->session->get('lms_user_name'));
}

$this->getDoctrine()->getManager()->persist($user);
$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->persist($user);
$this->doctrine->getManager()->flush();

return $user;
}
Expand All @@ -419,7 +427,7 @@ protected function saveUserToSession()
$userId = $this->session->get('lms_user_id');

if ($domain && $userId) {
$user = $this->getDoctrine()->getRepository(User::class)
$user = $this->doctrine->getRepository(User::class)
->findOneBy(['username' => "{$domain}||{$userId}"]);
}
}
Expand All @@ -429,6 +437,6 @@ protected function saveUserToSession()
}

$this->session->set('userId', $user->getId());
$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();
}
}
12 changes: 10 additions & 2 deletions src/Controller/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Response\ApiResponse;
use App\Services\SessionService;
use App\Services\UtilityService;
use Doctrine\Persistence\ManagerRegistry;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
use Knp\Snappy\Pdf;
use Mpdf\Mpdf;
Expand All @@ -29,6 +30,13 @@ class ReportsController extends ApiController
private $request;
private $util;

private ManagerRegistry $doctrine;

public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

/**
* @Route("/api/courses/{course}/reports", methods={"GET"}, name="get_reports")
* @param Request $request
Expand All @@ -51,7 +59,7 @@ public function getAllReports(
}

/** @var ReportRepository $repository */
$repository = $this->getDoctrine()->getRepository(Report::class);
$repository = $this->doctrine->getRepository(Report::class);
$reports = $repository->findAllInCourse($course);

$apiResponse->setData($reports);
Expand Down Expand Up @@ -187,4 +195,4 @@ public function getPdfReport(
return new JsonResponse($apiResponse);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Controller/SyncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function requestContentSync(ContentItem $contentItem, LmsFetchService $lm
public function cronSync(LmsApiService $lmsApi)
{
/** @var CourseRepository $courseRepository */
$courseRepository = $this->getDoctrine()->getRepository(Course::class);
$courseRepository = $this->doctrine->getRepository(Course::class);
$courses = $courseRepository->findCoursesNeedingUpdate($this->maxAge);
$user = $this->getUser();

Expand Down
10 changes: 9 additions & 1 deletion src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
namespace App\Controller;

use App\Entity\User;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class UserController extends AbstractController
{
private ManagerRegistry $doctrine;

public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

/**
* @Route("/api/users/{user}", name="user_put", methods={"PUT"})
*/
Expand All @@ -26,7 +34,7 @@ public function update(User $user, Request $request): JsonResponse
$user->setRefreshToken('');
}

$this->getDoctrine()->getManager()->flush();
$this->doctrine->getManager()->flush();

return $this->json($user);
}
Expand Down