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\Repository\CDocumentRepository; |
11
|
|
|
use Doctrine\DBAL\Connection; |
12
|
|
|
use Doctrine\DBAL\Schema\Schema; |
13
|
|
|
|
14
|
|
|
final class Version20240602231700 extends AbstractMigrationChamilo |
15
|
|
|
{ |
16
|
|
|
public function getDescription(): string |
17
|
|
|
{ |
18
|
|
|
return 'Delete documents that do not have parents based on the path.'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function up(Schema $schema): void |
22
|
|
|
{ |
23
|
|
|
$documentRepo = $this->container->get(CDocumentRepository::class); |
|
|
|
|
24
|
|
|
|
25
|
|
|
// Query to get the documentIids |
26
|
|
|
$sql = "SELECT cd1.iid, cd1.path, cd1.c_id |
27
|
|
|
FROM c_document cd1 |
28
|
|
|
LEFT JOIN c_document cd2 ON cd2.c_id = cd1.c_id AND cd2.path = SUBSTRING_INDEX(cd1.path, '/', 2) |
29
|
|
|
WHERE cd1.path LIKE '/shared_folder_session_%' |
30
|
|
|
AND cd2.iid IS NULL"; |
31
|
|
|
$result = $this->connection->executeQuery($sql); |
32
|
|
|
$orphans = $result->fetchAllAssociative(); |
33
|
|
|
|
34
|
|
|
if (empty($orphans)) { |
35
|
|
|
echo 'No orphan documents found.' . PHP_EOL; |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
foreach ($orphans as $itemData) { |
40
|
|
|
echo 'Deleting document with iid: ' . $itemData['iid'] . PHP_EOL; |
41
|
|
|
$document = $documentRepo->find($itemData['iid']); |
42
|
|
|
if ($document) { |
43
|
|
|
if ($document->getResourceNode()) { |
44
|
|
|
$this->entityManager->remove($document->getResourceNode()); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
$this->entityManager->remove($document); |
47
|
|
|
echo 'Deleted document with iid: ' . $itemData['iid'] . PHP_EOL; |
48
|
|
|
} else { |
49
|
|
|
echo 'Document with iid ' . $itemData['iid'] . ' not found.' . PHP_EOL; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->entityManager->flush(); |
54
|
|
|
$this->entityManager->clear(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
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.