Index: trunk/extensions/EducationProgram/actions/EPHistoryAction.php |
— | — | @@ -70,14 +70,8 @@ |
71 | 71 | * @param EPPageObject $object |
72 | 72 | */ |
73 | 73 | protected function displayRevisions( EPPageObject $object ) { |
74 | | - $conditions = array( |
75 | | - 'type' => get_class( $object ), |
76 | | - ); |
| 74 | + $conditions = $object->getRevisionIdentifiers(); |
77 | 75 | |
78 | | - if ( $object->hasIdField() ) { |
79 | | - $conditions['object_id'] = $object->getId(); |
80 | | - } |
81 | | - |
82 | 76 | $action = htmlspecialchars( $GLOBALS['wgScript'] ); |
83 | 77 | |
84 | 78 | $request = $this->getRequest(); |
Index: trunk/extensions/EducationProgram/includes/EPRevisions.php |
— | — | @@ -78,17 +78,15 @@ |
79 | 79 | * @return EPRevision |
80 | 80 | */ |
81 | 81 | public function newFromObject( EPRevisionedObject $object, EPRevisionAction $revAction ) { |
82 | | - $fields = array( |
83 | | - 'object_id' => $object->getId(), |
| 82 | + $fields = array_merge( $object->getRevisionIdentifiers(), array( |
84 | 83 | 'user_id' => $revAction->getUser()->getID(), |
85 | 84 | 'user_text' => $revAction->getUser()->getName(), |
86 | | - 'type' => get_class( $object ), |
87 | 85 | 'comment' => $revAction->getComment(), |
88 | 86 | 'minor_edit' => $revAction->isMinor(), |
89 | 87 | 'time' => $revAction->getTime(), |
90 | 88 | 'deleted' => $revAction->isDelete(), |
91 | 89 | 'data' => serialize( $object->toArray() ) |
92 | | - ); |
| 90 | + ) ); |
93 | 91 | |
94 | 92 | $identifier = $object->getIdentifier(); |
95 | 93 | |
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php |
— | — | @@ -276,14 +276,23 @@ |
277 | 277 | */ |
278 | 278 | public function getRevisions( array $conditions = array(), array $options = array() ) { |
279 | 279 | return EPRevisions::singleton()->select( null, array_merge( |
280 | | - array( |
281 | | - 'type' => get_called_class(), |
282 | | - 'object_id' => $this->getId(), |
283 | | - ), |
| 280 | + $this->getRevisionIdentifiers(), |
284 | 281 | $conditions |
285 | 282 | ), $options ); |
286 | 283 | } |
287 | 284 | |
| 285 | + public function getRevisionIdentifiers() { |
| 286 | + $identifiers = array( |
| 287 | + 'type' => get_class( $this->table ) |
| 288 | + ); |
| 289 | + |
| 290 | + if ( $this->hasIdField() ) { |
| 291 | + $identifiers['object_id'] = $this->getId(); |
| 292 | + } |
| 293 | + |
| 294 | + return $identifiers; |
| 295 | + } |
| 296 | + |
288 | 297 | /** |
289 | 298 | * Returns the most recently stored revision for this object |
290 | 299 | * matching the provided contions or false if there is none. |
— | — | @@ -299,10 +308,7 @@ |
300 | 309 | $options['ORDER BY'] = EPRevisions::singleton()->getPrefixedField( 'id' ) . ' DESC'; |
301 | 310 | |
302 | 311 | return EPRevisions::singleton()->selectRow( null, array_merge( |
303 | | - array( |
304 | | - 'type' => get_called_class(), |
305 | | - 'object_id' => $this->getId(), |
306 | | - ), |
| 312 | + $this->getRevisionIdentifiers(), |
307 | 313 | $conditions |
308 | 314 | ), $options ); |
309 | 315 | } |
— | — | @@ -430,5 +436,5 @@ |
431 | 437 | $revision = $this->getRevisionById( $revId ); |
432 | 438 | return $revision === false ? false : $this->undoRevision( $revision, $fields ); |
433 | 439 | } |
434 | | - |
| 440 | + |
435 | 441 | } |
Index: trunk/extensions/EducationProgram/includes/EPRevision.php |
— | — | @@ -22,6 +22,14 @@ |
23 | 23 | protected $user = false; |
24 | 24 | |
25 | 25 | /** |
| 26 | + * (non-PHPdoc) |
| 27 | + * @see DBDataObject::getTable() |
| 28 | + */ |
| 29 | + public function getTable() { |
| 30 | + return EPRevisions::singleton(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
26 | 34 | * Return the object as it was at this revision. |
27 | 35 | * |
28 | 36 | * @since 0,1 |
— | — | @@ -29,8 +37,8 @@ |
30 | 38 | * @return EPRevisionedObject |
31 | 39 | */ |
32 | 40 | public function getObject() { |
33 | | - $class = $this->getField( 'type' ) . 's'; // TODO: refactor made this suck a lot |
34 | | - return $class::singleton()->newFromArray( $this->getField( 'data' ), true ); |
| 41 | + $tableClass = $this->getField( 'type' ); |
| 42 | + return $tableClass::singleton()->newFromArray( $this->getField( 'data' ), true ); |
35 | 43 | } |
36 | 44 | |
37 | 45 | /** |
— | — | @@ -53,13 +61,13 @@ |
54 | 62 | $conditions['object_id'] = $objectId; |
55 | 63 | } |
56 | 64 | |
57 | | - $rev = EPRevision::selectRow( array( 'type', 'data' ), $conditions ); |
| 65 | + $rev = EPRevisions::singleton()->selectRow( array( 'type', 'data' ), $conditions ); |
58 | 66 | |
59 | 67 | if ( $rev === false ) { |
60 | 68 | return false; |
61 | 69 | } |
62 | 70 | else { |
63 | | - return $rev->getDataObject(); |
| 71 | + return $rev->getObject(); |
64 | 72 | } |
65 | 73 | } |
66 | 74 | |