Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php |
— | — | @@ -48,15 +48,21 @@ |
49 | 49 | $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_> |
50 | 50 | |
51 | 51 | if ( !$this->isNewPost() && !$c::hasIdentifier( $this->getTitle()->getText() ) ) { |
| 52 | + $c::displayDeletionLog( |
| 53 | + $this->getContext(), |
| 54 | + 'ep-' . strtolower( $this->getName() ) . '-deleted' |
| 55 | + ); |
| 56 | + |
52 | 57 | $name = $this->getTitle()->getText(); |
53 | | - $bracketPos = strpos( $name, '(' ); |
| 58 | + $term = ''; |
54 | 59 | |
55 | | - if ( $bracketPos !== false ) { |
56 | | - if ( $bracketPos > 0 && in_array( $name{$bracketPos - 1}, array( ' ', '_' ) ) ) { |
57 | | - $bracketPos -= 1; |
58 | | - } |
59 | | - |
60 | | - $name = substr( $name, 0, $bracketPos ); |
| 60 | + $matches = array(); |
| 61 | + |
| 62 | + preg_match( '/(.*)(\(.*\))/', $name, $matches ); |
| 63 | + |
| 64 | + if ( count( $matches ) == 3 && trim( $matches[1] ) !== '' && $matches[2] !== '' ) { |
| 65 | + $name = trim( $matches[1] ); |
| 66 | + $term = trim( $matches[2] ); |
61 | 67 | } |
62 | 68 | |
63 | 69 | EPCourse::displayAddNewRegion( |
— | — | @@ -66,12 +72,16 @@ |
67 | 73 | 'newname', |
68 | 74 | $name |
69 | 75 | ), |
70 | | - 'term' => $this->getRequest()->getText( 'newterm', '' ), |
| 76 | + 'term' => $this->getRequest()->getText( |
| 77 | + 'newterm', |
| 78 | + $term |
| 79 | + ), |
71 | 80 | ) |
72 | 81 | ); |
73 | 82 | |
74 | 83 | $this->isNew = true; |
75 | 84 | $this->getOutput()->setSubtitle( $this->getDescription() ); |
| 85 | + $this->getOutput()->setPageTitle( $this->getPageTitle() ); |
76 | 86 | |
77 | 87 | return ''; |
78 | 88 | } |
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php |
— | — | @@ -201,7 +201,7 @@ |
202 | 202 | * |
203 | 203 | * @return Success indicator |
204 | 204 | */ |
205 | | - public function loadFields( $fields = null, $override = true ) { |
| 205 | + public function loadFields( $fields = null, $override = true, $skipLoaded = false ) { |
206 | 206 | if ( is_null( $this->getId() ) ) { |
207 | 207 | return false; |
208 | 208 | } |
— | — | @@ -209,19 +209,30 @@ |
210 | 210 | if ( is_null( $fields ) ) { |
211 | 211 | $fields = array_keys( $this->getFieldTypes() ); |
212 | 212 | } |
213 | | - |
214 | | - $results = $this->rawSelect( |
215 | | - $this->getPrefixedFields( $fields ), |
216 | | - array( $this->getPrefixedField( 'id' ) => $this->getId() ), |
217 | | - array( 'LIMIT' => 1 ) |
218 | | - ); |
219 | | - |
220 | | - foreach ( $results as $result ) { |
221 | | - $this->setFields( $this->getFieldsFromDBResult( $result ), $override ); |
222 | | - return true; |
| 213 | + |
| 214 | + if ( $skipLoaded ) { |
| 215 | + $loadedFields = array_keys( $this->fields ); |
| 216 | + $fields = array_filter( $fields, function( $field ) use ( $loadedFields ) { |
| 217 | + return !in_array( $loadedFields ); |
| 218 | + } ); |
223 | 219 | } |
| 220 | + |
| 221 | + if ( count( $fields ) > 0 ) { |
| 222 | + $results = $this->rawSelect( |
| 223 | + $this->getPrefixedFields( $fields ), |
| 224 | + array( $this->getPrefixedField( 'id' ) => $this->getId() ), |
| 225 | + array( 'LIMIT' => 1 ) |
| 226 | + ); |
| 227 | + |
| 228 | + foreach ( $results as $result ) { |
| 229 | + $this->setFields( $this->getFieldsFromDBResult( $result ), $override ); |
| 230 | + return true; |
| 231 | + } |
| 232 | + |
| 233 | + return false; |
| 234 | + } |
224 | 235 | |
225 | | - return false; |
| 236 | + return true; |
226 | 237 | } |
227 | 238 | |
228 | 239 | /** |
— | — | @@ -477,16 +488,50 @@ |
478 | 489 | * @return boolean Success indicator |
479 | 490 | */ |
480 | 491 | public function remove() { |
481 | | - $success = $this->delete( array( 'id' => $this->getId() ) ); |
| 492 | + $this->beforeRemove(); |
| 493 | + |
| 494 | + $success = static::delete( array( 'id' => $this->getId() ) ); |
482 | 495 | |
483 | 496 | if ( $success ) { |
484 | | - $this->setField( 'id', null ); |
| 497 | + $this->onRemoved(); |
485 | 498 | } |
486 | 499 | |
487 | 500 | return $success; |
488 | 501 | } |
| 502 | + |
| 503 | + /** |
| 504 | + * Gets called before an object is removed from the database. |
| 505 | + * |
| 506 | + * @since 0.1 |
| 507 | + */ |
| 508 | + protected function beforeRemove() { |
| 509 | + $this->loadFields( $this->getBeforeRemoveFields(), false, true ); |
| 510 | + } |
489 | 511 | |
490 | 512 | /** |
| 513 | + * Before removal of an object happens, @see beforeRemove gets called. |
| 514 | + * This method loads the fields of which the names have been returned by this one (or all fields if null is returned). |
| 515 | + * This allows for loading info needed after removal to get rid of linked data and the like. |
| 516 | + * |
| 517 | + * @since 0.1 |
| 518 | + * |
| 519 | + * @return array|null |
| 520 | + */ |
| 521 | + protected function getBeforeRemoveFields() { |
| 522 | + return array(); |
| 523 | + } |
| 524 | + |
| 525 | + /** |
| 526 | + * Gets called after successfull removal. |
| 527 | + * Can be overriden to get rid of linked data. |
| 528 | + * |
| 529 | + * @since 0.1 |
| 530 | + */ |
| 531 | + protected function onRemoved() { |
| 532 | + $this->setField( 'id', null ); |
| 533 | + } |
| 534 | + |
| 535 | + /** |
491 | 536 | * Return the names and values of the fields. |
492 | 537 | * |
493 | 538 | * @since 0.1 |
— | — | @@ -1043,7 +1088,7 @@ |
1044 | 1089 | * |
1045 | 1090 | * @since 0.1 |
1046 | 1091 | * |
1047 | | - * @param array|null $fields |
| 1092 | + * @param array $fields |
1048 | 1093 | * @param array $conditions |
1049 | 1094 | * @param array $options |
1050 | 1095 | * @param array $joinConds |
— | — | @@ -1051,7 +1096,7 @@ |
1052 | 1097 | * |
1053 | 1098 | * @return ResultWrapper |
1054 | 1099 | */ |
1055 | | - public static function rawSelect( $fields = null, array $conditions = array(), array $options = array(), array $joinConds = array(), array $tables = null ) { |
| 1100 | + public static function rawSelect( array $fields, array $conditions = array(), array $options = array(), array $joinConds = array(), array $tables = null ) { |
1056 | 1101 | if ( is_null( $tables ) ) { |
1057 | 1102 | $tables = static::getDBTable(); |
1058 | 1103 | } |
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php |
— | — | @@ -75,7 +75,13 @@ |
76 | 76 | $value = EPCourse::getLinkFor( $value ); |
77 | 77 | break; |
78 | 78 | case 'org_id': |
79 | | - $value = EPOrg::selectRow( 'name', array( 'id' => $value ) )->getLink(); |
| 79 | + $org = EPOrg::selectRow( 'name', array( 'id' => $value ) ); |
| 80 | + |
| 81 | + // This should not happen. A course should always have an org. |
| 82 | + // But if something gets messed up somehow, just display the ID rather then throwing a fatal. |
| 83 | + if ( $org !== false ) { |
| 84 | + $value = $org->getLink(); |
| 85 | + } |
80 | 86 | break; |
81 | 87 | case 'term': |
82 | 88 | $value = htmlspecialchars( $value ); |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -154,23 +154,32 @@ |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * (non-PHPdoc) |
158 | | - * @see EPDBObject::remove() |
| 158 | + * @see EPRevisionedObject::onRemoved() |
159 | 159 | */ |
160 | | - public function remove() { |
161 | | - $id = $this->getId(); |
162 | | - $this->loadFields( array( 'name' ) ); |
163 | | - |
164 | | - $success = parent::remove(); |
165 | | - |
166 | | - if ( $success ) { |
167 | | - $success = wfGetDB( DB_MASTER )->delete( 'ep_cas_per_org', array( 'cpo_org_id' => $id ) ) && $success; |
168 | | - |
169 | | - foreach ( EPCourse::select( 'id', array( 'org_id' => $id ) ) as /* EPCourse */ $course ) { |
170 | | - $success = $course->remove() && $success; |
| 160 | + protected function onRemoved() { |
| 161 | + foreach ( EPCourse::select( null, array( 'org_id' => $this->getId() ) ) as /* EPCourse */ $course ) { |
| 162 | + $revAction = clone $this->revAction; |
| 163 | + |
| 164 | + if ( trim( $revAction->getComment() ) === '' ) { |
| 165 | + $revAction->setComment( wfMsgExt( |
| 166 | + 'ep-org-course-delete', |
| 167 | + 'parsemag', |
| 168 | + $this->getField( 'name' ) |
| 169 | + ) ); |
171 | 170 | } |
| 171 | + else { |
| 172 | + $revAction->setComment( wfMsgExt( |
| 173 | + 'ep-org-course-delete-comment', |
| 174 | + 'parsemag', |
| 175 | + $this->getField( 'name' ), |
| 176 | + $revAction->getComment() |
| 177 | + ) ); |
| 178 | + } |
| 179 | + |
| 180 | + $course->revisionedRemove( $revAction ); |
172 | 181 | } |
173 | | - |
174 | | - return $success; |
| 182 | + |
| 183 | + parent::onRemoved(); |
175 | 184 | } |
176 | 185 | |
177 | 186 | /** |
Index: trunk/extensions/EducationProgram/includes/EPPager.php |
— | — | @@ -68,7 +68,7 @@ |
69 | 69 | function formatRow( $row ) { |
70 | 70 | $c = $this->className; // Yeah, this is needed in PHP 5.3 >_> |
71 | 71 | $this->currentObject = $c::newFromDBResult( $row ); |
72 | | - |
| 72 | + |
73 | 73 | $cells = array(); |
74 | 74 | |
75 | 75 | foreach ( $this->getFieldNames() as $field => $name ) { |
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php |
— | — | @@ -191,41 +191,15 @@ |
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
195 | | - * (non-PHPdoc) |
196 | | - * @see EPDBObject::remove() |
197 | | - */ |
198 | | - public function remove() { |
199 | | - $object = clone $this; |
200 | | - $object->loadFields(); |
201 | | - |
202 | | - $success = parent::remove(); |
203 | | - |
204 | | - if ( $success ) { |
205 | | - $object->onRemoved(); |
206 | | - } |
207 | | - |
208 | | - return $success; |
209 | | - } |
210 | | - |
211 | | - /** |
212 | | - * @since 0.1 |
213 | | - * |
214 | | - * @param EPRevisionAction $revAction |
215 | | - */ |
216 | | - public function handleRemoved( EPRevisionAction $revAction ) { |
217 | | - $this->setRevisionAction( $revAction ); |
218 | | - $this->onRemoved(); |
219 | | - } |
220 | | - |
221 | | - /** |
222 | 195 | * Do logging and revision storage after a removal. |
223 | | - * The object needs to have all it's fields loaded. |
| 196 | + * @see EPDBObject::onRemoved() |
224 | 197 | * |
225 | 198 | * @since 0.1 |
226 | 199 | */ |
227 | 200 | protected function onRemoved() { |
228 | 201 | $this->storeRevision( $this ); |
229 | 202 | $this->log( 'remove' ); |
| 203 | + parent::onRemoved( $object ); |
230 | 204 | } |
231 | 205 | |
232 | 206 | public function getIdentifier() { |
— | — | @@ -261,9 +235,17 @@ |
262 | 236 | */ |
263 | 237 | public function revisionedRemove( EPRevisionAction $revAction ) { |
264 | 238 | $this->setRevisionAction( $revAction ); |
265 | | - $success = $this->remove(); |
| 239 | + $success = $this->remove(); |
266 | 240 | $this->setRevisionAction( false ); |
267 | 241 | return $success; |
268 | 242 | } |
269 | 243 | |
| 244 | + /** |
| 245 | + * (non-PHPdoc) |
| 246 | + * @see EPDBObject::getBeforeRemoveFields() |
| 247 | + */ |
| 248 | + protected function getBeforeRemoveFields() { |
| 249 | + return null; |
| 250 | + } |
| 251 | + |
270 | 252 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -250,32 +250,21 @@ |
251 | 251 | |
252 | 252 | return $success; |
253 | 253 | } |
254 | | - |
| 254 | + |
255 | 255 | /** |
256 | 256 | * (non-PHPdoc) |
257 | | - * @see EPDBObject::remove() |
| 257 | + * @see EPRevisionedObject::onRemoved() |
258 | 258 | */ |
259 | | - public function remove() { |
260 | | - $id = $this->getId(); |
261 | | - |
| 259 | + protected function onRemoved() { |
262 | 260 | if ( $this->updateSummaries ) { |
263 | | - $this->loadFields( array( 'org_id' ) ); |
264 | | - $orgId = $this->getField( 'org_id' ); |
| 261 | + EPOrg::updateSummaryFields( array( 'courses', 'students', 'active', 'instructors', 'oas', 'cas' ), array( 'id' => $this->getField( 'org_id' ) ) ); |
265 | 262 | } |
266 | 263 | |
267 | | - $success = parent::remove(); |
268 | | - |
269 | | - if ( $success && $this->updateSummaries ) { |
270 | | - EPOrg::updateSummaryFields( array( 'courses', 'students', 'active', 'instructors', 'oas', 'cas' ), array( 'id' => $orgId ) ); |
271 | | - } |
272 | | - |
273 | | - if ( $success ) { |
274 | | - $success = wfGetDB( DB_MASTER )->delete( 'ep_students_per_course', array( 'spc_course_id' => $id ) ) && $success; |
275 | | - $success = wfGetDB( DB_MASTER )->delete( 'ep_cas_per_course', array( 'cpc_course_id' => $id ) ) && $success; |
276 | | - $success = wfGetDB( DB_MASTER )->delete( 'ep_oas_per_course', array( 'opc_course_id' => $id ) ) && $success; |
277 | | - } |
278 | | - |
279 | | - return $success; |
| 264 | + wfGetDB( DB_MASTER )->delete( 'ep_students_per_course', array( 'spc_course_id' => $this->getId() ) ); |
| 265 | + wfGetDB( DB_MASTER )->delete( 'ep_cas_per_course', array( 'cpc_course_id' => $this->getId() ) ); |
| 266 | + wfGetDB( DB_MASTER )->delete( 'ep_oas_per_course', array( 'opc_course_id' => $this->getId() ) ); |
| 267 | + |
| 268 | + parent::onRemoved(); |
280 | 269 | } |
281 | 270 | |
282 | 271 | /** |
Index: trunk/extensions/EducationProgram/includes/EPPageObject.php |
— | — | @@ -103,8 +103,8 @@ |
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
| 107 | + * Delete all objects matching the provided condirions. |
107 | 108 | * |
108 | | - * |
109 | 109 | * @since 0.1 |
110 | 110 | * |
111 | 111 | * @param EPRevisionAction $revAction |
— | — | @@ -121,14 +121,10 @@ |
122 | 122 | $success = true; |
123 | 123 | |
124 | 124 | if ( count( $objects ) > 0 ) { |
125 | | - $success = static::delete( $conditions ); |
| 125 | + $revAction->setDelete( true ); |
126 | 126 | |
127 | | - if ( $success ) { |
128 | | - $revAction->setDelete( true ); |
129 | | - |
130 | | - foreach ( $objects as /* EPPageObject */ $object ) { |
131 | | - $object->handleRemoved( $revAction ); |
132 | | - } |
| 127 | + foreach ( $objects as /* EPPageObject */ $object ) { |
| 128 | + $success = $object->revisionedRemove( $revAction ) && $success; |
133 | 129 | } |
134 | 130 | } |
135 | 131 | |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -23,6 +23,8 @@ |
24 | 24 | // Misc |
25 | 25 | 'ep-item-summary' => 'Summary', |
26 | 26 | 'ep-toplink' => 'My courses', |
| 27 | + 'ep-org-course-delete-comment' => "Deleted institution $1 and all it's courses with comment $2", |
| 28 | + 'ep-org-course-delete' => "Deleted institution $1 and all it's courses", |
27 | 29 | |
28 | 30 | // Tabs |
29 | 31 | 'ep-tab-view' => 'Read', |