r112662 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112661‎ | r112662 | r112663 >
Date:00:33, 29 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on org undeletion
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPUndeleteAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewOrgAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgs.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionedObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/sql/AddCoursesField.sql (added) (history)
  • /trunk/extensions/EducationProgram/sql/EducationProgram.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql
@@ -16,7 +16,8 @@
1717 org_instructor_count SMALLINT unsigned NOT NULL, -- Amount of instructors
1818 org_oa_count INT unsigned NOT NULL, -- Amount of online ambassadors
1919 org_ca_count INT unsigned NOT NULL, -- Amount of campus ambassadors
20 - org_student_count INT unsigned NOT NULL -- Amount of students
 20+ org_student_count INT unsigned NOT NULL, -- Amount of students
 21+ org_courses BLOB NOT NULL -- The ids of the courses (linking ep_courses.course_id)
2122 ) /*$wgDBTableOptions*/;
2223
2324 CREATE UNIQUE INDEX /*i*/ep_org_name ON /*_*/ep_orgs (org_name);
Index: trunk/extensions/EducationProgram/sql/AddCoursesField.sql
@@ -0,0 +1,7 @@
 2+-- MySQL patch for the Education Program extension.
 3+-- Licence: GNU GPL v3+
 4+-- Author: Jeroen De Dauw < jeroendedauw@gmail.com >
 5+
 6+ALTER TABLE /*_*/ep_orgs ADD COLUMN org_courses BLOB NOT NULL;
 7+
 8+UPDATE /*_*/ep_orgs SET org_courses = 'a:0:{}'; -- Serialized empty array
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/sql/AddCoursesField.sql
___________________________________________________________________
Added: svn:eol-style
19 + native
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -26,10 +26,18 @@
2727 parent::__construct( $page, $context, EPCourses::singleton() );
2828 }
2929
 30+ /**
 31+ * (non-PHPdoc)
 32+ * @see Action::getName()
 33+ */
3034 public function getName() {
3135 return 'viewcourse';
3236 }
3337
 38+ /**
 39+ * (non-PHPdoc)
 40+ * @see EPViewAction::displayPage()
 41+ */
3442 protected function displayPage( DBDataObject $course ) {
3543 parent::displayPage( $course );
3644
@@ -205,4 +213,4 @@
206214 }
207215 }
208216
209 -}
\ No newline at end of file
 217+}
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
@@ -26,10 +26,18 @@
2727 parent::__construct( $page, $context, EPOrgs::singleton() );
2828 }
2929
 30+ /**
 31+ * (non-PHPdoc)
 32+ * @see Action::getName()
 33+ */
3034 public function getName() {
3135 return 'vieworg';
3236 }
3337
 38+ /**
 39+ * (non-PHPdoc)
 40+ * @see EPViewAction::displayPage()
 41+ */
3442 protected function displayPage( DBDataObject $org ) {
3543 parent::displayPage( $org );
3644
@@ -85,4 +93,4 @@
8694 return $stats;
8795 }
8896
89 -}
\ No newline at end of file
 97+}
Index: trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
@@ -49,8 +49,9 @@
5050
5151 if ( $object === false ) {
5252 $revision = EPRevisions::singleton()->getLatestRevision( array(
53 - 'object_identifier' => $this->getTitle()->getText()
54 - ) );
 53+ 'object_identifier' => $this->getTitle()->getText(),
 54+ 'type' => $this->page->getTable()->getDataObjectClass(),
 55+ ) );
5556
5657 if ( $revision === false ) {
5758 $query = array( 'undeletefailed' => 'norevs' ); // TODO: handle
Index: trunk/extensions/EducationProgram/includes/EPOrgs.php
@@ -63,6 +63,7 @@
6464 'instructor_count' => 'int',
6565 'ca_count' => 'int',
6666 'oa_count' => 'int',
 67+ 'courses' => 'array',
6768 );
6869 }
6970
@@ -84,6 +85,7 @@
8586 'instructor_count' => 0,
8687 'ca_count' => 0,
8788 'oa_count' => 0,
 89+ 'courses' => array(),
8890 );
8991 }
9092
@@ -112,6 +114,7 @@
113115 'instructor_count',
114116 'oa_count',
115117 'ca_count',
 118+ 'courses',
116119 );
117120 }
118121
Index: trunk/extensions/EducationProgram/includes/EPRevisionAction.php
@@ -1,5 +1,18 @@
22 <?php
33
 4+/**
 5+ * Class representing a single revision action.
 6+ * This can be any kind of change creating a new revision,
 7+ * such as page creation, edits, deletion and reverts.
 8+ *
 9+ * @since 0.1
 10+ *
 11+ * @file EPRevisionAction.php
 12+ * @ingroup EducationProgram
 13+ *
 14+ * @licence GNU GPL v3 or later
 15+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 16+ */
