Index: trunk/extensions/EducationProgram/maintenance/importWEPFromDB.php |
— | — | @@ -171,35 +171,44 @@ |
172 | 172 | $course->course_startdate = str_replace( '-', '', $course->course_startdate ); |
173 | 173 | $course->course_enddate = str_replace( '-', '', $course->course_enddate ); |
174 | 174 | |
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 ); |
188 | 178 | } |
| 179 | + } |
| 180 | + else { |
| 181 | + $this->msg( "\t ERROR: Failed to insert course '$name'. Linked org does not exist!\n" ); |
| 182 | + } |
| 183 | + } |
| 184 | + } |
189 | 185 | |
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 | + ); |
194 | 196 | |
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; |
203 | 199 | } |
| 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 | + } |
204 | 213 | } |
205 | 214 | |
206 | 215 | /** |