Completed
Push — 1.10.x ( 2635b5...f0080b )
by Yannick
165:55 queued 120:08
created

Version20151101082300::up()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 274
Code Lines 221

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 221
nc 1
nop 1
dl 0
loc 274
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Application\Migrations\Schema\V110;
5
6
use Application\Migrations\AbstractMigrationChamilo;
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\DBAL\Types\Type;
9
10
/**
11
 * Calendar color
12
 */
13
class Version20151101082300 extends AbstractMigrationChamilo
14
{
15
    /**
16
     * @param Schema $schema
17
     */
18
    public function up(Schema $schema)
19
    {
20
        $accessUrl = $schema->getTable('access_url');
21
        $accessUrl->getColumn('id')->setUnsigned(false);
22
23
        $accessUrlRelCourse = $schema->getTable('access_url_rel_course');
24
        $accessUrlRelCourse->getColumn('access_url_id')->setUnsigned(false);
25
        $accessUrlRelCourse->addForeignKeyConstraint('access_url', ['access_url_id'], ['id']);
26
        $accessUrlRelCourse->addForeignKeyConstraint('course', ['c_id'], ['id']);
27
28
        $schema->renameTable('class', 'class_item');
29
30
        $classUser = $schema->getTable('class_user');
31
        $classUser->getColumn('class_id')->setUnsigned(false);
32
        $classUser->getColumn('user_id')->setUnsigned(false);
33
34
        $course = $schema->getTable('course');
35
        $course->getColumn('course_type_id')->setUnsigned(false);
36
        $course->addForeignKeyConstraint('room', ['room_id'], ['id']);
37
38
        $courseRelClass = $schema->getTable('course_rel_class');
39
        $courseRelClass->getColumn('class_id')->setUnsigned(false)->setType(Type::getType(Type::INTEGER));
40
41
        $courseRelUser = $schema->getTable('course_rel_user');
42
        $courseRelUser->addForeignKeyConstraint('course', ['c_id'], ['id']);
43
        $courseRelUser->addForeignKeyConstraint('user', ['user_id'], ['id']);
44
45
        $courseType = $schema->getTable('course_type');
46
        $courseType->getColumn('id')->setUnsigned(false);
47
48
        $schema->getTable('c_announcement')->addIndex(['c_id']);
49
        $schema->getTable('c_announcement_attachment')->addIndex(['c_id']);
50
        $schema->getTable('c_attendance')->addIndex(['c_id']);
51
        $schema->getTable('c_attendance_calendar')->addIndex(['c_id']);
52
53
        $cAttendanceCalendarRelGroup = $schema->getTable('c_attendance_calendar_rel_group');
54
        $cAttendanceCalendarRelGroup->addIndex(['c_id']);
55
        $cAttendanceCalendarRelGroup->addIndex(['group_id']);
56
57
        $schema->getTable('c_attendance_result')->addIndex(['c_id']);
58
59
        $cAttendanceSheet = $schema->getTable('c_attendance_sheet');
60
        $cAttendanceSheet->addIndex(['c_id']);
61
        $cAttendanceSheet->addIndex(['user_id']);
62
63
        $schema->getTable('c_attendance_sheet_log')->addIndex(['c_id']);
64
        $schema->getTable('c_blog')->addIndex(['c_id']);
65
        $schema->getTable('c_blog_attachment')->addIndex(['c_id']);
66
        $schema->getTable('c_blog_comment')->addIndex(['c_id']);
67
        $schema->getTable('c_blog_post')->addIndex(['c_id']);
68
        $schema->getTable('c_blog_rating')->addIndex(['c_id']);
69
70
        $cBlogRelUser = $schema->getTable('c_blog_rel_user');
71
        $cBlogRelUser->getColumn('blog_id')->setUnsigned(false);
72
        $cBlogRelUser->getColumn('user_id')->setUnsigned(false);
73
        $cBlogRelUser->addIndex(['c_id']);
74
75
        $schema->getTable('c_blog_task')->addIndex(['c_id']);
76
77
        $cBlogTaskRelUser = $schema->getTable('c_blog_task_rel_user');
78
        $cBlogTaskRelUser->getColumn('blog_id')->setUnsigned(false);
79
        $cBlogTaskRelUser->getColumn('user_id')->setUnsigned(false);
80
        $cBlogTaskRelUser->getColumn('task_id')->setUnsigned(false);
81
        $cBlogTaskRelUser->addIndex(['c_id']);
82
        $cBlogTaskRelUser->addIndex(['user_id']);
83
        $cBlogTaskRelUser->addIndex(['task_id']);
84
85
        $cCalendarEvent = $schema->getTable('c_calendar_event');
86
        $cCalendarEvent->addIndex(['c_id']);
87
88
        $schema->getTable('c_calendar_event_attachment')->addIndex(['c_id']);
89
        $schema->getTable('c_calendar_event_repeat')->addIndex(['c_id']);
90
        $schema->getTable('c_calendar_event_repeat_not')->addIndex(['c_id']);
91
92
        $cChatConnected = $schema->getTable('c_chat_connected');
93
        $cChatConnected->addIndex(['c_id']);
94
        $cChatConnected->addIndex(['user_id']);
95
96
        $schema->getTable('c_course_setting')->addIndex(['c_id']);
97
        $schema->getTable('c_document')->addIndex(['c_id']);
98
        $schema->getTable('c_dropbox_category')->addIndex(['c_id']);
99
        $schema->getTable('c_dropbox_feedback')->addIndex(['c_id']);
100
        $schema->getTable('c_dropbox_file')->addIndex(['c_id']);
101
102
        $cDropboxPerson = $schema->getTable('c_dropbox_person');
103
        $cDropboxPerson->addIndex(['c_id']);
104
        $cDropboxPerson->addIndex(['user_id']);
105
106
        $cDropboxPost = $schema->getTable('c_dropbox_post');
107
        $cDropboxPost->addIndex(['c_id']);
108
        $cDropboxPost->addIndex(['dest_user_id']);
109
110
        $schema->getTable('c_forum_attachment')->addIndex(['c_id']);
111
        $schema->getTable('c_forum_category')->addIndex(['c_id']);
112
        $schema->getTable('c_forum_forum')->addIndex(['c_id']);
113
114
        $cForumMailcue = $schema->getTable('c_forum_mailcue');
115
        $cForumMailcue->addIndex(['c_id']);
116
        $cForumMailcue->addIndex(['thread_id']);
117
        $cForumMailcue->addIndex(['user_id']);
118
        $cForumMailcue->addIndex(['post_id']);
119
120
        $cForumNotification = $schema->getTable('c_forum_notification');
121
        $cForumNotification->addIndex(['c_id']);
122
        $cForumNotification->addIndex(['thread_id']);
123
        $cForumNotification->addIndex(['post_id']);
124
125
        $schema->getTable('c_forum_post')->addIndex(['c_id']);
126
        $schema->getTable('c_forum_thread')->addIndex(['c_id']);
127
        $schema->getTable('c_forum_thread_qualify')->addIndex(['c_id']);
128
        $schema->getTable('c_forum_thread_qualify_log')->addIndex(['c_id']);
129
        $schema->getTable('c_glossary')->addIndex(['c_id']);
130
        $schema->getTable('c_group_category')->addIndex(['c_id']);
131
        $schema->getTable('c_group_info')->addIndex(['c_id']);
132
        $schema->getTable('c_group_rel_tutor')->addIndex(['c_id']);
133
134
        $schema->getTable('c_group_rel_user')->addIndex(['c_id']);
135
        $schema->getTable('c_link')->addIndex(['c_id']);
136
        $schema->getTable('c_link_category')->addIndex(['c_id']);
137
        $schema->getTable('c_lp')->addIndex(['c_id']);
138
        $schema->getTable('c_lp_category')->addIndex(['c_id']);
139
        $schema->getTable('c_lp_item')->addIndex(['c_id']);
140
        $schema->getTable('c_lp_item_view')->addIndex(['c_id']);
141
        $schema->getTable('c_lp_iv_interaction')->addIndex(['c_id']);
142
        $schema->getTable('c_lp_iv_objective')->addIndex(['c_id']);
143
        $schema->getTable('c_lp_view')->addIndex(['c_id']);
144
        $schema->getTable('c_notebook')->addIndex(['c_id']);
145
        $schema->getTable('c_online_connected')->addIndex(['c_id']);
146
        $schema->getTable('c_online_link')->addIndex(['c_id']);
147
        $schema->getTable('c_permission_group')->addIndex(['c_id']);
148
        $schema->getTable('c_permission_task')->addIndex(['c_id']);
149
        $schema->getTable('c_permission_user')->addIndex(['c_id']);
150
        $schema->getTable('c_quiz')->addIndex(['c_id']);
151
        $schema->getTable('c_quiz_answer')->addIndex(['c_id']);
152
        $schema->getTable('c_quiz_question')->addIndex(['c_id']);
153
        $schema->getTable('c_quiz_question_category')->addIndex(['c_id']);
154
        $schema->getTable('c_quiz_question_option')->addIndex(['c_id']);
155
        $schema->getTable('c_quiz_question_rel_category')->addIndex(['c_id']);
156
157
        $cQuizRelQuestion = $schema->getTable('c_quiz_rel_question');
158
        $cQuizRelQuestion->addIndex(['c_id']);
159
        $cQuizRelQuestion->addIndex(['question_id']);
160
        $cQuizRelQuestion->addIndex(['exercice_id']);
161
162
        $schema->getTable('c_resource')->addIndex(['c_id']);
163
164
        $schema->getTable('c_role')->addIndex(['c_id']);
165
166
        $cRoleGroup = $schema->getTable('c_role_group');
167
        $cRoleGroup->addIndex(['c_id']);
168
        $cRoleGroup->addIndex(['group_id']);
169
170
        $cRolePermissions = $schema->getTable('c_role_permissions');
171
        $cRolePermissions->addIndex(['c_id']);
172
        $cRolePermissions->addIndex(['role_id']);
173
174
        $cRoleUser = $schema->getTable('c_role_user');
175
        $cRoleUser->addIndex(['c_id']);
176
        $cRoleUser->addIndex(['user_id']);
177
178
        $schema->getTable('c_student_publication')->addIndex(['c_id']);
179
        $schema->getTable('c_student_publication_assignment')->addIndex(['c_id']);
180
181
        $cStudentPublicationComment = $schema->getTable('c_student_publication_comment');
182
        $cStudentPublicationComment->addIndex(['c_id']);
183
        $cStudentPublicationComment->addIndex(['user_id']);
184
        $cStudentPublicationComment->addIndex(['work_id']);
185
186
        $cStudentPublicationComment = $schema->getTable('c_student_publication_rel_document');
187
        $cStudentPublicationComment->addIndex(['c_id']);
188
        $cStudentPublicationComment->addIndex(['work_id']);
189
        $cStudentPublicationComment->addIndex(['document_id']);
190
191
        $cStudentPublicationComment = $schema->getTable('c_student_publication_rel_user');
192
        $cStudentPublicationComment->addIndex(['c_id']);
193
        $cStudentPublicationComment->addIndex(['work_id']);
194
        $cStudentPublicationComment->addIndex(['user_id']);
195
196
        $schema->getTable('c_survey')->addIndex(['c_id']);
197
        $schema->getTable('c_survey_answer')->addIndex(['c_id']);
198
        $schema->getTable('c_survey_group')->addIndex(['c_id']);
199
        $schema->getTable('c_survey_invitation')->addIndex(['c_id']);
200
        $schema->getTable('c_survey_question')->addIndex(['c_id']);
201
        $schema->getTable('c_survey_question_option')->addIndex(['c_id']);
202
        $schema->getTable('c_thematic')->addIndex(['c_id']);
203
        $schema->getTable('c_thematic_advance')->addIndex(['c_id']);
204
        $schema->getTable('c_thematic_plan')->addIndex(['c_id']);
205
        $schema->getTable('c_tool')->addIndex(['c_id']);
206
        $schema->getTable('c_tool_intro')->addIndex(['c_id']);
207
        $schema->getTable('c_userinfo_content')->addIndex(['c_id']);
208
        $schema->getTable('c_userinfo_def')->addIndex(['c_id']);
209
        $schema->getTable('c_wiki')->addIndex(['c_id']);
210
        $schema->getTable('c_wiki_conf')->addIndex(['c_id']);
211
        $schema->getTable('c_wiki_discuss')->addIndex(['c_id']);
212
213
        $cWikiMailcue = $schema->getTable('c_wiki_mailcue');
214
        $cWikiMailcue->addIndex(['c_id']);
215
        $cWikiMailcue->addIndex(['user_id']);
216
217
        $schema->getTable('extra_field_values')->addForeignKeyConstraint('extra_field', ['field_id'], ['id']);
218
219
        $session = $schema->getTable('session');
220
        $session->getColumn('id_coach')->setUnsigned(false);
221
        $session->addIndex(['session_category_id']);
222
        $session->addIndex(['id_coach']);
223
        $session->addForeignKeyConstraint('session_category', ['session_category_id'], ['id']);
224
        $session->addForeignKeyConstraint('user', ['id_coach'], ['id']);
225
226
        $sessionCategory = $schema->getTable('session_category');
227
        $sessionCategory->addIndex(['access_url_id']);
228
        $sessionCategory->addForeignKeyConstraint('access_url', ['access_url_id'], ['id']);
229
230
        $sessionRelCourse = $schema->getTable('session_rel_course');
231
        $sessionRelCourse->dropColumn('course_code');
232
        $sessionRelCourse->addColumn('id', Type::INTEGER)->setAutoincrement(true);
233
        $sessionRelCourse->getColumn('c_id')->setUnsigned(false);
234
        $sessionRelCourse->setPrimaryKey(['id']);
235
        $sessionRelCourse->addIndex(['c_id']);
236
        $sessionRelCourse->addIndex(['session_id']);
237
        $sessionRelCourse->addForeignKeyConstraint('course', ['c_id'], ['id']);
238
        $sessionRelCourse->addForeignKeyConstraint('session', ['session_id'], ['id']);
239
240
        $sessionRelCourseRelUser = $schema->getTable('session_rel_course_rel_user');
241
        $sessionRelCourseRelUser->dropColumn('course_code');
242
        $sessionRelCourseRelUser->addColumn('id', Type::INTEGER)->setAutoincrement(true);
243
        $sessionRelCourseRelUser->getColumn('c_id')->setUnsigned(false);
244
        $sessionRelCourseRelUser->setPrimaryKey(['id']);
245
        $sessionRelCourseRelUser->addIndex(['c_id']);
246
        $sessionRelCourseRelUser->addIndex(['session_id']);
247
        $sessionRelCourseRelUser->addForeignKeyConstraint('course', ['c_id'], ['id']);
248
        $sessionRelCourseRelUser->addForeignKeyConstraint('session', ['session_id'], ['id']);
249
        $sessionRelCourseRelUser->addForeignKeyConstraint('user', ['user_id'], ['id']);
250
251
        $sessionRelUser = $schema->getTable('session_rel_user');
252
        $sessionRelUser->addColumn('moved_to', Type::INTEGER)->setNotnull(false);
253
        $sessionRelUser->addColumn('moved_status', Type::INTEGER)->setNotnull(false);
254
        $sessionRelUser->addColumn('moved_at', Type::DATETIME)->setNotnull(false);
255
256
        $sessionRelUser->addIndex(['session_id']);
257
        $sessionRelUser->addIndex(['user_id']);
258
        $sessionRelUser->addIndex(['user_id', 'moved_to']);
259
        $sessionRelUser->addForeignKeyConstraint('user', ['user_id'], ['id']);
260
        $sessionRelUser->addForeignKeyConstraint('session', ['session_id'], ['id']);
261
262
        $settingsCurrent = $schema->getTable('settings_current');
263
        $settingsCurrent->addUniqueIndex(['variable', 'subkey', 'access_url']);
264
265
        $settingsCurrent = $schema->getTable('settings_options');
266
        $settingsCurrent->dropIndex('id');
267
        $settingsCurrent->addUniqueIndex(['variable', 'value']);
268
269
        $schema->getTable('track_e_access')->addIndex(['c_id']);
270
        $schema->getTable('track_e_attempt')->addIndex(['c_id']);
271
        $schema->getTable('track_e_course_access')->addIndex(['c_id']);
272
273
        $trackEDefault = $schema->getTable('track_e_default');
274
        $trackEDefault->addIndex(['c_id']);
275
        $trackEDefault->addIndex(['session_id']);
276
277
        $schema->getTable('track_e_downloads')->addIndex(['c_id']);
278
        $schema->getTable('track_e_exercises')->addIndex(['c_id']);
279
        $schema->getTable('track_e_hotpotatoes')->addIndex(['c_id']);
280
        $schema->getTable('track_e_lastaccess')->addIndex(['c_id']);
281
        $schema->getTable('track_e_links')->addIndex(['c_id']);
282
        $schema->getTable('track_e_online')->addIndex(['c_id']);
283
        $schema->getTable('track_e_uploads')->addIndex(['c_id']);
284
        $schema->getTable('user')->addUniqueIndex(['username_canonical']);
285
286
        $usergroupRelUSer = $schema->getTable('usergroup_rel_user');
287
        $usergroupRelUSer->addIndex(['user_id']);
288
        $usergroupRelUSer->addIndex(['usergroup_id']);
289
        $usergroupRelUSer->addForeignKeyConstraint('usergroup', ['usergroup_id'], ['id']);
290
        $usergroupRelUSer->addForeignKeyConstraint('user', ['user_id'], ['id']);
291
    }
292
293
    /**
294
     * @param Schema $schema
295
     */
296
    public function down(Schema $schema)
297
    {
298
    }
299
}
300