Passed
Push — dependabot/npm_and_yarn/cross-... ( 1f4447...a16049 )
by
unknown
10:20
created

Version20241120123300   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A up() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Chamilo\CourseBundle\Entity\CTool;
11
use Doctrine\DBAL\Schema\Schema;
12
13
final class Version20241120123300 extends AbstractMigrationChamilo
14
{
15
    public function getDescription(): string
16
    {
17
        return 'Remove session-specific tools and related entities, keeping only course-base tools.';
18
    }
19
20
    public function up(Schema $schema): void
21
    {
22
        $repository = $this->entityManager->getRepository(CTool::class);
0 ignored issues
show
Bug introduced by
The method getRepository() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        /** @scrutinizer ignore-call */ 
23
        $repository = $this->entityManager->getRepository(CTool::class);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
24
        $queryBuilder = $repository->createQueryBuilder('ct');
25
        $queryBuilder->where('ct.session IS NOT NULL');
26
        $sessionTools = $queryBuilder->getQuery()->getResult();
27
28
        foreach ($sessionTools as $tool) {
29
            $this->entityManager->remove($tool);
30
            error_log(\sprintf('Removed tool: %s (ID: %d)', $tool->getTitle(), $tool->getIid()));
31
        }
32
33
        $this->entityManager->flush();
34
    }
35
}
36