Pwirth has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/381175 )
Change subject: Moved generateID to Content class ...................................................................... Moved generateID to Content class Change-Id: I0aa1a895a6038af5154cef940b30c36f91c0c5c7 --- M src/Content/Entity.php M src/Entity.php 2 files changed, 40 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation refs/changes/75/381175/1 diff --git a/src/Content/Entity.php b/src/Content/Entity.php index ae5910e..36744cc 100644 --- a/src/Content/Entity.php +++ b/src/Content/Entity.php @@ -106,4 +106,36 @@ return \Xml::tags( 'tr', array(), $th . $td ); } + + /** + * Returns a generated id for a given entity. + * @param \BlueSpice\Entity $entity + * @return int + */ + public static function generateID( \BlueSpice\Entity $entity ) { + //this is the case if the current Entity is new (no Title created yet) + //Get the page_title of the last created title in entity namespace and + //add +1. Entities are stored like: MYEntityNamespace:1, + //MYEntityNamespace:2, MYEntityNamespace:3 + if ( (int) $entity->getID() > 0 ) { + return $entity->getID(); + } + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->selectRow( + 'page', + 'page_title', + array( 'page_namespace' => $entity::NS ), + __METHOD__, + array( + 'ORDER BY' => 'LENGTH( page_title ) DESC, page_title DESC' + ) + ); + + if ( $res ) { + $id = (int) $res->page_title + 1; + } else { + $id = 1; + } + return $id; + } } \ No newline at end of file diff --git a/src/Entity.php b/src/Entity.php index e8bb3d9..275097a 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -74,32 +74,6 @@ return $oInstance; } - protected function generateID() { - //this is the case if the current Entity is new (no Title created yet) - //Get the page_title of the last created title in entity namespace and - //add +1. Entities are stored like: MYEntityNamespace:1, - //MYEntityNamespace:2, MYEntityNamespace:3 - //TODO: This should be done by related Content object - if ( (int) $this->getID() === 0 ) { - $dbw = wfGetDB( DB_MASTER ); - $res = $dbw->selectRow( - 'page', - 'page_title', - array( 'page_namespace' => static::NS ), - __METHOD__, - array( - 'ORDER BY' => 'LENGTH( page_title ) DESC, page_title DESC' - ) - ); - - if ( $res ) { - $this->iID = (int) $res->page_title + 1; - } else { - $this->iID = 1; - } - } - } - /** * Get Entity by EntityContent Object, wrapper for newFromObject * @param EntityContent $sContent @@ -239,16 +213,20 @@ * @return \Status */ public function save( \User $oUser = null, $aOptions = [] ) { - if( !$oUser instanceof User ) { + if( !$oUser instanceof \User ) { return \Status::newFatal( 'No User' ); } if( $this->exists() && !$this->hasUnsavedChanges() ) { return \Status::newGood( $this ); } - if( empty($this->getID()) ) { - $this->generateID(); + $sContentClass = $this->getConfig()->get( 'ContentClass' ); + if( !class_exists( $sContentClass ) ) { + return \Status::newFatal( "Content class '$sContentClass' not found" ); } - if( empty($this->getID()) ) { + if( empty( $this->getID() ) ) { + $this->iID = $sContentClass::generateID( $this ); + } + if( empty( $this->getID() ) ) { return \Status::newFatal( 'No ID generated' ); } if( empty($this->getOwnerID()) ) { @@ -265,7 +243,6 @@ } $oWikiPage = \WikiPage::factory( $oTitle ); - $sContentClass = $this->getConfig()->get( 'ContentClass' ); try { $oStatus = $oWikiPage->doEditContent( new $sContentClass( json_encode( $this ) ), -- To view, visit https://gerrit.wikimedia.org/r/381175 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0aa1a895a6038af5154cef940b30c36f91c0c5c7 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