https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111902

Revision: 111902
Author:   jeroendedauw
Date:     2012-02-20 00:57:24 +0000 (Mon, 20 Feb 2012)
Log Message:
-----------
Follow up to r111900; 

Modified Paths:
--------------
    trunk/extensions/EducationProgram/includes/EPPageObject.php
    trunk/extensions/EducationProgram/maintenance/importWEPData.php

Modified: trunk/extensions/EducationProgram/includes/EPPageObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPPageObject.php 2012-02-20 
00:42:24 UTC (rev 111901)
+++ trunk/extensions/EducationProgram/includes/EPPageObject.php 2012-02-20 
00:57:24 UTC (rev 111902)
@@ -27,7 +27,20 @@
        public function getTitle() {
                return $this->table->getTitleFor( $this->getIdentifier() );
        }
-
+       
+       /**
+        * (non-PHPdoc)
+        * @see DBDataObject::save()
+        */
+       public function save() {
+               if ( $this->hasField( $this->table->getIdentifierField() ) && 
is_null( $this->getTitle() ) ) {
+                       throw new MWException( 'The title for a EPPageObject 
needs to be valid when saving.' );
+                       return false;
+               }
+               
+               return parent::save();
+       }
+       
        public function getLink( $action = 'view', $html = null, $customAttribs 
= array(), $query = array() ) {
                return $this->table->getLinkFor(
                        $this->getIdentifier(),
@@ -43,7 +56,14 @@
         * @see EPRevisionedObject::getLogInfo()
         */
        protected function getLogInfo( $subType ) {
-               return $this->table->getLogInfoForTitle( $this->getTitle() );
+               $title = $this->getTitle();
+               
+               if ( is_null( $title ) ) {
+                       return false;
+               }
+               else {
+                       return $this->table->getLogInfoForTitle( 
$this->getTitle() );
+               }
        }
 
 }

Modified: trunk/extensions/EducationProgram/maintenance/importWEPData.php
===================================================================
--- trunk/extensions/EducationProgram/maintenance/importWEPData.php     
2012-02-20 00:42:24 UTC (rev 111901)
+++ trunk/extensions/EducationProgram/maintenance/importWEPData.php     
2012-02-20 00:57:24 UTC (rev 111902)
@@ -37,8 +37,8 @@
                        return;
                }
                
-               $orgs = array(); // org
-               $courses = array(); // course => org
+               $orgs = array(); // org name => org id
+               $courses = array(); // course => org name
                $students = array(); // student => [ courses ]
                
                foreach ( explode( "\n", $text ) as $line ) {
@@ -58,30 +58,57 @@
                                }
                                
                                $courses[$course] = $org;
-                               $orgs[] = $org;
+                               $orgs[$org] = false;
                        }
                }
                
-               $orgs = array_unique( $orgs );
-               
                echo 'Found ' . count( $orgs ) . ' orgs, ' . count( $courses ) 
. ' courses and ' . count( $students ) . " students.\n";
                
+               echo "Inserting orgs ...";
+               
                wfGetDB( DB_MASTER )->begin();
                
-               foreach ( $orgs as $org ) {
+               foreach ( $orgs as $org => &$id ) {
                        $org = EPOrgs::singleton()->newFromArray(
                                array(
                                        'name' => $org,
-                                       'country' => 'us',
+                                       'country' => 'US',
                                ),
                                true
                        );
                        
                        $org->save();
+                       $id = $org->getId();
                }
                
                wfGetDB( DB_MASTER )->commit();
                
+               echo " done!\n";
+               
+               echo "Inserting courses ...\n";
+               
+               foreach ( $courses as $course => $org ) {
+                       $name = $course;
+                       
+                       $course = EPCourses::singleton()->newFromArray(
+                               array(
+                                       'org_id' => $orgs[$org],
+                                       'name' => $course,
+                                       'mc' => $course,
+                               ),
+                               true
+                       );
+                       
+                       try{
+                               $course->save();
+                       }
+                       catch ( Exception $ex ) {
+                               echo "Failed to insert course '$name'.\n";
+                       }
+               }
+               
+               echo "Inserted courses\n";
+               
                echo "\n\n";
        }
        


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to