Merge "Import: Handle uploads with sha1 starting with 0 properly"
[mediawiki.git] / includes / libs / eventrelayer / EventRelayerMCRD.php
blob1e8b2a40580a7586d4f985c25ea9dab4a7b8e678
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.
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.
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
18 * @file
19 * @author Aaron Schulz
22 /**
23 * Relayed that uses the mcrelaypushd server
25 class EventRelayerMCRD extends EventRelayer {
26 /** @var MultiHttpClient */
27 protected $http;
28 /** @var string */
29 protected $baseUrl;
31 /**
32 * Additional params include 'mcrdConfig', which is a map of:
33 * - url : The base URL of the service (without paths)
34 * @param array $params
36 public function __construct( array $params ) {
37 parent::__construct( $params );
39 $this->baseUrl = $params['mcrdConfig']['url'];
41 $httpConfig = isset( $params['httpConfig'] ) ? $params['httpConfig'] : array();
42 if ( !isset( $httpConfig['connTimeout'] ) ) {
43 $httpConfig['connTimeout'] = 1;
45 if ( !isset( $httpConfig['reqTimeout'] ) ) {
46 $httpConfig['reqTimeout'] = .25;
49 $this->http = new MultiHttpClient( $httpConfig );
52 protected function doNotify( $channel, array $events ) {
53 if ( !count( $events ) ) {
54 return true;
57 $response = $this->http->run( array(
58 'url' => "{$this->baseUrl}/relayer/api/v1.0/" . rawurlencode( $channel ),
59 'method' => 'POST',
60 'body' => json_encode( array( 'events' => $events ) ),
61 'headers' => array( 'content-type' => 'application/json' )
62 ) );
64 return $response['code'] == 201;