417 class EPRevisionAction {
518
619 protected $user;
@@ -8,49 +21,82 @@
922 protected $comment = '';
1023 protected $time = false;
1124
12 - public function __construct() {
13 -
14 - }
15 -
 25+ /**
 26+ * @since 0.1
 27+ * @return boolean
 28+ */
1629 public function isMinor() {
1730 return $this->isMinor;
1831 }
1932
 33+ /**
 34+ * @since 0.1
 35+ * @return boolean
 36+ */
2037 public function isDelete() {
2138 return $this->isDelete;
2239 }
2340
 41+ /**
 42+ * @since 0.1
 43+ * @return string
 44+ */
2445 public function getComment() {
2546 return $this->comment;
2647 }
2748
2849 /**
 50+ * @since 0.1
2951 * @return User
3052 */
3153 public function getUser() {
3254 return $this->user;
3355 }
3456
 57+ /**
 58+ * @since 0.1
 59+ * @return string
 60+ */
3561 public function getTime() {
3662 return $this->time === false ? wfTimestampNow() : $this->time;
3763 }
3864
 65+ /**
 66+ * @since 0.1
 67+ * @param User $user
 68+ */
3969 public function setUser( User $user ) {
4070 $this->user = $user;
4171 }
4272
 73+ /**
 74+ * @since 0.1
 75+ * @param string $comment
 76+ */
4377 public function setComment( $comment ) {
4478 $this->comment = $comment;
4579 }
4680
 81+ /**
 82+ * @since 0.1
 83+ * @param boolean $isDelete
 84+ */
4785 public function setDelete( $isDelete ) {
4886 $this->isDelete = $isDelete;
4987 }
5088
 89+ /**
 90+ * @since 0.1
 91+ * @param boolean $isMinor
 92+ */
5193 public function setMinor( $isMinor ) {
5294 $this->isMinor = $isMinor;
5395 }
5496
 97+ /**
 98+ * @since 0.1
 99+ * @param string $time
 100+ */
55101 public function setTime( $time ) {
56102 $this->time = $time;
57103 }
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -27,7 +27,7 @@
2828 */
2929 public function loadSummaryFields( $summaryFields = null ) {
3030 if ( is_null( $summaryFields ) ) {
31 - $summaryFields = array( 'course_count', 'active', 'student_count', 'instructor_count', 'oa_count', 'ca_count' );
 31+ $summaryFields = array( 'course_count', 'active', 'student_count', 'instructor_count', 'oa_count', 'ca_count', 'courses' );
3232 }
3333 else {
3434 $summaryFields = (array)$summaryFields;
@@ -35,8 +35,9 @@
3636
3737 $fields = array();
3838
39 - if ( in_array( 'course_count', $summaryFields ) ) {
40 - $fields['course_count'] = EPCourses::singleton()->count( array( 'org_id' => $this->getId() ) );
 39+ if ( in_array( 'course_count', $summaryFields ) || in_array( 'courses', $summaryFields ) ) {
 40+ $fields['courses'] = EPCourses::singleton()->selectFields( 'id', array( 'org_id' => $this->getId() ) );
 41+ $fields['course_count'] = count( $fields['courses'] );
4142 }
4243
4344 $dbr = wfGetDB( DB_SLAVE );
@@ -104,6 +105,34 @@
105106
106107 return parent::save();
107108 }
 109+
 110+ /**
 111+ * (non-PHPdoc)
 112+ * @see EPRevisionedObject::undelete()
 113+ */
 114+ public function undelete( EPRevisionAction $revAction ) {
 115+ $success = parent::undelete( $revAction );
 116+
 117+ if ( $success ) {
 118+ $courseRevAction = new EPRevisionAction();
 119+
 120+ $courseRevAction->setUser( $revAction->getUser() );
 121+ $courseRevAction->setComment( '' ); // TODO
 122+
 123+ foreach ( $this->getField( 'courses' ) as $courseId ) {
 124+ $courseRevision = EPRevisions::singleton()->getLatestRevision( array(
 125+ 'object_id' => $courseId,
 126+ 'type' => 'EPCourse',
 127+ ) );
 128+
 129+ if ( $courseRevision !== false ) {
 130+ $courseRevision->getObject()->undelete( $courseRevAction );
 131+ }
 132+ }
 133+ }
 134+
 135+ return $success;
 136+ }
108137
109138 /**
110139 * Adds a control to add a new org to the provided context.
@@ -201,10 +230,14 @@
202231 */
203232 public function getCourses( array $fields = null ) {
204233 if ( $this->courses === false ) {
205 - $this->courses = EPCourses::singleton()->select( $fields, array( 'org_id' => $this->getId() ) );
 234+ $courses = EPCourses::singleton()->select( $fields, array( 'org_id' => $this->getId() ) );
 235+
 236+ if ( is_null( $fields ) ) {
 237+ $this->courses = $courses;
 238+ }
206239 }
207240
208 - return $this->courses;
 241+ return $this->courses === false ? $courses : $courses;
209242 }
210243
211244 }
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -193,7 +193,7 @@
194194 * @since 0.1
195195 */
196196 protected function onRemoved() {
197 - //$this->storeRevision( $this );
 197+ $this->storeRevision( $this );
198198 $this->log( 'remove' );
199199 parent::onRemoved();
200200 }
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -29,20 +29,13 @@
3030 dirname( __FILE__ ) . '/sql/EducationProgram.sql'
3131 );
3232
33 -// $updater->addExtensionUpdate( array(
34 -// 'addField',
35 -// 'ep_revisions',
36 -// 'rev_object_identifier',
37 -// dirname( __FILE__ ) . '/sql/AddRevIdentifier.sql',
38 -// true
39 -// ) );
40 -//
41 -// $updater->addExtensionUpdate( array(
42 -// 'addTable',
43 -// 'ep_users_per_course',
44 -// dirname( __FILE__ ) . '/sql/UpdateUserLinks.sql',
45 -// true
46 -// ) );
 33+ $updater->addExtensionUpdate( array(
 34+ 'addField',
 35+ 'ep_orgs',
 36+ 'org_courses',
 37+ dirname( __FILE__ ) . '/sql/AddCoursesField.sql',
 38+ true
 39+ ) );
4740
4841 return true;
4942 }

Status & tagging log