r114530 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114529‎ | r114530 | r114531 >
Date:16:54, 27 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some extra error handling
Modified paths:
  • /trunk/extensions/EducationProgram/maintenance/importWEPFromDB.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/maintenance/importWEPFromDB.php
@@ -171,35 +171,44 @@
172172 $course->course_startdate = str_replace( '-', '', $course->course_startdate );
173173 $course->course_enddate = str_replace( '-', '', $course->course_enddate );
174174
175 - if ( $currentId === false || $this->override ) {
176 - $data = array(
177 - 'org_id' => $this->orgIds[$course->course_university_id],
178 - 'name' => $name,
179 - 'mc' => $course->course_coursename,
180 - 'start' => $course->course_startdate . '000000',
181 - 'end' => ( $course->course_enddate === '' ? $course->course_startdate : $course->course_enddate ) . '000000',
182 - 'lang' => $course->course_language,
183 - 'term' => $term,
184 - );
185 -
186 - if ( $currentId !== false ) {
187 - $data['id'] = $currentId;
 175+ if ( array_key_exists( $course->course_university_id, $this->orgIds ) ) {
 176+ if ( $currentId === false || $this->override ) {
 177+ $this->insertCourse( $currentId, $course, $name, $term, $revAction );
188178 }
 179+ }
 180+ else {
 181+ $this->msg( "\t ERROR: Failed to insert course '$name'. Linked org does not exist!\n" );
 182+ }
 183+ }
 184+ }
189185
190 - $courseObject = $courseTable->newFromArray(
191 - $data,
192 - $currentId === false
193 - );
 186+ protected function insertCourse( $currentId, $course, $name, $term, $revAction ) {
 187+ $data = array(
 188+ 'org_id' => $this->orgIds[$course->course_university_id],
 189+ 'name' => $name,
 190+ 'mc' => $course->course_coursename,
 191+ 'start' => $course->course_startdate . '000000',
 192+ 'end' => ( $course->course_enddate === '' ? $course->course_startdate : $course->course_enddate ) . '000000',
 193+ 'lang' => $course->course_language,
 194+ 'term' => $term,
 195+ );
194196
195 - try{
196 - $courseObject->revisionedSave( $revAction );
197 - $this->courseIds[$course->course_id] = $courseObject->getId();
198 - }
199 - catch ( Exception $ex ) {
200 - $this->msg( "\t ERROR: Failed to insert course '$name'.\n" );
201 - }
202 - }
 197+ if ( $currentId !== false ) {
 198+ $data['id'] = $currentId;
203199 }
 200+
 201+ $courseObject = EPCourses::singleton()->newFromArray(
 202+ $data,
 203+ $currentId === false
 204+ );
 205+
 206+ try{
 207+ $courseObject->revisionedSave( $revAction );
 208+ $this->courseIds[$course->course_id] = $courseObject->getId();
 209+ }
 210+ catch ( Exception $ex ) {
 211+ $this->msg( "\t ERROR: Failed to insert course '$name'.\n" );
 212+ }
204213 }
205214
206215 /**

Status & tagging log