/**
  * Store a data item to an external store, identified by a partial URL
  * The protocol part is used to identify the class, the rest is passed to the
  * class itself as a parameter.
  * Returns the URL of the stored data item, or false on error
  */
 static function insert($url, $data)
 {
     list($proto, $params) = explode('://', $url, 2);
     $store =& ExternalStore::getStoreObject($proto);
     if ($store === false) {
         return false;
     } else {
         return $store->store($params, $data);
     }
 }
Exemple #2
0
 public function execute()
 {
     $dbr = wfGetDB(DB_SLAVE);
     $row = $dbr->selectRow(array('text', 'revision'), array('old_flags', 'old_text'), array('old_id=rev_text_id', 'rev_id' => $this->getArg()));
     if (!$row) {
         $this->error("Row not found", true);
     }
     $flags = explode(',', $row->old_flags);
     $text = $row->old_text;
     if (in_array('external', $flags)) {
         $this->output("External {$text}\n");
         if (preg_match('!^DB://(\\w+)/(\\w+)/(\\w+)$!', $text, $m)) {
             $es = ExternalStore::getStoreObject('DB');
             $blob = $es->fetchBlob($m[1], $m[2], $m[3]);
             if (strtolower(get_class($blob)) == 'concatenatedgziphistoryblob') {
                 $this->output("Found external CGZ\n");
                 $blob->uncompress();
                 $this->output("Items: (" . implode(', ', array_keys($blob->mItems)) . ")\n");
                 $text = $blob->getItem($m[3]);
             } else {
                 $this->output("CGZ expected at {$text}, got " . gettype($blob) . "\n");
                 $text = $blob;
             }
         } else {
             $this->output("External plain {$text}\n");
             $text = ExternalStore::fetchFromURL($text);
         }
     }
     if (in_array('gzip', $flags)) {
         $text = gzinflate($text);
     }
     if (in_array('object', $flags)) {
         $obj = unserialize($text);
         $text = $obj->getText();
     }
     if (is_object($text)) {
         $this->error("Unexpectedly got object of type: " . get_class($text));
     } else {
         $this->output("Text length: " . strlen($text) . "\n");
         $this->output(substr($text, 0, 100) . "\n");
     }
 }
Exemple #3
0
 * @ingroup Maintenance ExternalStorage
 */
require_once dirname(__FILE__) . '/../commandLine.inc';
$wgDebugLogFile = '/dev/stdout';
$dbr = wfGetDB(DB_SLAVE);
$row = $dbr->selectRow(array('text', 'revision'), array('old_flags', 'old_text'), array('old_id=rev_text_id', 'rev_id' => $args[0]));
if (!$row) {
    print "Row not found\n";
    exit;
}
$flags = explode(',', $row->old_flags);
$text = $row->old_text;
if (in_array('external', $flags)) {
    print "External {$text}\n";
    if (preg_match('!^DB://(\\w+)/(\\w+)/(\\w+)$!', $text, $m)) {
        $es = ExternalStore::getStoreObject('DB');
        $blob = $es->fetchBlob($m[1], $m[2], $m[3]);
        if (strtolower(get_class($blob)) == 'concatenatedgziphistoryblob') {
            print "Found external CGZ\n";
            $blob->uncompress();
            print "Items: (" . implode(', ', array_keys($blob->mItems)) . ")\n";
            $text = $blob->getItem($m[3]);
        } else {
            print "CGZ expected at {$text}, got " . gettype($blob) . "\n";
            $text = $blob;
        }
    } else {
        print "External plain {$text}\n";
        $text = ExternalStore::fetchFromURL($text);
    }
}
 /**
  * Gets master database connections for all of the ExternalStoreDB
  * stores configured in $wgDefaultExternalStore.
  *
  * @return Database[] Array of Database master connections
  */
 protected static function getExternalStoreDatabaseConnections()
 {
     global $wgDefaultExternalStore;
     /** @var ExternalStoreDB $externalStoreDB */
     $externalStoreDB = ExternalStore::getStoreObject('DB');
     $defaultArray = (array) $wgDefaultExternalStore;
     $dbws = [];
     foreach ($defaultArray as $url) {
         if (strpos($url, 'DB://') === 0) {
             list($proto, $cluster) = explode('://', $url, 2);
             // Avoid getMaster() because setupDatabaseWithTestPrefix()
             // requires Database instead of plain DBConnRef/IDatabase
             $lb = $externalStoreDB->getLoadBalancer($cluster);
             $dbw = $lb->getConnection(DB_MASTER);
             $dbws[] = $dbw;
         }
     }
     return $dbws;
 }
 /**
  * Gets master database connections for all of the ExternalStoreDB
  * stores configured in $wgDefaultExternalStore.
  *
  * @return array Array of DatabaseBase master connections
  */
 protected static function getExternalStoreDatabaseConnections()
 {
     global $wgDefaultExternalStore;
     $externalStoreDB = ExternalStore::getStoreObject('DB');
     $defaultArray = (array) $wgDefaultExternalStore;
     $dbws = [];
     foreach ($defaultArray as $url) {
         if (strpos($url, 'DB://') === 0) {
             list($proto, $cluster) = explode('://', $url, 2);
             $dbw = $externalStoreDB->getMaster($cluster);
             $dbws[] = $dbw;
         }
     }
     return $dbws;
 }