Cicalese has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/359505 )
Change subject: Move Echo notofication creation into a job. ...................................................................... Move Echo notofication creation into a job. T167446 Change-Id: I779a2c4bf6d5e43b5e4a01c3c4e9ef0a054b3252 --- M extension.json M includes/ApiCSPostComment.php A includes/CommentStreamsNotificationJob.php 3 files changed, 155 insertions(+), 33 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommentStreams refs/changes/05/359505/1 diff --git a/extension.json b/extension.json index 6cc58b6..1d05291 100644 --- a/extension.json +++ b/extension.json @@ -78,6 +78,9 @@ "localBasePath": "resources", "remoteExtPath": "CommentStreams/resources" }, + "JobClasses": { + "commentstreams": "CommentStreamsNotificationJob" + }, "AutoloadClasses": { "CommentStreamsHooks": "includes/CommentStreamsHooks.php", "CommentStreams": "includes/CommentStreams.php", @@ -88,6 +91,8 @@ "ApiCSEditComment": "includes/ApiCSEditComment.php", "ApiCSDeleteComment": "includes/ApiCSDeleteComment.php", "ApiCSVote": "includes/ApiCSVote.php", + "CommentStreamsNotificationJob": + "includes/CommentStreamsNotificationJob.php", "EchoCSFormatter": "includes/EchoCSFormatter.php", "EchoCSReplyPresentationModel": "includes/EchoCSReplyPresentationModel.php", "EchoCSWatchedPresentationModel": diff --git a/includes/ApiCSPostComment.php b/includes/ApiCSPostComment.php index c00b7bc..8983066 100644 --- a/includes/ApiCSPostComment.php +++ b/includes/ApiCSPostComment.php @@ -1,6 +1,6 @@ <?php /* - * Copyright (c) 2016 The MITRE Corporation + * Copyright (c) 2017 The MITRE Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -130,10 +130,13 @@ return; } + $params = []; + $parent_id = $comment->getParentId(); if ( is_null( $parent_id ) ) { - $comment_title = $comment->getCommentTitle(); + $params['comment_title'] = $comment->getCommentTitle(); } else { + $params['parent_id'] = $parent_id; $parent_page = WikiPage::newFromId( $parent_id ); if ( is_null( $parent_page ) ) { return; @@ -141,10 +144,14 @@ $parent_comment = Comment::newFromWikiPage( $parent_page ); if ( is_null( $parent_comment ) ) { return; - } else { - $comment_title = $parent_comment->getCommentTitle(); } + $params['comment_title'] = $parent_comment->getCommentTitle(); } + + $params['comment_id'] = $comment->getId(); + $params['comment_author_username'] = $comment->getUsername(); + $params['comment_author_display_name'] = + $comment->getUserDisplayNameUnlinked(); $associated_page_display_title = $associated_page->getTitle()->getPrefixedText(); @@ -157,37 +164,18 @@ $values[$associated_title->getArticleID()]; } } + $params['associated_page_display_title'] = $associated_page_display_title; - $extra = [ - 'comment' => $comment->getId(), - 'comment_author_username' => $comment->getUsername(), - 'comment_author_display_name' => $comment->getUserDisplayNameUnlinked(), - 'comment_title' => $comment_title, - 'associated_page_display_title' => $associated_page_display_title, - 'comment_wikitext' => $comment->getWikitext() - ]; + $params['comment_wikitext'] = $comment->getWikitext(); - if ( !is_null( $parent_id ) ) { - EchoEvent::create( [ - 'type' => 'commentstreams-reply-on-watched-page', - 'title' => $associated_page->getTitle(), - 'extra' => $extra, - 'agent' => $this->getUser() - ] ); - EchoEvent::create( [ - 'type' => 'commentstreams-reply-to-author', - 'title' => $associated_page->getTitle(), - 'extra' => $extra, - 'agent' => $this->getUser() - ] ); - } else { - EchoEvent::create( [ - 'type' => 'commentstreams-comment-on-watched-page', - 'title' => $associated_page->getTitle(), - 'extra' => $extra, - 'agent' => $this->getUser() - ] ); - } + $params['associated_page_id'] = + $associated_page->getTitle()->getArticleId(); + $params['user_id'] = $this->getUser()->getId(); + + $jobs = []; + $jobs[] = new CommentStreamsNotificationJob( + $comment->getWikiPage()->getTitle(), $params ); + JobQueueGroup::singleton()->push( $jobs ); } /** diff --git a/includes/CommentStreamsNotificationJob.php b/includes/CommentStreamsNotificationJob.php new file mode 100644 index 0000000..6861f2a --- /dev/null +++ b/includes/CommentStreamsNotificationJob.php @@ -0,0 +1,129 @@ +<?php +/* + * Copyright (c) 2017 The MITRE Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +class CommentStreamsNotificationJob extends Job { + + function __construct( $title, $params = '', $id = 0 ) { + parent::__construct( 'commentstreams', $title, $params, $id ); + } + + /** + * Send Echo notifications + * + * @return boolean success + */ + public function run() { +wfDebug("RUN!"); + + if ( is_null( $this->title ) ) { + $this->error = "commentstreams: Invalid title"; + return false; + } + + $extra = []; + + if ( !array_key_exists( 'comment_title', $this->params ) ) { + $this->error = "commentstreams: Missing comment title"; + return false; + } + $extra['comment_title'] = $this->params['comment_title']; + + if ( !array_key_exists( 'comment_id', $this->params ) ) { + $this->error = "commentstreams: Missing comment id"; + return false; + } + $extra['comment_id'] = $this->params['comment_id']; + + if ( !array_key_exists( 'comment_author_username', $this->params ) ) { + $this->error = "commentstreams: Missing comment author username"; + return false; + } + $extra['comment_author_username'] = + $this->params['comment_author_username']; + + if ( !array_key_exists( 'comment_author_display_name', $this->params ) ) { + $this->error = "commentstreams: Missing comment author display name"; + return false; + } + $extra['comment_author_display_name'] = + $this->params['comment_author_display_name']; + + if ( !array_key_exists( 'associated_page_display_title', $this->params ) ) { + $this->error = "commentstreams: Missing associated page display title"; + return false; + } + $extra['associated_page_display_title'] = + $this->params['associated_page_display_title']; + + if ( !array_key_exists( 'comment_wikitext', $this->params ) ) { + $this->error = "commentstreams: Missing comment wikitext"; + return false; + } + $extra['comment_wikitext'] = $this->params['comment_wikitext']; + + if ( !array_key_exists( 'associated_page_id', $this->params ) ) { + $this->error = "commentstreams: Missing associated page id"; + return false; + } + $associated_page = Title::newFromID( $this->params['associated_page_id'] ); + + if ( !array_key_exists( 'user_id', $this->params ) ) { + $this->error = "commentstreams: Missing user id"; + return false; + } + $user = User::newFromID( $this->params['user_id'] ); + +wfDebug("NOTIFYING"); +wfDebug("ASSOC PAGE: " . $associated_page); +wfDebug("User: " . print_r($user, true)); +wfDebug("Username: " . $user->getName()); +wfDebug("Extra: " . print_r($extra, true)); + if ( array_key_exists( 'parent_id', $this->params ) ) { +wfDebug("A"); + EchoEvent::create( [ + 'type' => 'commentstreams-reply-on-watched-page', + 'title' => $associated_page, + 'extra' => $extra, + 'agent' => $user + ] ); +wfDebug("B"); + EchoEvent::create( [ + 'type' => 'commentstreams-reply-to-author', + 'title' => $associated_page, + 'extra' => $extra, + 'agent' => $user + ] ); +wfDebug("C"); + } else { +wfDebug("D"); + EchoEvent::create( [ + 'type' => 'commentstreams-comment-on-watched-page', + 'title' => $associated_page, + 'extra' => $extra, + 'agent' => $user + ] ); +wfDebug("E"); + } +wfDebug("F"); + } +} -- To view, visit https://gerrit.wikimedia.org/r/359505 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I779a2c4bf6d5e43b5e4a01c3c4e9ef0a054b3252 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CommentStreams Gerrit-Branch: master Gerrit-Owner: Cicalese <cical...@mitre.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits