Pwirth has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/385375 )
Change subject: [WIP] BSFoundation: Added dettings data store ...................................................................... [WIP] BSFoundation: Added dettings data store Change-Id: I1776ef3ba3e00963a342c01bcb717249c50b7de9 --- M src/Config.php M src/Data/FieldType.php A src/Data/Settings/PrimaryDataProvider.php A src/Data/Settings/Reader.php A src/Data/Settings/Record.php A src/Data/Settings/Schema.php A src/Data/Settings/SecondaryDataProvider.php A src/Data/Settings/Store.php 8 files changed, 169 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation refs/changes/75/385375/1 diff --git a/src/Config.php b/src/Config.php index e81912b..cb5e505 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1,6 +1,8 @@ <?php namespace BlueSpice; +use BlueSpice\Data\Settings\Store; +use BlueSpice\Context; class Config extends \MultiConfig implements \Serializable { @@ -62,22 +64,24 @@ protected function makeDatabaseConfig() { $hash = []; $dbr = $this->loadBalancer->getConnection( DB_REPLICA ); - //when config get initialized before the database is created - //(f.e.: in update.php) - //TODO: Cache this config if( !$dbr->tableExists( 'bs_settings3' ) ) { return new \HashConfig( $hash ); } - $res = $dbr->select( 'bs_settings3', '*' ); + $store = $this->getStore(); + $resultSet = $store->getReader()->read( new Data\ReaderParams( [] ) ); - foreach( $res as $row ) { - if( strpos( $row->s_name, 'bsg' ) === 0 ) { - $name = substr( $row->s_name, 3 ); - $hash[$name] = \FormatJson::decode( $row->s_value ); - } + foreach( $resultSet->getRecords() as $row ) { + $hash[$row['name']] = $row['value']; } return new \HashConfig( $hash ); } + protected function getStore() { + return new Store( + new Context( \RequestContext::getMain(), $this ), + $this->loadBalancer + ); + } + } diff --git a/src/Data/FieldType.php b/src/Data/FieldType.php index 672a7b6..d419cf2 100644 --- a/src/Data/FieldType.php +++ b/src/Data/FieldType.php @@ -13,4 +13,5 @@ const INT = 'int'; const STRING = 'string'; const LISTVALUE = 'list'; + const MIXED = 'mixed'; } diff --git a/src/Data/Settings/PrimaryDataProvider.php b/src/Data/Settings/PrimaryDataProvider.php new file mode 100644 index 0000000..3b30031 --- /dev/null +++ b/src/Data/Settings/PrimaryDataProvider.php @@ -0,0 +1,60 @@ +<?php + +namespace BlueSpice\Data\Settings; + +use \BlueSpice\Data\IPrimaryDataProvider; + +class PrimaryDataProvider implements IPrimaryDataProvider { + + protected static $stored = null; + + /** + * + * @var \BlueSpice\Data\Record[] + */ + protected $data = []; + + /** + * + * @var \Wikimedia\Rdbms\IDatabase + */ + protected $db = null; + + /** + * + * @param \Wikimedia\Rdbms\IDatabase $db + */ + public function __construct( $db ) { + $this->db = $db; + } + + /** + * + * @param string $query + * @param type $preFilters + */ + public function makeData( $query = '', $preFilters = [] ) { + if( static::$stored ) { + return static::$stored; + } + $res = $this->db->select( 'bs_settings3', '*' ); + + foreach( $res as $row ) { + $this->appendRowToData( $row ); + } + + static::$stored = $this->data; + return static::$stored; + } + + protected function appendRowToData( $row ) { + if( strpos( $row->s_name, 'bsg' ) !== 0 ) { + return; + } + + $this->data[] = new Record( (object) [ + Record::NAME => $row->s_name, + Record::VALUE => \FormatJson::decode( $row->s_value ) + ]); + } +} \ No newline at end of file diff --git a/src/Data/Settings/Reader.php b/src/Data/Settings/Reader.php new file mode 100644 index 0000000..099dfa5 --- /dev/null +++ b/src/Data/Settings/Reader.php @@ -0,0 +1,25 @@ +<?php + +namespace BlueSpice\Data\Settings; + +use \BlueSpice\Data\DatabaseReader; + +class Reader extends DatabaseReader { + public function __construct( $loadBalancer, \IContextSource $context = null ) { + parent::__construct( $loadBalancer, $context, $context->getConfig() ); + } + + protected function makePrimaryDataProvider( $params ) { + return new PrimaryDataProvider( $this->db ); + } + + protected function makeSecondaryDataProvider() { + return new SecondaryDataProvider( + \MediaWiki\MediaWikiServices::getInstance()->getLinkRenderer() + ); + } + + public function getSchema() { + return new Schema(); + } +} \ No newline at end of file diff --git a/src/Data/Settings/Record.php b/src/Data/Settings/Record.php new file mode 100644 index 0000000..6fd09c2 --- /dev/null +++ b/src/Data/Settings/Record.php @@ -0,0 +1,8 @@ +<?php + +namespace BlueSpice\Data\Settings; + +class Record extends \BlueSpice\Data\Record { + const NAME = 's_name'; + const VALUE = 's_value'; +} \ No newline at end of file diff --git a/src/Data/Settings/Schema.php b/src/Data/Settings/Schema.php new file mode 100644 index 0000000..f73a153 --- /dev/null +++ b/src/Data/Settings/Schema.php @@ -0,0 +1,22 @@ +<?php + +namespace BlueSpice\Data\Settings; + +use BlueSpice\Data\FieldType; + +class Schema extends \BlueSpice\Data\Schema { + public function __construct() { + parent::__construct( [ + Record::NAME => [ + self::FILTERABLE => true, + self::SORTABLE => true, + self::TYPE => FieldType::STRING + ], + Record::VALUE => [ + self::FILTERABLE => false, + self::SORTABLE => false, + self::TYPE => FieldType::MIXED + ], + ]); + } +} \ No newline at end of file diff --git a/src/Data/Settings/SecondaryDataProvider.php b/src/Data/Settings/SecondaryDataProvider.php new file mode 100644 index 0000000..1fc77fd --- /dev/null +++ b/src/Data/Settings/SecondaryDataProvider.php @@ -0,0 +1,11 @@ +<?php + +namespace BlueSpice\Data\Settings; + +class SecondaryDataProvider extends \BlueSpice\Data\SecondaryDataProvider { + + public function __construct( $linkrenderer ) {} + + protected function doExtend( &$dataSet ) {} + +} \ No newline at end of file diff --git a/src/Data/Settings/Store.php b/src/Data/Settings/Store.php new file mode 100644 index 0000000..6967beb --- /dev/null +++ b/src/Data/Settings/Store.php @@ -0,0 +1,29 @@ +<?php + +namespace BlueSpice\Data\Settings; + +class Store implements \BlueSpice\Data\IStore { + + /** + * + * @var \IContextSource + */ + protected $context = null; + + /** + * + * @param \IContextSource $context + */ + public function __construct( $context, $loadBalancer ) { + $this->context = $context; + $this->loadBalancer = $loadBalancer; + } + + public function getReader() { + return new Reader( $this->loadBalancer, $this->context ); + } + + public function getWriter() { + return new Writer( $this->loadBalancer, $this->context ); + } +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/385375 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1776ef3ba3e00963a342c01bcb717249c50b7de9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation Gerrit-Branch: master Gerrit-Owner: Pwirth <wi...@hallowelt.biz> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits