*/
public function storeBlob( $data, $hints = [] );
+ /**
+ * Check if the blob metadata or backing blob data store is read-only
+ *
+ * @return bool
+ */
+ public function isReadOnly();
}
$this->logger = $logger;
}
+ /**
+ * @return bool Whether the store is read-only
+ */
+ public function isReadOnly() {
+ return $this->blobStore->isReadOnly();
+ }
+
/**
* @return bool
*/
return [ $schema, $id, $parameters ];
}
+ public function isReadOnly() {
+ if ( $this->useExternalStore && ExternalStore::defaultStoresAreReadOnly() ) {
+ return true;
+ }
+
+ return ( $this->getDBLoadBalancer()->getReadOnlyReason() !== false );
+ }
}
* provided by $wgDefaultExternalStore.
*
* @param string $data
- * @param array $params Associative array of ExternalStoreMedium parameters
+ * @param array $params Map of ExternalStoreMedium::__construct context parameters
* @return string|bool The URL of the stored data item, or false on error
* @throws MWException
*/
*
* @param array $tryStores Refer to $wgDefaultExternalStore
* @param string $data
- * @param array $params Associative array of ExternalStoreMedium parameters
+ * @param array $params Map of ExternalStoreMedium::__construct context parameters
* @return string|bool The URL of the stored data item, or false on error
* @throws MWException
*/
}
}
+ /**
+ * @return bool Whether all the default insertion stores are marked as read-only
+ * @since 1.31
+ */
+ public static function defaultStoresAreReadOnly() {
+ global $wgDefaultExternalStore;
+
+ $tryStores = (array)$wgDefaultExternalStore;
+ if ( !$tryStores ) {
+ return false; // no stores exists which can be "read only"
+ }
+
+ foreach ( $tryStores as $storeUrl ) {
+ list( $proto, $path ) = explode( '://', $storeUrl, 2 );
+ $store = self::getStoreObject( $proto, [] );
+ if ( !$store->isReadOnly( $path ) ) {
+ return false; // at least one store is not read-only
+ }
+ }
+
+ return true; // all stores are read-only
+ }
+
/**
* @param string $data
* @param string $wiki
protected $params = [];
/**
- * @param array $params Options
+ * @param array $params Usage context options:
+ * - wiki: the domain ID of the wiki this is being used for [optional]
*/
public function __construct( array $params = [] ) {
$this->params = $params;
use MediaWiki\Logger\LoggerFactory;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\MediaWikiServices;
/**
* Class to represent a local file in the wiki's own database
) {
if ( $this->getRepo()->getReadOnlyReason() !== false ) {
return $this->readOnlyFatalStatus();
+ } elseif ( MediaWikiServices::getInstance()->getRevisionStore()->isReadOnly() ) {
+ // Check this in advance to avoid writing to FileBackend and the file tables,
+ // only to fail on insert the revision due to the text store being unavailable.
+ return $this->readOnlyFatalStatus();
}
$srcPath = ( $src instanceof FSFile ) ? $src->getPath() : $src;