Merge "(bug 42226) failure in sites tests"
[lhc/web/wiklou.git] / includes / site / SiteObject.php
index 7f143d1..78c942b 100644 (file)
@@ -23,7 +23,7 @@
  * @file
  * @ingroup Site
  *
- * @licence GNU GPL v2+
+ * @license GNU GPL v2+
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  * @author Daniel Werner
  */
@@ -157,10 +157,23 @@ class SiteObject extends ORMRow implements Site {
                $path = $this->getLinkPath();
 
                if ( $path === false ) {
-                       return false;
+                       return '';
+               }
+
+               $protocol = parse_url( $path, PHP_URL_SCHEME );
+
+               // Malformed URL
+               if ( $protocol === false ) {
+                       throw new MWException( "failed to parse URL $path" );
+               }
+
+               // No schema
+               if ( $protocol === null ) {
+                       // Used for protocol relative URLs
+                       $protocol = '';
                }
 
-               return parse_url( $path, PHP_URL_SCHEME );
+               return $protocol;
        }
 
        /**
@@ -426,7 +439,7 @@ class SiteObject extends ORMRow implements Site {
        }
 
        /**
-        * @see ORMRow::save
+        * @see IORMRow::save
         * @see Site::save
         *
         * @since 1.21
@@ -436,7 +449,7 @@ class SiteObject extends ORMRow implements Site {
         * @return boolean Success indicator
         */
        public function save( $functionName = null ) {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->table->getWriteDbConnection();
 
                $trx = $dbw->trxLevel();
 
@@ -482,6 +495,25 @@ class SiteObject extends ORMRow implements Site {
                return $success;
        }
 
+       /**
+        * @since 1.21
+        *
+        * @see ORMRow::onRemoved
+        */
+       protected function onRemoved() {
+               $dbw = $this->table->getWriteDbConnection();
+
+               $dbw->delete(
+                       'site_identifiers',
+                       array(
+                               'si_site' => $this->getId()
+                       ),
+                       __METHOD__
+               );
+
+               parent::onRemoved();
+       }
+
        /**
         * @see Site::setPath
         *