[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceFoundation[master]: Added entity schema and entity reader base class

2017-09-29 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/380527 )

Change subject: Added entity schema and entity reader base class
..


Added entity schema and entity reader base class

* Also improved the schema base class

PatchSet3
* Fixed unintentional overwrite of filter method

PatchSet6
* Changed hook name to BSEntityConfigAttributeDefinitions
* Added hook handler base class

PatchSet7
* Added LISTVALUE to field types

PatchSet8
* Changed the value of LISTVALUE to 'list', as suggested by rvogel

Change-Id: I96e369b299a7f250f5da5f43df840adddba1153b
---
A src/Data/Entity/Reader.php
A src/Data/Entity/Schema.php
M src/Data/FieldType.php
M src/Data/Schema.php
M src/EntityConfig.php
A src/Hook/BSEntityConfigAttributeDefinitions.php
6 files changed, 271 insertions(+), 15 deletions(-)

Approvals:
  Robert Vogel: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/Data/Entity/Reader.php b/src/Data/Entity/Reader.php
new file mode 100644
index 000..3883186
--- /dev/null
+++ b/src/Data/Entity/Reader.php
@@ -0,0 +1,10 @@
+ true,
+   self::SORTABLE => true,
+   self::TYPE => FieldType::STRING,
+   self::STORABLE => true,
+   self::INDEXABLE => true,
+   ];
+   }
+
+   protected function fillMissingWithDefaults( $fieldDefinition ) {
+   foreach( $this->getDefaultFieldDefinition() as $key => 
$defaultVal ) {
+   if( array_key_exists( $key, $fieldDefinition ) ) {
+   continue;
+   }
+   $fieldDefinition[$key] = $defaultVal;
+   }
+   return $fieldDefinition;
+   }
+
+   /**
+*
+* @return \BlueSpice\Social\EntityConfig[]
+*/
+   protected function getEntityConfigs() {
+   $entityConfigs = [];
+   foreach( EntityRegistry::getRegisterdTypeKeys() as $type ) {
+   if( !$entityConfig = EntityConfig::factory( $type ) ) {
+   continue;
+   }
+   $entityConfigs[] = $entityConfig;
+   }
+   return $entityConfigs;
+   }
+
+   public function __construct() {
+   $scheme = [];
+   foreach( $this->getEntityConfigs() as $entityConfig ) {
+   $definitions = $entityConfig->get( 
'AttributeDefinitions' );
+   foreach( $definitions as $key => $definition ) {
+   $definitions[$key] = 
$this->fillMissingWithDefaults(
+   $definition
+   );
+   }
+   $scheme = array_merge( $scheme, $definitions );
+   }
+   parent::__construct( $scheme );
+   }
+
+   /**
+* @return string[]
+*/
+   public function getIndexableFields() {
+   return $this->filterFields( self::INDEXABLE, true );
+   }
+
+   /**
+* @return string[]
+*/
+   public function getStorableFields() {
+   return $this->filterFields( self::STORABLE, true );
+   }
+
+   /**
+* @return string[]
+*/
+   public function getUnindexableFields() {
+   return $this->filterFields( self::INDEXABLE, false );
+   }
+
+   /**
+* @return string[]
+*/
+   public function getUnstorableFields() {
+   return $this->filterFields( self::STORABLE, false );
+   }
+}
\ No newline at end of file
diff --git a/src/Data/FieldType.php b/src/Data/FieldType.php
index fb32551..672a7b6 100644
--- a/src/Data/FieldType.php
+++ b/src/Data/FieldType.php
@@ -12,4 +12,5 @@
const FLOAT = 'float';
const INT = 'int';
const STRING = 'string';
+   const LISTVALUE = 'list';
 }
diff --git a/src/Data/Schema.php b/src/Data/Schema.php
index a59990f..7d8e847 100644
--- a/src/Data/Schema.php
+++ b/src/Data/Schema.php
@@ -7,28 +7,47 @@
const SORTABLE = 'sortable';
const TYPE = 'type';
 
+   protected function filterFields( $key, $value ) {
+   $entries = $this->filterEntries( $key, $value );
+   return array_keys( $entries );
+   }
+
+   protected function filterEntries( $key, $value ) {
+   $callback = function( $entry ) use( $key, $value ) {
+   return array_key_exists( $key, $entry )
+   ? $entry[$key] === $value
+   : false === $value
+   ;
+   };
+   return array_filter( (array)$this, $callback );
+   }
+
/**
 * @return string[]
 */
