From: Tim Starling Date: Sun, 14 Aug 2005 07:18:34 +0000 (+0000) Subject: support for two-part external storage URLs referring to parts of history blobs X-Git-Tag: 1.6.0~1990 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=65abef703bf63f97e5dfdb8a9703d7e5752375e5;p=lhc%2Fweb%2Fwiklou.git support for two-part external storage URLs referring to parts of history blobs --- diff --git a/includes/ExternalStoreDB.php b/includes/ExternalStoreDB.php index 00f8c481ea..155e428b8e 100644 --- a/includes/ExternalStoreDB.php +++ b/includes/ExternalStoreDB.php @@ -10,31 +10,79 @@ require_once( 'LoadBalancer.php' ); /** @package MediaWiki */ + class ExternalStoreDB { + var $loadBalancers = array(); + /** * Fetch data from given URL * @param string $url An url */ + + function &getLoadBalancer( $cluster ) { + global $wgExternalServers; + if ( !array_key_exists( $cluster, $this->loadBalancers ) ) { + $this->loadBalancers[$cluster] = LoadBalancer::newFromParams( $wgExternalServers[$cluster] ); + } + return $this->loadBalancers[$cluster]; + } + + function &getSlave( $cluster ) { + $lb =& $this->getLoadBalancer( $cluster ); + return $lb->getConnection( DB_SLAVE ); + } + + function &getMaster( $cluster ) { + $lb =& $this->getLoadBalancer( $cluster ); + return $lb->getConnection( DB_MASTER ); + } + + function ExternalStoreDB() { + $this->mLoadBalancer = LoadBalancer::NewFromParams( $wgExternalServers[$cluster] ); + } + function fetchFromURL($url) { global $wgExternalServers; # - # URLs have the form DB://cluster/id, e.g. - # DB://cluster1/3298247 + # URLs have the form DB://cluster/id or DB://cluster/id/itemid for concatenated storage # $path = explode( '/', $url ); $cluster = $path[2]; $id = $path[3]; + if ( isset( $path[4] ) ) { + $itemID = $path[4]; + } else { + $itemID = false; + } - $lb = LoadBalancer::NewFromParams( $wgExternalServers[$cluster] ); - $db = $lb->getConnection( DB_SLAVE ); + $dbr =& $this->getSlave( $cluster ); + $ret = $dbr->selectField( 'blobs', 'blob_text', array( 'blob_id' => $id ) ); - $ret = $db->selectField( 'blobs', 'blob_text', array( 'blob_id' => $id ) ); + if ( $itemID !== false ) { + # Unserialise object and get item + $obj = unserialize( $ret ); + $ret = $obj->getItem( $itemID ); + } return $ret; } - /* @fixme XXX: may require other methods, for store, delete, - * whatever, for initial ext storage + /** + * Insert a data item into a given cluster + * + * @param string $cluster The cluster name + * @param string $data The data item + * @return string URL */ + function store( $cluster, $data ) { + global $wgExternalServers; + $fname = 'ExternalStoreDB::store'; + + $dbw =& $this->getMaster( $cluster ); + + $id = $dbw->nextSequenceValue( 'blob_blob_id_seq' ); + $dbw->insert( 'blobs', array( 'blob_id' => $id, 'blob_text' => $data ), $fname ); + return "DB://$cluster/" . $dbw->insertId(); + } } ?> diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php index f7fa77afd3..b407a836fe 100644 --- a/includes/HistoryBlob.php +++ b/includes/HistoryBlob.php @@ -210,14 +210,14 @@ class HistoryBlobStub { } $flags = explode( ',', $row->old_flags ); if( in_array( 'external', $flags ) ) { - $url=$row->old_text; - @list($proto,$path)=explode('://',$url,2); - if ($path=="") { - wfProfileOut( $fname ); - return false; - } - require_once('ExternalStore.php'); - $row->old_text=ExternalStore::fetchFromUrl($url); + $url=$row->old_text; + @list($proto,$path)=explode('://',$url,2); + if ($path=="") { + wfProfileOut( $fname ); + return false; + } + require_once('ExternalStore.php'); + $row->old_text=ExternalStore::fetchFromUrl($url); } if( !in_array( 'object', $flags ) ) {