Mattflaschen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/249044
Change subject: Implement AbstractCollection::newFromRevisionId
......................................................................
Implement AbstractCollection::newFromRevisionId
This will be useful when troubleshooting things in a shell, and anyway,
it already says it's implemented. :)
Change-Id: I2bd9eaefe012f41bf74d1f403c356db3d573b64c
---
M includes/Collection/AbstractCollection.php
M includes/Collection/HeaderCollection.php
M includes/Collection/LocalCacheAbstractCollection.php
M includes/Collection/PostCollection.php
M includes/Collection/PostSummaryCollection.php
5 files changed, 38 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/44/249044/1
diff --git a/includes/Collection/AbstractCollection.php
b/includes/Collection/AbstractCollection.php
index f69b32a..4948ef9 100644
--- a/includes/Collection/AbstractCollection.php
+++ b/includes/Collection/AbstractCollection.php
@@ -6,6 +6,7 @@
use Flow\Data\ManagerGroup;
use Flow\Data\ObjectManager;
use Flow\Exception\InvalidDataException;
+use Flow\Exception\FlowException;
use Flow\Model\AbstractRevision;
use Flow\Model\UUID;
use Flow\Model\Workflow;
@@ -37,7 +38,7 @@
*
* @return string
*/
- abstract public function getRevisionClass();
+ abstract public static function getRevisionClass();
/**
* Returns the id of the workflow this collection is associated with.
@@ -67,13 +68,32 @@
}
/**
- * Instantiate a new object based on its id.
+ * Instantiate a new object based on its type id
+ * (post ID, header ID, etc.)
*
* @param UUID $uuid
* @return AbstractCollection
*/
public static function newFromId( UUID $uuid ) {
return new static( $uuid );
+ }
+
+ /**
+ * Instantiate a new collection based on a revision ID
+ *
+ * @param UUID $revId Revision ID
+ * @return AbstractCollection
+ */
+ public static function newFromRevisionId( UUID $revId ) {
+ $revisions = static::getStorage()->find(
+ array( 'rev_id' => $revId )
+ );
+
+ if ( !$revisions ) {
+ throw new InvalidDataException( 'Revisions for ' .
$revId->getAlphadecimal() . ' could not be found', 'invalid-revision-id' );
+ }
+
+ return static::newFromRevision( $revisions[0] );
}
/**
@@ -97,9 +117,9 @@
* @param string|null $class Storage class - defaults to
getRevisionClass()
* @return ObjectManager
*/
- public function getStorage( $class = null ) {
+ public static function getStorage( $class = null ) {
if ( !$class ) {
- $class = $this->getRevisionClass();
+ $class = static::getRevisionClass();
}
/** @var ManagerGroup $storage */
@@ -116,13 +136,13 @@
public function getAllRevisions() {
if ( !$this->revisions ) {
/** @var AbstractRevision[] $revisions */
- $revisions = $this->getStorage()->find(
+ $revisions = self::getStorage()->find(
array( 'rev_type_id' => $this->uuid ),
array( 'sort' => 'rev_id', 'order' => 'DESC' )
);
if ( !$revisions ) {
- throw new InvalidDataException( 'Revisions for
' . $this->uuid->getAlphadecimal() . ' could not be found',
'invalid-revision-id' );
+ throw new InvalidDataException( 'Revisions for
' . $this->uuid->getAlphadecimal() . ' could not be found', 'invalid-type-id' );
}
foreach ( $revisions as $revision ) {
@@ -137,7 +157,7 @@
* Returns the revision with the given id.
*
* @param UUID $uuid
- * @return AbstractRevision|null null if there is no such revision
+ * @return AbstractRevision|null null if there is no such revision in
the collection
*/
public function getRevision( UUID $uuid ) {
// make sure all revisions have been loaded
@@ -227,7 +247,7 @@
if ( !$this->workflow ) {
$uuid = $this->getWorkflowId();
- $this->workflow = $this->getStorage(
'Flow\\Model\\Workflow' )->get( $uuid );
+ $this->workflow = self::getStorage(
'Flow\\Model\\Workflow' )->get( $uuid );
if ( !$this->workflow ) {
throw new InvalidDataException( 'Invalid
workflow: ' . $uuid->getAlphadecimal(), 'invalid-workflow' );
}
@@ -237,6 +257,6 @@
}
public function getBoardWorkflow() {
- return $this->getStorage( 'Flow\\Model\\Workflow' )->get(
$this->getBoardWorkflowId() );
+ return self::getStorage( 'Flow\\Model\\Workflow' )->get(
$this->getBoardWorkflowId() );
}
}
diff --git a/includes/Collection/HeaderCollection.php
b/includes/Collection/HeaderCollection.php
index 3f4eefa..592ec9b 100644
--- a/includes/Collection/HeaderCollection.php
+++ b/includes/Collection/HeaderCollection.php
@@ -3,7 +3,7 @@
namespace Flow\Collection;
class HeaderCollection extends LocalCacheAbstractCollection {
- public function getRevisionClass() {
+ public static function getRevisionClass() {
return 'Flow\\Model\\Header';
}
diff --git a/includes/Collection/LocalCacheAbstractCollection.php
b/includes/Collection/LocalCacheAbstractCollection.php
index 4d958c7..46f274d 100644
--- a/includes/Collection/LocalCacheAbstractCollection.php
+++ b/includes/Collection/LocalCacheAbstractCollection.php
@@ -64,8 +64,8 @@
$previousId = $oldest->getPrevRevisionId();
// check if it's in local storage already
- if ( $previousId && $this->getStorage()->got(
$previousId ) ) {
- $revision = $this->getStorage()->get(
$previousId );
+ if ( $previousId && self::getStorage()->got(
$previousId ) ) {
+ $revision = self::getStorage()->get(
$previousId );
// add this revision to revisions array
$this->revisions[$previousId->getAlphadecimal()] = $revision;
@@ -104,11 +104,11 @@
$attributes = array( 'rev_type_id' => $this->uuid );
$options = array( 'sort' => 'rev_id', 'limit' => 1, 'order' =>
'DESC' );
- if ( $this->getStorage()->found( $attributes, $options ) ) {
+ if ( self::getStorage()->found( $attributes, $options ) ) {
// if last revision is already known in local cache,
fetch it
- $revision = $this->getStorage()->find( $attributes,
$options );
+ $revision = self::getStorage()->find( $attributes,
$options );
if ( !$revision ) {
- throw new InvalidDataException( 'Last revision
for ' . $this->uuid->getAlphadecimal() . ' could not be found',
'invalid-revision-id' );
+ throw new InvalidDataException( 'Last revision
for ' . $this->uuid->getAlphadecimal() . ' could not be found',
'invalid-type-id' );
}
$revision = reset( $revision );
$this->revisions[$revision->getRevisionId()->getAlphadecimal()] = $revision;
diff --git a/includes/Collection/PostCollection.php
b/includes/Collection/PostCollection.php
index cd2b405..ee9993d 100644
--- a/includes/Collection/PostCollection.php
+++ b/includes/Collection/PostCollection.php
@@ -13,7 +13,7 @@
*/
protected $rootId;
- public function getRevisionClass() {
+ public static function getRevisionClass() {
return 'Flow\\Model\\PostRevision';
}
@@ -37,7 +37,7 @@
* @throws InvalidDataException
*/
public function getBoardWorkflowId() {
- $found = $this->getStorage( 'Flow\\Model\\TopicListEntry'
)->find(
+ $found = self::getStorage( 'Flow\\Model\\TopicListEntry'
)->find(
// uses flow_topic_list:topic index, for topic->board
lookups
array( 'topic_id' => $this->getWorkflowId() )
);
diff --git a/includes/Collection/PostSummaryCollection.php
b/includes/Collection/PostSummaryCollection.php
index 02275c7..4286f8a 100644
--- a/includes/Collection/PostSummaryCollection.php
+++ b/includes/Collection/PostSummaryCollection.php
@@ -11,7 +11,7 @@
*/
protected $rootId;
- public function getRevisionClass() {
+ public static function getRevisionClass() {
return 'Flow\\Model\\PostSummary';
}
--
To view, visit https://gerrit.wikimedia.org/r/249044
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2bd9eaefe012f41bf74d1f403c356db3d573b64c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits