From 1a2d5d7c4eb9825b17b5e41183ce68d4edc7e039 Mon Sep 17 00:00:00 2001 From: bsitu Date: Wed, 9 Jul 2014 12:02:19 -0700 Subject: [PATCH] Abstract the logic of getting last bundle notif into a method We will likely need the very last record when building a bundle notification in some cases ( talk page diff, flow unread post etc ), it's better just to have that logic in a method Change-Id: I8121e0cbed2beb066e27953d79225bb99c550553 --- formatters/BasicFormatter.php | 68 ++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/formatters/BasicFormatter.php b/formatters/BasicFormatter.php index 867ce41ab..28258a0c4 100644 --- a/formatters/BasicFormatter.php +++ b/formatters/BasicFormatter.php @@ -751,31 +751,18 @@ class EchoBasicFormatter extends EchoNotificationFormatter { 'diff' => $eventData['revid'], ); - if ( $event->getBundleHash() ) { - // First try cache data from preivous query - if ( isset( $this->bundleData['last-raw-data'] ) ) { - $stat = $this->bundleData['last-raw-data']; - // Then try to query the storage - } else { - global $wgEchoBackend; - $stat = $wgEchoBackend->getRawBundleData( $user, $event->getBundleHash(), $this->distributionType, 'ASC', 1 ); - if ( $stat ) { - $stat = $stat->current(); + $data = $this->getBundleLastRawData( $event, $user ); + if ( $data ) { + $extra = $data->extra_data; + if ( isset( $extra['revid'] ) ) { + $oldId = $target->getPreviousRevisionID( $extra['revid'] ); + // The diff engine doesn't provide a way to diff against a null revision. + // In this case, just fall back old id to the first revision + if ( !$oldId ) { + $oldId = $extra['revid']; } - } - - if ( $stat ) { - $extra = $stat->event_extra ? unserialize( $stat->event_extra ) : array(); - if ( isset( $extra['revid'] ) ) { - $oldId = $target->getPreviousRevisionID( $extra['revid'] ); - // The diff engine doesn't provide a way to diff against a null revision. - // In this case, just fall back old id to the first revision - if ( !$oldId ) { - $oldId = $extra['revid']; - } - if ( $oldId < $eventData['revid'] ) { - $query['oldid'] = $oldId; - } + if ( $oldId < $eventData['revid'] ) { + $query['oldid'] = $oldId; } } } @@ -785,6 +772,39 @@ class EchoBasicFormatter extends EchoNotificationFormatter { return array( $target, $query ); } + /** + * Get the last bundle data in raw stdObject format. When bundling notifications, + * we mostly only need the very first notification, which is the bundle base. + * In some cases, like talk notification diff, Flow notificaiton first unread post, + * we need data from the very last notification. + * + * @param EchoEvent + * @param User + * @return stdObject|boolean false for none + */ + protected function getBundleLastRawData( $event, $user ) { + if ( $event->getBundleHash() ) { + // First try cache data from preivous query + if ( isset( $this->bundleData['last-raw-data'] ) ) { + $data = $this->bundleData['last-raw-data']; + // Then try to query the storage + } else { + global $wgEchoBackend; + $data = $wgEchoBackend->getRawBundleData( $user, $event->getBundleHash(), $this->distributionType, 'ASC', 1 ); + if ( $data ) { + $data = $data->current(); + } + } + + if ( $data ) { + $data->event_extra = $data->event_extra ? unserialize( $data->event_extra ) : array(); + return $data; + } + } + + return false; + } + /** * Get the style for standard links in html email * @return string