Merge "Drop index oi_name_archive_name on table oldimage"
[lhc/web/wiklou.git] / includes / rcfeed / RedisPubSubFeedEngine.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 /**
22 * Send recent change notifications via Redis Pub/Sub
23 *
24 * If the feed URI contains a path component, it will be used to generate a
25 * channel name by stripping the leading slash and replacing any remaining
26 * slashes with '.'. If no path component is present, the channel is set to
27 * 'rc'. If the URI contains a query string, its parameters will be parsed
28 * as RedisConnectionPool options.
29 *
30 * @example
31 * $wgRCFeeds['redis'] = array(
32 * 'formatter' => 'JSONRCFeedFormatter',
33 * 'uri' => "redis://127.0.0.1:6379/rc.$wgDBname",
34 * );
35 *
36 * @since 1.22
37 */
38 class RedisPubSubFeedEngine extends RCFeedEngine {
39
40 /**
41 * @see FormattedRCFeed::send
42 */
43 public function send( array $feed, $line ) {
44 $parsed = wfParseUrl( $feed['uri'] );
45 $server = $parsed['host'];
46 $options = [ 'serializer' => 'none' ];
47 $channel = 'rc';
48
49 if ( isset( $parsed['port'] ) ) {
50 $server .= ":{$parsed['port']}";
51 }
52 if ( isset( $parsed['query'] ) ) {
53 parse_str( $parsed['query'], $options );
54 }
55 if ( isset( $parsed['pass'] ) ) {
56 $options['password'] = $parsed['pass'];
57 }
58 if ( isset( $parsed['path'] ) ) {
59 $channel = str_replace( '/', '.', ltrim( $parsed['path'], '/' ) );
60 }
61 $pool = RedisConnectionPool::singleton( $options );
62 $conn = $pool->getConnection( $server );
63 if ( $conn !== false ) {
64 $conn->publish( $channel, $line );
65 return true;
66 } else {
67 return false;
68 }
69 }
70 }