https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112662
Revision: 112662
Author: jeroendedauw
Date: 2012-02-29 00:33:31 +0000 (Wed, 29 Feb 2012)
Log Message:
-----------
work on org undeletion
Modified Paths:
--------------
trunk/extensions/EducationProgram/EducationProgram.hooks.php
trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
trunk/extensions/EducationProgram/actions/ViewCourseAction.php
trunk/extensions/EducationProgram/actions/ViewOrgAction.php
trunk/extensions/EducationProgram/includes/EPOrg.php
trunk/extensions/EducationProgram/includes/EPOrgs.php
trunk/extensions/EducationProgram/includes/EPRevisionAction.php
trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
trunk/extensions/EducationProgram/sql/EducationProgram.sql
Added Paths:
-----------
trunk/extensions/EducationProgram/sql/AddCoursesField.sql
Modified: trunk/extensions/EducationProgram/EducationProgram.hooks.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.hooks.php
2012-02-28 23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/EducationProgram.hooks.php
2012-02-29 00:33:31 UTC (rev 112662)
@@ -29,20 +29,13 @@
dirname( __FILE__ ) . '/sql/EducationProgram.sql'
);
-// $updater->addExtensionUpdate( array(
-// 'addField',
-// 'ep_revisions',
-// 'rev_object_identifier',
-// dirname( __FILE__ ) . '/sql/AddRevIdentifier.sql',
-// true
-// ) );
-//
-// $updater->addExtensionUpdate( array(
-// 'addTable',
-// 'ep_users_per_course',
-// dirname( __FILE__ ) . '/sql/UpdateUserLinks.sql',
-// true
-// ) );
+ $updater->addExtensionUpdate( array(
+ 'addField',
+ 'ep_orgs',
+ 'org_courses',
+ dirname( __FILE__ ) . '/sql/AddCoursesField.sql',
+ true
+ ) );
return true;
}
Modified: trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
2012-02-28 23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
2012-02-29 00:33:31 UTC (rev 112662)
@@ -49,8 +49,9 @@
if ( $object === false ) {
$revision =
EPRevisions::singleton()->getLatestRevision( array(
- 'object_identifier' =>
$this->getTitle()->getText()
- ) );
+ 'object_identifier' =>
$this->getTitle()->getText(),
+ 'type' =>
$this->page->getTable()->getDataObjectClass(),
+ ) );
if ( $revision === false ) {
$query = array( 'undeletefailed' => 'norevs' );
// TODO: handle
Modified: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/ViewCourseAction.php
2012-02-28 23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/actions/ViewCourseAction.php
2012-02-29 00:33:31 UTC (rev 112662)
@@ -26,10 +26,18 @@
parent::__construct( $page, $context, EPCourses::singleton() );
}
+ /**
+ * (non-PHPdoc)
+ * @see Action::getName()
+ */
public function getName() {
return 'viewcourse';
}
+ /**
+ * (non-PHPdoc)
+ * @see EPViewAction::displayPage()
+ */
protected function displayPage( DBDataObject $course ) {
parent::displayPage( $course );
@@ -205,4 +213,4 @@
}
}
-}
\ No newline at end of file
+}
Modified: trunk/extensions/EducationProgram/actions/ViewOrgAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/ViewOrgAction.php 2012-02-28
23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/actions/ViewOrgAction.php 2012-02-29
00:33:31 UTC (rev 112662)
@@ -26,10 +26,18 @@
parent::__construct( $page, $context, EPOrgs::singleton() );
}
+ /**
+ * (non-PHPdoc)
+ * @see Action::getName()
+ */
public function getName() {
return 'vieworg';
}
+ /**
+ * (non-PHPdoc)
+ * @see EPViewAction::displayPage()
+ */
protected function displayPage( DBDataObject $org ) {
parent::displayPage( $org );
@@ -85,4 +93,4 @@
return $stats;
}
-}
\ No newline at end of file
+}
Modified: trunk/extensions/EducationProgram/includes/EPOrg.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPOrg.php 2012-02-28
23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/includes/EPOrg.php 2012-02-29
00:33:31 UTC (rev 112662)
@@ -27,7 +27,7 @@
*/
public function loadSummaryFields( $summaryFields = null ) {
if ( is_null( $summaryFields ) ) {
- $summaryFields = array( 'course_count', 'active',
'student_count', 'instructor_count', 'oa_count', 'ca_count' );
+ $summaryFields = array( 'course_count', 'active',
'student_count', 'instructor_count', 'oa_count', 'ca_count', 'courses' );
}
else {
$summaryFields = (array)$summaryFields;
@@ -35,8 +35,9 @@
$fields = array();
- if ( in_array( 'course_count', $summaryFields ) ) {
- $fields['course_count'] =
EPCourses::singleton()->count( array( 'org_id' => $this->getId() ) );
+ if ( in_array( 'course_count', $summaryFields ) || in_array(
'courses', $summaryFields ) ) {
+ $fields['courses'] =
EPCourses::singleton()->selectFields( 'id', array( 'org_id' => $this->getId() )
);
+ $fields['course_count'] = count( $fields['courses'] );
}
$dbr = wfGetDB( DB_SLAVE );
@@ -104,6 +105,34 @@
return parent::save();
}
+
+ /**
+ * (non-PHPdoc)
+ * @see EPRevisionedObject::undelete()
+ */
+ public function undelete( EPRevisionAction $revAction ) {
+ $success = parent::undelete( $revAction );
+
+ if ( $success ) {
+ $courseRevAction = new EPRevisionAction();
+
+ $courseRevAction->setUser( $revAction->getUser() );
+ $courseRevAction->setComment( '' ); // TODO
+
+ foreach ( $this->getField( 'courses' ) as $courseId ) {
+ $courseRevision =
EPRevisions::singleton()->getLatestRevision( array(
+ 'object_id' => $courseId,
+ 'type' => 'EPCourse',
+ ) );
+
+ if ( $courseRevision !== false ) {
+ $courseRevision->getObject()->undelete(
$courseRevAction );
+ }
+ }
+ }
+
+ return $success;
+ }
/**
* Adds a control to add a new org to the provided context.
@@ -201,10 +230,14 @@
*/
public function getCourses( array $fields = null ) {
if ( $this->courses === false ) {
- $this->courses = EPCourses::singleton()->select(
$fields, array( 'org_id' => $this->getId() ) );
+ $courses = EPCourses::singleton()->select( $fields,
array( 'org_id' => $this->getId() ) );
+
+ if ( is_null( $fields ) ) {
+ $this->courses = $courses;
+ }
}
- return $this->courses;
+ return $this->courses === false ? $courses : $courses;
}
}
Modified: trunk/extensions/EducationProgram/includes/EPOrgs.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPOrgs.php 2012-02-28
23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/includes/EPOrgs.php 2012-02-29
00:33:31 UTC (rev 112662)
@@ -63,6 +63,7 @@
'instructor_count' => 'int',
'ca_count' => 'int',
'oa_count' => 'int',
+ 'courses' => 'array',
);
}
@@ -84,6 +85,7 @@
'instructor_count' => 0,
'ca_count' => 0,
'oa_count' => 0,
+ 'courses' => array(),
);
}
@@ -112,6 +114,7 @@
'instructor_count',
'oa_count',
'ca_count',
+ 'courses',
);
}
Modified: trunk/extensions/EducationProgram/includes/EPRevisionAction.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevisionAction.php
2012-02-28 23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/includes/EPRevisionAction.php
2012-02-29 00:33:31 UTC (rev 112662)
@@ -1,5 +1,18 @@
<?php
+/**
+ * Class representing a single revision action.
+ * This can be any kind of change creating a new revision,
+ * such as page creation, edits, deletion and reverts.
+ *
+ * @since 0.1
+ *
+ * @file EPRevisionAction.php
+ * @ingroup EducationProgram
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
class EPRevisionAction {
protected $user;
@@ -8,49 +21,82 @@
protected $comment = '';
protected $time = false;
- public function __construct() {
-
- }
-
+ /**
+ * @since 0.1
+ * @return boolean
+ */
public function isMinor() {
return $this->isMinor;
}
+ /**
+ * @since 0.1
+ * @return boolean
+ */
public function isDelete() {
return $this->isDelete;
}
+ /**
+ * @since 0.1
+ * @return string
+ */
public function getComment() {
return $this->comment;
}
/**
+ * @since 0.1
* @return User
*/
public function getUser() {
return $this->user;
}
+ /**
+ * @since 0.1
+ * @return string
+ */
public function getTime() {
return $this->time === false ? wfTimestampNow() : $this->time;
}
+ /**
+ * @since 0.1
+ * @param User $user
+ */
public function setUser( User $user ) {
$this->user = $user;
}
+ /**
+ * @since 0.1
+ * @param string $comment
+ */
public function setComment( $comment ) {
$this->comment = $comment;
}
+ /**
+ * @since 0.1
+ * @param boolean $isDelete
+ */
public function setDelete( $isDelete ) {
$this->isDelete = $isDelete;
}
+ /**
+ * @since 0.1
+ * @param boolean $isMinor
+ */
public function setMinor( $isMinor ) {
$this->isMinor = $isMinor;
}
+ /**
+ * @since 0.1
+ * @param string $time
+ */
public function setTime( $time ) {
$this->time = $time;
}
Modified: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
2012-02-28 23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
2012-02-29 00:33:31 UTC (rev 112662)
@@ -193,7 +193,7 @@
* @since 0.1
*/
protected function onRemoved() {
- //$this->storeRevision( $this );
+ $this->storeRevision( $this );
$this->log( 'remove' );
parent::onRemoved();
}
Added: trunk/extensions/EducationProgram/sql/AddCoursesField.sql
===================================================================
--- trunk/extensions/EducationProgram/sql/AddCoursesField.sql
(rev 0)
+++ trunk/extensions/EducationProgram/sql/AddCoursesField.sql 2012-02-29
00:33:31 UTC (rev 112662)
@@ -0,0 +1,7 @@
+-- MySQL patch for the Education Program extension.
+-- Licence: GNU GPL v3+
+-- Author: Jeroen De Dauw < [email protected] >
+
+ALTER TABLE /*_*/ep_orgs ADD COLUMN org_courses BLOB NOT NULL;
+
+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
+ native
Modified: trunk/extensions/EducationProgram/sql/EducationProgram.sql
===================================================================
--- trunk/extensions/EducationProgram/sql/EducationProgram.sql 2012-02-28
23:57:19 UTC (rev 112661)
+++ trunk/extensions/EducationProgram/sql/EducationProgram.sql 2012-02-29
00:33:31 UTC (rev 112662)
@@ -16,7 +16,8 @@
org_instructor_count SMALLINT unsigned NOT NULL, -- Amount of
instructors
org_oa_count INT unsigned NOT NULL, -- Amount of online
ambassadors
org_ca_count INT unsigned NOT NULL, -- Amount of campus
ambassadors
- org_student_count INT unsigned NOT NULL -- Amount of students
+ org_student_count INT unsigned NOT NULL, -- Amount of
students
+ org_courses BLOB NOT NULL -- The ids of the
courses (linking ep_courses.course_id)
) /*$wgDBTableOptions*/;
CREATE UNIQUE INDEX /*i*/ep_org_name ON /*_*/ep_orgs (org_name);
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs