Index: trunk/extensions/EducationProgram/maintenance/importWEPData.php |
— | — | @@ -154,9 +154,8 @@ |
155 | 155 | * @param array $courseIds Maps course names to ids |
156 | 156 | */ |
157 | 157 | protected function insertStudents( array $students, array $courseIds ) { |
158 | | - foreach ( $students as $student => $courseNames ) { |
159 | | - $name = $student; |
160 | | - $user = User::newFromName( $student ); |
| 158 | + foreach ( $students as $name => $courseNames ) { |
| 159 | + $user = User::newFromName( $name ); |
161 | 160 | |
162 | 161 | if ( $user === false ) { |
163 | 162 | echo "Failed to insert student '$name'. (invalid user name)\n"; |
— | — | @@ -184,16 +183,18 @@ |
185 | 184 | |
186 | 185 | foreach ( $courseNames as $courseName ) { |
187 | 186 | if ( array_key_exists( $courseName, $courseIds ) ) { |
188 | | - $courses[] = EPCourses::singleton()->newFromArray( array( |
189 | | - 'id' => $courseIds[$courseName], |
190 | | - 'students' => array(), |
191 | | - ) ); |
| 187 | + $revAction = new EPRevisionAction(); |
| 188 | + $revAction->setUser( $user ); |
| 189 | + $revAction->setComment( 'Import' ); |
| 190 | + |
| 191 | + $course = EPCourses::singleton()->selectRow( null, array( 'id' => $courseIds[$courseName] ) ); |
| 192 | + $course->enlistUsers( array( $user->getId() ), 'student', true, $revAction ); |
192 | 193 | } |
193 | 194 | else { |
194 | 195 | echo "Failed to associate student '$name' with course '$courseName'.\n"; |
195 | 196 | } |
196 | 197 | } |
197 | | - |
| 198 | + |
198 | 199 | if ( $student->associateWithCourses( $courses ) ) { |
199 | 200 | echo "Inserted student '$name'\t\t and associated with courses: " . str_replace( '_', ' ', implode( ', ', $courseNames ) ) . "\n"; |
200 | 201 | } |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -532,12 +532,23 @@ |
533 | 533 | * @see DBDataObject::setField() |
534 | 534 | */ |
535 | 535 | public function setField( $name, $value ) { |
536 | | - if ( $name === 'instructors' ) { |
537 | | - $this->instructors = false; |
| 536 | + switch ( $name ) { |
| 537 | + case 'mc': |
| 538 | + $value = str_replace( '_', ' ', $value ); |
| 539 | + break; |
| 540 | + case 'instructors': |
| 541 | + $this->instructors = false; |
| 542 | + break; |
| 543 | + case 'students': |
| 544 | + $this->students = false; |
| 545 | + break; |
| 546 | + case 'oas': |
| 547 | + $this->oas = false; |
| 548 | + break; |
| 549 | + case 'cas': |
| 550 | + $this->cas = false; |
| 551 | + break; |
538 | 552 | } |
539 | | - elseif ( $name === 'mc' ) { |
540 | | - $value = str_replace( '_', ' ', $value ); |
541 | | - } |
542 | 553 | |
543 | 554 | parent::setField( $name, $value ); |
544 | 555 | } |
— | — | @@ -566,21 +577,10 @@ |
567 | 578 | |
568 | 579 | $field = $roleMap[$role]; |
569 | 580 | $users = $this->getField( $field ); |
570 | | - $addedUsers = array(); |
| 581 | + $addedUsers = array_diff( (array)$newUsers, $users ); |
571 | 582 | |
572 | | - foreach ( (array)$newUsers as $userId ) { |
573 | | - if ( !is_integer( $userId ) ) { |
574 | | - throw new MWException( 'Provided user id is not an integer' ); |
575 | | - } |
576 | | - |
577 | | - if ( !in_array( $userId, $users ) ) { |
578 | | - $users[] = $userId; |
579 | | - $addedUsers[] = $userId; |
580 | | - } |
581 | | - } |
582 | | - |
583 | 583 | if ( count( $addedUsers ) > 0 ) { |
584 | | - $this->setField( $field, $users ); |
| 584 | + $this->setField( $field, array_merge( $users, $addedUsers ) ); |
585 | 585 | |
586 | 586 | $success = true; |
587 | 587 | |