| Conditions | 8 |
| Paths | 9 |
| Total Lines | 101 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 30 | public function up(Schema $schema): void |
||
| 31 | { |
||
| 32 | $container = $this->getContainer(); |
||
| 33 | $doctrine = $container->get('doctrine'); |
||
| 34 | $em = $doctrine->getManager(); |
||
| 35 | /** @var Connection $connection */ |
||
| 36 | $connection = $em->getConnection(); |
||
| 37 | |||
| 38 | $documentRepo = $container->get(CDocumentRepository::class); |
||
| 39 | $courseRepo = $container->get(CourseRepository::class); |
||
| 40 | $sessionRepo = $container->get(SessionRepository::class); |
||
| 41 | $groupRepo = $container->get(CGroupRepository::class); |
||
| 42 | $userRepo = $container->get(UserRepository::class); |
||
| 43 | |||
| 44 | /** @var Kernel $kernel */ |
||
| 45 | $kernel = $container->get('kernel'); |
||
| 46 | $rootPath = $kernel->getProjectDir(); |
||
| 47 | |||
| 48 | $userList = []; |
||
| 49 | $groupList = []; |
||
| 50 | $sessionList = []; |
||
| 51 | $batchSize = self::BATCH_SIZE; |
||
| 52 | |||
| 53 | $admin = $this->getAdmin(); |
||
| 54 | $urlRepo = $em->getRepository(AccessUrl::class); |
||
| 55 | $urls = $urlRepo->findAll(); |
||
| 56 | |||
| 57 | /** @var AccessUrl $url */ |
||
| 58 | foreach ($urls as $url) { |
||
| 59 | $accessUrlRelCourses = $url->getCourses(); |
||
| 60 | /** @var AccessUrlRelCourse $accessUrlRelCourse */ |
||
| 61 | foreach ($accessUrlRelCourses as $accessUrlRelCourse) { |
||
| 62 | $counter = 1; |
||
| 63 | $course = $accessUrlRelCourse->getCourse(); |
||
| 64 | $courseId = $course->getId(); |
||
| 65 | $courseCode = $course->getCode(); |
||
| 66 | $course = $courseRepo->find($courseId); |
||
| 67 | |||
| 68 | $sql = "SELECT * FROM c_document WHERE c_id = $courseId |
||
| 69 | ORDER BY filetype DESC"; |
||
| 70 | $result = $connection->executeQuery($sql); |
||
| 71 | $documents = $result->fetchAllAssociative(); |
||
| 72 | foreach ($documents as $documentData) { |
||
| 73 | $documentId = $documentData['iid']; |
||
| 74 | $documentPath = $documentData['path']; |
||
| 75 | |||
| 76 | /** @var CDocument $document */ |
||
| 77 | $document = $documentRepo->find($documentId); |
||
| 78 | if ($document->hasResourceNode()) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | |||
| 82 | $sql = "SELECT * FROM c_item_property |
||
| 83 | WHERE tool = 'document' AND c_id = $courseId AND ref = $documentId"; |
||
| 84 | $result = $connection->executeQuery($sql); |
||
| 85 | $items = $result->fetchAllAssociative(); |
||
| 86 | |||
| 87 | // For some reason this document doesnt have a c_item_property value. |
||
| 88 | if (empty($items)) { |
||
| 89 | continue; |
||
| 90 | } |
||
| 91 | |||
| 92 | $createNode = false; |
||
| 93 | $resourceNode = null; |
||
| 94 | $parent = null; |
||
| 95 | if ('.' !== dirname($documentPath)) { |
||
| 96 | $parentId = \DocumentManager::get_document_id( |
||
| 97 | ['real_id' => $courseId], |
||
| 98 | dirname($documentPath) |
||
| 99 | ); |
||
| 100 | $parent = $documentRepo->find($parentId); |
||
| 101 | } |
||
| 102 | |||
| 103 | if (null === $parent) { |
||
| 104 | $parent = $course; |
||
| 105 | } |
||
| 106 | |||
| 107 | $this->fixItemProperty($documentRepo, $course, $admin, $document, $parent, $items); |
||
| 108 | $filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/document/'.$documentPath; |
||
| 109 | $this->addLegacyFileToResource($filePath, $documentRepo, $document, $documentId); |
||
| 110 | |||
| 111 | $em->persist($document); |
||
| 112 | $em->flush(); |
||
| 113 | //$em->clear(); |
||
| 114 | /*if ($createNode) { |
||
| 115 | $em->persist($document); |
||
| 116 | if (0 === $counter % $batchSize) { |
||
| 117 | $em->flush(); |
||
| 118 | $em->clear(); |
||
| 119 | } |
||
| 120 | |||
| 121 | $counter++; |
||
| 122 | } else { |
||
| 123 | $em->clear(); |
||
| 124 | }*/ |
||
| 125 | } |
||
| 126 | $em->clear(); |
||
| 127 | } |
||
| 128 | |||
| 129 | $em->flush(); |
||
| 130 | $em->clear(); |
||
| 131 | } |
||
| 139 |