public function getUnsortableFields() {
-   $

[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceFoundation[master]: Added entity schema and entity reader base class

2017-09-25 Thread Pwirth (Code Review)
Pwirth has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/380527 )

Change subject: Added entity schema and entity reader base class
..

Added entity schema and entity reader base class

Also improved the schema base class

Change-Id: I96e369b299a7f250f5da5f43df840adddba1153b
---
A src/Data/Entity/Reader.php
A src/Data/Entity/Schema.php
M src/Data/Schema.php
M src/EntityConfig.php
4 files changed, 190 insertions(+), 15 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation 
refs/changes/27/380527/1

diff --git a/src/Data/Entity/Reader.php b/src/Data/Entity/Reader.php
new file mode 100644
index 000..35d44a6
--- /dev/null
+++ b/src/Data/Entity/Reader.php
@@ -0,0 +1,10 @@
+ true,
+   self::SORTABLE => true,
+   self::TYPE => FieldType::STRING,
+   self::STORABLE => true,
+   self::INDEXABLE => true,
+   ];
+   }
+
+   protected function fillMissingWithDefaults( $fieldDefinition ) {
+   foreach( $this->getDefaultFieldDefinition() as $key => 
$defaultVal ) {
+   if( array_key_exists( $key, $fieldDefinition ) ) {
+   continue;
+   }
+   $fieldDefinition[$key] = $defaultVal;
+   }
+   return $fieldDefinition;
+   }
+
+   /**
+* 
+* @return \BlueSpice\Social\EntityConfig[]
+*/
+   protected function getEntityConfigs() {
+   $entityConfigs = [];
+   foreach( EntityRegistry::getRegisterdTypeKeys() as $type ) {
+   if( !$entityConfig = EntityConfig::factory( $type ) ) {
+   continue;
+   }
+   $entityConfigs[] = $entityConfig;
+   }
+   return $entityConfigs;
+   }
+
+   public function __construct() {
+   $scheme = [];
+   foreach( $this->getEntityConfigs() as $entityConfig ) {
+   $definitions = $entityConfig->get( 
'AttributeDefinitions' );
+   foreach( $definitions as $key => $definition ) {
+   $definitions[$key] = 
$this->fillMissingWithDefaults(
+   $definition
+   );
+   }
+   $scheme = array_merge( $scheme, $definitions );
+   }
+   parent::__construct( $scheme );
+   }
+
+   /**
+* @return string[]
+*/
+   public function getIndexableFields() {
+   return array_keys( $this->filter( self::INDEXABLE, true ) );
+   }
+
+   /**
+* @return string[]
+*/
+   public function getStorableFields() {
+   return array_keys( $this->filter( self::STORABLE, true ) );
+   }
+
+   /**
+* @return string[]
+*/
+   public function getUnindexableFields() {
+   return array_keys( $this->filter( self::INDEXABLE, false ) );
+   }
+
+   /**
+* @return string[]
+*/
+   public function getUnstorableFields() {
+   return array_keys( $this->filter( self::STORABLE, false ) );
+   }
+}
\ No newline at end of file
diff --git a/src/Data/Schema.php b/src/Data/Schema.php
index a59990f..817375a 100644
--- a/src/Data/Schema.php
+++ b/src/Data/Schema.php
@@ -7,28 +7,41 @@
const SORTABLE = 'sortable';
const TYPE = 'type';
 
+   protected function filter( $key, $value ) {
+   return array_filter( (array)$this, function( $e ) use( $key, 
$value ) {
+   return array_key_exists( $key, $e )
+   ? $e[$key] === $value
+   : false
+   ;
+   });
+   }
+
/**
 * @return string[]
 */
public function getUnsortableFields() {
-   $unsortableFields = [];
-   foreach( $this as $fieldName => $fieldDef ) {
-   if( $this->fieldIsSortable( $fieldDef ) ) {
-   continue;
-   }
-
-   $unsortableFields[] = $fieldName;
-   }
-
-   return $unsortableFields;
+   return array_keys( $this->filter( self::SORTABLE, false ) );
}
 
-   protected function fieldIsSortable( $fieldDef ) {
-   if( !isset( $fieldDef[self::SORTABLE] ) ) {
-   return false;
-   }
+   /**
+* @return string[]
+*/
+   public function getUnfilterableFields() {
+   return array_keys( $this->filter( self::FILTERABLE, false ) );
+   }
 
-   return $fieldDef[self::SORTABLE];
+