Conditions | 68 |
Paths | > 20000 |
Total Lines | 393 |
Code Lines | 270 |
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 |
||
24 | public function up(Schema $schema): void |
||
25 | { |
||
26 | $container = $this->getContainer(); |
||
27 | $em = $this->getEntityManager(); |
||
28 | |||
29 | /** @var Connection $connection */ |
||
30 | $connection = $em->getConnection(); |
||
31 | $kernel = $container->get('kernel'); |
||
32 | $rootPath = $kernel->getProjectDir(); |
||
33 | |||
34 | /** @var CDocumentRepository $documentRepo */ |
||
35 | $documentRepo = $container->get(CDocumentRepository::class); |
||
36 | |||
37 | $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
||
38 | |||
39 | /** @var Course $course */ |
||
40 | foreach ($q->toIterable() as $course) { |
||
41 | $courseId = $course->getId(); |
||
42 | $courseDirectory = $course->getDirectory(); |
||
43 | |||
44 | // Tool intro |
||
45 | $sql = "SELECT * FROM c_tool_intro WHERE c_id = {$courseId} ORDER BY iid"; |
||
46 | $result = $connection->executeQuery($sql); |
||
47 | $items = $result->fetchAllAssociative(); |
||
48 | if (!empty($items)) { |
||
49 | foreach ($items as $itemData) { |
||
50 | $originalIntroText = $itemData['intro_text']; |
||
51 | if (!empty($originalIntroText)) { |
||
52 | $updatedIntroText = $this->replaceURLParametersInContent($originalIntroText, $connection); |
||
53 | if ($originalIntroText !== $updatedIntroText) { |
||
54 | $sql = 'UPDATE c_tool_intro SET intro_text = :newIntroText WHERE iid = :introId'; |
||
55 | $params = [ |
||
56 | 'newIntroText' => $updatedIntroText, |
||
57 | 'introId' => $itemData['iid'], |
||
58 | ]; |
||
59 | $connection->executeQuery($sql, $params); |
||
60 | error_log('Updated c_tool_intro cid ='.$courseId); |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | // Course description |
||
67 | $sql = "SELECT * FROM c_course_description WHERE c_id = {$courseId} ORDER BY iid"; |
||
68 | $result = $connection->executeQuery($sql); |
||
69 | $items = $result->fetchAllAssociative(); |
||
70 | if (!empty($items)) { |
||
71 | foreach ($items as $itemData) { |
||
72 | $originalContent = $itemData['content']; |
||
73 | if (!empty($originalContent)) { |
||
74 | $updatedContent = $this->replaceURLParametersInContent($originalContent, $connection); |
||
75 | if ($originalContent !== $updatedContent) { |
||
76 | $sql = 'UPDATE c_course_description SET content = :newContent WHERE iid = :id'; |
||
77 | $params = [ |
||
78 | 'newContent' => $updatedContent, |
||
79 | 'id' => $itemData['iid'], |
||
80 | ]; |
||
81 | $connection->executeQuery($sql, $params); |
||
82 | error_log('Updated c_course_description cid ='.$courseId); |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | // Quiz |
||
89 | $sql = "SELECT * FROM c_quiz WHERE c_id = {$courseId} ORDER BY iid"; |
||
90 | $result = $connection->executeQuery($sql); |
||
91 | $items = $result->fetchAllAssociative(); |
||
92 | if (!empty($items)) { |
||
93 | foreach ($items as $itemData) { |
||
94 | $originalDescription = $itemData['description']; |
||
95 | if (!empty($originalDescription)) { |
||
96 | $updatedDescription = $this->replaceURLParametersInContent($originalDescription, $connection); |
||
97 | if ($originalDescription !== $updatedDescription) { |
||
98 | $sql = 'UPDATE c_quiz SET description = :newDescription WHERE iid = :id'; |
||
99 | $params = [ |
||
100 | 'newDescription' => $updatedDescription, |
||
101 | 'id' => $itemData['iid'], |
||
102 | ]; |
||
103 | $connection->executeQuery($sql, $params); |
||
104 | error_log('Updated c_quiz cid ='.$courseId); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | $originalText = $itemData['text_when_finished']; |
||
109 | if (!empty($originalText)) { |
||
110 | $updatedText = $this->replaceURLParametersInContent($originalText, $connection); |
||
111 | if ($originalText !== $updatedText) { |
||
112 | $sql = 'UPDATE c_quiz SET text_when_finished = :newText WHERE iid = :id'; |
||
113 | $params = [ |
||
114 | 'newText' => $updatedText, |
||
115 | 'id' => $itemData['iid'], |
||
116 | ]; |
||
117 | $connection->executeQuery($sql, $params); |
||
118 | error_log('Updated c_quiz text_when_finished cid ='.$courseId); |
||
119 | } |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | |||
124 | // Quiz question |
||
125 | $sql = "SELECT * FROM c_quiz_question WHERE c_id = {$courseId} ORDER BY iid"; |
||
126 | $result = $connection->executeQuery($sql); |
||
127 | $items = $result->fetchAllAssociative(); |
||
128 | if (!empty($items)) { |
||
129 | foreach ($items as $itemData) { |
||
130 | $originalDescription = $itemData['description']; |
||
131 | if (!empty($originalDescription)) { |
||
132 | $updatedDescription = $this->replaceURLParametersInContent($originalDescription, $connection); |
||
133 | if ($originalDescription !== $updatedDescription) { |
||
134 | $sql = 'UPDATE c_quiz_question SET description = :newDescription WHERE iid = :id'; |
||
135 | $params = [ |
||
136 | 'newDescription' => $updatedDescription, |
||
137 | 'id' => $itemData['iid'], |
||
138 | ]; |
||
139 | $connection->executeQuery($sql, $params); |
||
140 | error_log('Updated c_quiz_question cid ='.$courseId); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | $originalQuestion = $itemData['question']; |
||
145 | if (!empty($originalQuestion)) { |
||
146 | $updatedQuestion = $this->replaceURLParametersInContent($originalQuestion, $connection); |
||
147 | if ($originalQuestion !== $updatedQuestion) { |
||
148 | $sql = 'UPDATE c_quiz_question SET question = :newQuestion WHERE iid = :id'; |
||
149 | $params = [ |
||
150 | 'newQuestion' => $updatedQuestion, |
||
151 | 'id' => $itemData['iid'], |
||
152 | ]; |
||
153 | $connection->executeQuery($sql, $params); |
||
154 | error_log('Updated c_quiz_question question cid ='.$courseId); |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | |||
160 | // Quiz answer |
||
161 | $sql = "SELECT * FROM c_quiz_answer WHERE c_id = {$courseId} ORDER BY iid"; |
||
162 | $result = $connection->executeQuery($sql); |
||
163 | $items = $result->fetchAllAssociative(); |
||
164 | if (!empty($items)) { |
||
165 | foreach ($items as $itemData) { |
||
166 | $originalAnswer = $itemData['answer']; |
||
167 | if (!empty($originalAnswer)) { |
||
168 | $updatedAnswer = $this->replaceURLParametersInContent($originalAnswer, $connection); |
||
169 | if ($originalAnswer !== $updatedAnswer) { |
||
170 | $sql = 'UPDATE c_quiz_answer SET answer = :newAnswer WHERE iid = :id'; |
||
171 | $params = [ |
||
172 | 'newAnswer' => $updatedAnswer, |
||
173 | 'id' => $itemData['iid'], |
||
174 | ]; |
||
175 | $connection->executeQuery($sql, $params); |
||
176 | error_log('Updated c_quiz_answer cid ='.$courseId); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | $originalComment = $itemData['comment']; |
||
181 | if (!empty($originalComment)) { |
||
182 | $updatedComment = $this->replaceURLParametersInContent($originalComment, $connection); |
||
183 | if ($originalComment !== $updatedComment) { |
||
184 | $sql = 'UPDATE c_quiz_answer SET comment = :newComment WHERE iid = :id'; |
||
185 | $params = [ |
||
186 | 'newComment' => $updatedComment, |
||
187 | 'id' => $itemData['iid'], |
||
188 | ]; |
||
189 | $connection->executeQuery($sql, $params); |
||
190 | error_log('Updated c_quiz_answer comment cid ='.$courseId); |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | |||
196 | // Student publication |
||
197 | $sql = "SELECT * FROM c_student_publication WHERE c_id = {$courseId} ORDER BY iid"; |
||
198 | $result = $connection->executeQuery($sql); |
||
199 | $items = $result->fetchAllAssociative(); |
||
200 | if (!empty($items)) { |
||
201 | foreach ($items as $itemData) { |
||
202 | $originalWorkDescription = $itemData['description']; |
||
203 | if (!empty($originalWorkDescription)) { |
||
204 | $updatedWorkDescription = $this->replaceURLParametersInContent($originalWorkDescription, $connection); |
||
205 | if ($originalWorkDescription !== $updatedWorkDescription) { |
||
206 | $sql = 'UPDATE c_student_publication SET description = :newDescription WHERE iid = :id'; |
||
207 | $params = [ |
||
208 | 'newDescription' => $updatedWorkDescription, |
||
209 | 'id' => $itemData['iid'], |
||
210 | ]; |
||
211 | $connection->executeQuery($sql, $params); |
||
212 | error_log('Updated c_student_publication cid ='.$courseId); |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 | } |
||
217 | |||
218 | // Student publication comment |
||
219 | $sql = "SELECT * FROM c_student_publication_comment WHERE c_id = {$courseId} ORDER BY iid"; |
||
220 | $result = $connection->executeQuery($sql); |
||
221 | $items = $result->fetchAllAssociative(); |
||
222 | if (!empty($items)) { |
||
223 | foreach ($items as $itemData) { |
||
224 | $originalWorkComment = $itemData['comment']; |
||
225 | if (!empty($originalWorkComment)) { |
||
226 | $updatedWorkComment = $this->replaceURLParametersInContent($originalWorkComment, $connection); |
||
227 | if ($originalWorkComment !== $updatedWorkComment) { |
||
228 | $sql = 'UPDATE c_student_publication_comment SET comment = :newComment WHERE iid = :id'; |
||
229 | $params = [ |
||
230 | 'newComment' => $updatedWorkComment, |
||
231 | 'id' => $itemData['iid'], |
||
232 | ]; |
||
233 | $connection->executeQuery($sql, $params); |
||
234 | error_log('Updated c_student_publication_comment cid ='.$courseId); |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | } |
||
239 | |||
240 | // Forum category |
||
241 | $sql = "SELECT * FROM c_forum_category WHERE c_id = {$courseId} ORDER BY iid"; |
||
242 | $result = $connection->executeQuery($sql); |
||
243 | $items = $result->fetchAllAssociative(); |
||
244 | if (!empty($items)) { |
||
245 | foreach ($items as $itemData) { |
||
246 | $originalCatComment = $itemData['cat_comment']; |
||
247 | if (!empty($originalCatComment)) { |
||
248 | $updatedCatComment = $this->replaceURLParametersInContent($originalCatComment, $connection); |
||
249 | if ($originalCatComment !== $updatedCatComment) { |
||
250 | $sql = 'UPDATE c_forum_category SET cat_comment = :newComment WHERE iid = :id'; |
||
251 | $params = [ |
||
252 | 'newComment' => $updatedCatComment, |
||
253 | 'id' => $itemData['iid'], |
||
254 | ]; |
||
255 | $connection->executeQuery($sql, $params); |
||
256 | error_log('Updated c_forum_category cid ='.$courseId); |
||
257 | } |
||
258 | } |
||
259 | } |
||
260 | } |
||
261 | |||
262 | // Forum |
||
263 | $sql = "SELECT * FROM c_forum_forum WHERE c_id = {$courseId} ORDER BY iid"; |
||
264 | $result = $connection->executeQuery($sql); |
||
265 | $items = $result->fetchAllAssociative(); |
||
266 | if (!empty($items)) { |
||
267 | foreach ($items as $itemData) { |
||
268 | $originalForumComment = $itemData['forum_comment']; |
||
269 | if (!empty($originalForumComment)) { |
||
270 | $updatedForumComment = $this->replaceURLParametersInContent($originalForumComment, $connection); |
||
271 | if ($originalForumComment !== $updatedForumComment) { |
||
272 | $sql = 'UPDATE c_forum_forum SET forum_comment = :newComment WHERE iid = :id'; |
||
273 | $params = [ |
||
274 | 'newComment' => $updatedForumComment, |
||
275 | 'id' => $itemData['iid'], |
||
276 | ]; |
||
277 | $connection->executeQuery($sql, $params); |
||
278 | error_log('Updated c_forum_forum cid ='.$courseId); |
||
279 | } |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | |||
284 | // Forum post |
||
285 | $sql = "SELECT * FROM c_forum_post WHERE c_id = {$courseId} ORDER BY iid"; |
||
286 | $result = $connection->executeQuery($sql); |
||
287 | $items = $result->fetchAllAssociative(); |
||
288 | if (!empty($items)) { |
||
289 | foreach ($items as $itemData) { |
||
290 | $originalPostText = $itemData['post_text']; |
||
291 | if (!empty($originalPostText)) { |
||
292 | $updatedPostText = $this->replaceURLParametersInContent($originalPostText, $connection); |
||
293 | if ($originalPostText !== $updatedPostText) { |
||
294 | $sql = 'UPDATE c_forum_post SET post_text = :newText WHERE iid = :id'; |
||
295 | $params = [ |
||
296 | 'newText' => $updatedPostText, |
||
297 | 'id' => $itemData['iid'], |
||
298 | ]; |
||
299 | $connection->executeQuery($sql, $params); |
||
300 | error_log('Updated c_forum_post cid ='.$courseId); |
||
301 | } |
||
302 | } |
||
303 | } |
||
304 | } |
||
305 | |||
306 | // Glossary |
||
307 | $sql = "SELECT * FROM c_glossary WHERE c_id = {$courseId} ORDER BY iid"; |
||
308 | $result = $connection->executeQuery($sql); |
||
309 | $items = $result->fetchAllAssociative(); |
||
310 | if (!empty($items)) { |
||
311 | foreach ($items as $itemData) { |
||
312 | $originalGlossaryDescription = $itemData['description']; |
||
313 | if (!empty($originalGlossaryDescription)) { |
||
314 | $updatedGlossaryDescription = $this->replaceURLParametersInContent($originalGlossaryDescription, $connection); |
||
315 | if ($originalGlossaryDescription !== $updatedGlossaryDescription) { |
||
316 | $sql = 'UPDATE c_glossary SET description = :newDescription WHERE iid = :id'; |
||
317 | $params = [ |
||
318 | 'newDescription' => $updatedGlossaryDescription, |
||
319 | 'id' => $itemData['iid'], |
||
320 | ]; |
||
321 | $connection->executeQuery($sql, $params); |
||
322 | error_log('Updated c_glossary cid ='.$courseId); |
||
323 | } |
||
324 | } |
||
325 | } |
||
326 | } |
||
327 | |||
328 | // Survey |
||
329 | $sql = "SELECT * FROM c_survey WHERE c_id = {$courseId} ORDER BY iid"; |
||
330 | $result = $connection->executeQuery($sql); |
||
331 | $items = $result->fetchAllAssociative(); |
||
332 | if (!empty($items)) { |
||
333 | foreach ($items as $itemData) { |
||
334 | $originalSurveyTitle = $itemData['title']; |
||
335 | if (!empty($originalSurveyTitle)) { |
||
336 | $updatedSurveyTitle = $this->replaceURLParametersInContent($originalSurveyTitle, $connection); |
||
337 | if ($originalSurveyTitle !== $updatedSurveyTitle) { |
||
338 | $sql = 'UPDATE c_survey SET title = :newTitle WHERE iid = :id'; |
||
339 | $params = [ |
||
340 | 'newTitle' => $updatedSurveyTitle, |
||
341 | 'id' => $itemData['iid'], |
||
342 | ]; |
||
343 | $connection->executeQuery($sql, $params); |
||
344 | error_log('Updated c_survey cid ='.$courseId); |
||
345 | } |
||
346 | } |
||
347 | |||
348 | $originalSurveySubTitle = $itemData['subtitle']; |
||
349 | if (!empty($originalSurveySubTitle)) { |
||
350 | $updatedSurveySubTitle = $this->replaceURLParametersInContent($originalSurveySubTitle, $connection); |
||
351 | if ($originalSurveySubTitle !== $updatedSurveySubTitle) { |
||
352 | $sql = 'UPDATE c_survey SET subtitle = :newSubtitle WHERE iid = :id'; |
||
353 | $params = [ |
||
354 | 'newSubtitle' => $updatedSurveySubTitle, |
||
355 | 'id' => $itemData['iid'], |
||
356 | ]; |
||
357 | $connection->executeQuery($sql, $params); |
||
358 | error_log('Updated c_survey subtitle cid ='.$courseId); |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | } |
||
363 | |||
364 | // Survey question |
||
365 | $sql = "SELECT * FROM c_survey_question WHERE c_id = {$courseId} ORDER BY iid"; |
||
366 | $result = $connection->executeQuery($sql); |
||
367 | $items = $result->fetchAllAssociative(); |
||
368 | if (!empty($items)) { |
||
369 | foreach ($items as $itemData) { |
||
370 | $originalSurveyQuestion = $itemData['survey_question']; |
||
371 | if (!empty($originalSurveyQuestion)) { |
||
372 | $updatedSurveyQuestion = $this->replaceURLParametersInContent($originalSurveyQuestion, $connection); |
||
373 | if ($originalSurveyQuestion !== $updatedSurveyQuestion) { |
||
374 | $sql = 'UPDATE c_survey_question SET survey_question = :newQuestion WHERE iid = :id'; |
||
375 | $params = [ |
||
376 | 'newQuestion' => $updatedSurveyQuestion, |
||
377 | 'id' => $itemData['iid'], |
||
378 | ]; |
||
379 | $connection->executeQuery($sql, $params); |
||
380 | error_log('Updated c_survey_question cid ='.$courseId); |
||
381 | } |
||
382 | } |
||
383 | |||
384 | $originalSurveyQuestionComment = $itemData['survey_question_comment']; |
||
385 | if (!empty($originalSurveyQuestionComment)) { |
||
386 | $updatedSurveyQuestionComment = $this->replaceURLParametersInContent($originalSurveyQuestionComment, $connection); |
||
387 | if ($originalSurveyQuestionComment !== $updatedSurveyQuestionComment) { |
||
388 | $sql = 'UPDATE c_survey_question SET survey_question_comment = :newComment WHERE iid = :id'; |
||
389 | $params = [ |
||
390 | 'newComment' => $updatedSurveyQuestionComment, |
||
391 | 'id' => $itemData['iid'], |
||
392 | ]; |
||
393 | $connection->executeQuery($sql, $params); |
||
394 | error_log('Updated c_survey_question survey_question_comment cid ='.$courseId); |
||
395 | } |
||
396 | } |
||
397 | } |
||
398 | } |
||
399 | |||
400 | // Survey question option |
||
401 | $sql = "SELECT * FROM c_survey_question_option WHERE c_id = {$courseId} ORDER BY iid"; |
||
402 | $result = $connection->executeQuery($sql); |
||
403 | $items = $result->fetchAllAssociative(); |
||
404 | if (!empty($items)) { |
||
405 | foreach ($items as $itemData) { |
||
406 | $originalOptionText = $itemData['option_text']; |
||
407 | if (!empty($originalOptionText)) { |
||
408 | $updatedOptionText = $this->replaceURLParametersInContent($originalOptionText, $connection); |
||
409 | if ($originalOptionText !== $updatedOptionText) { |
||
410 | $sql = 'UPDATE c_survey_question_option SET option_text = :newText WHERE iid = :id'; |
||
411 | $params = [ |
||
412 | 'newText' => $updatedOptionText, |
||
413 | 'id' => $itemData['iid'], |
||
414 | ]; |
||
415 | $connection->executeQuery($sql, $params); |
||
416 | error_log('Updated c_survey_question_option cid ='.$courseId); |
||
417 | } |
||
470 |