r111907 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111906‎ | r111907 | r111908 >
Date:02:14, 20 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed some small issues and added docs
Modified paths:
  • /trunk/extensions/EducationProgram/actions/EditCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRoleObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/maintenance/importWEPData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/maintenance/importWEPData.php
@@ -79,7 +79,14 @@
8080 echo "Import completed!\n\n";
8181 }
8282
83 - protected function insertOrgs( array $orgs ) {
 83+ /**
 84+ * Insert the orgs.
 85+ *
 86+ * @since 0.1
 87+ *
 88+ * @param array $orgs Org names as keys. Values get set to the id after insertion.
 89+ */
 90+ protected function insertOrgs( array &$orgs ) {
8491 wfGetDB( DB_MASTER )->begin();
8592
8693 foreach ( $orgs as $org => &$id ) {
@@ -98,6 +105,14 @@
99106 wfGetDB( DB_MASTER )->commit();
100107 }
101108
 109+ /**
 110+ * Insert the courses.
 111+ *
 112+ * @param array $courses
 113+ * @param array $orgs
 114+ *
 115+ * @return array Inserted courses. keys are names, values are ids
 116+ */
102117 protected function insertCourses( array $courses, array $orgs ) {
103118 $courseIds = array();
104119
@@ -125,6 +140,17 @@
126141 return $courseIds;
127142 }
128143
 144+ /**
 145+ * Insert the students.
 146+ * Create user account if none matches the name yet.
 147+ * Create student profile if none matches the user yet.
 148+ * Associate with courses.
 149+ *
 150+ * @since 0.1
 151+ *
 152+ * @param array $students Keys are names, values are arrays with course names
 153+ * @param array $courseIds Maps course names to ids
 154+ */
129155 protected function insertStudents( array $students, array $courseIds ) {
130156 foreach ( $students as $student => $courseNames ) {
131157 $name = $student;
@@ -145,15 +171,7 @@
146172 else {
147173 $student = EPStudent::newFromUser( $user );
148174
149 - if ( $student === false ) {
150 - $student = new EPStudent(
151 - array(
152 - 'user_id' => $user->getId(),
153 - 'first_enroll' => wfTimestamp( TS_MW )
154 - ),
155 - true
156 - );
157 -
 175+ if ( is_null( $student->getId() ) ) {
158176 if ( !$student->save() ) {
159177 echo "Failed to insert student '$name'. (failed create student profile)\n";
160178 continue;
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php
@@ -100,8 +100,6 @@
101101 * @return array
102102 */
103103 protected function titleToNameAndTerm( $titleText ) {
104 - $term = '';
105 -
106104 $matches = array();
107105 preg_match( '/(.*)\((.*)\)/', $titleText, $matches );
108106
@@ -109,6 +107,10 @@
110108 $name = trim( $matches[1] );
111109 $term = trim( $matches[2] );
112110 }
 111+ else {
 112+ $name = $titleText;
 113+ $term = '';
 114+ }
113115
114116 return array( $name, $term );
115117 }
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php
@@ -52,7 +52,7 @@
5353 $class = $map[get_called_class()];
5454 $table = $class::singleton();
5555
56 - $userRole = $table->selectRow( null, $data );
 56+ $userRole = $table->selectRow( $fields, $data );
5757 return $userRole === false ? new static( $table, $data, true ) : $userRole;
5858 }
5959

Status & tagging log