|
1
|
|
|
<?php declare( strict_types=1 ); |
|
2
|
|
|
|
|
3
|
|
|
namespace BotRiconferme\Task\Subtask; |
|
4
|
|
|
|
|
5
|
|
|
use BotRiconferme\TaskResult; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Notify the affected users |
|
9
|
|
|
*/ |
|
10
|
|
|
class UserNotice extends Subtask { |
|
11
|
|
|
/** |
|
12
|
|
|
* @inheritDoc |
|
13
|
|
|
*/ |
|
14
|
|
|
public function run() : TaskResult { |
|
15
|
|
|
$this->getLogger()->info( 'Starting task UserNotice' ); |
|
16
|
|
|
|
|
17
|
|
|
$pages = $this->getDataProvider()->getCreatedPages(); |
|
18
|
|
|
$users = $this->getDataProvider()->getUsersToProcess(); |
|
19
|
|
|
if ( $pages && $users ) { |
|
20
|
|
|
$ricNums = []; |
|
21
|
|
|
foreach ( $pages as $page ) { |
|
22
|
|
|
$ricNums[ $page->getUser() ] = $page->getNum(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
foreach ( $users as $user => $_ ) { |
|
26
|
|
|
$this->addMsg( $user, $ricNums[ $user ] ); |
|
27
|
|
|
} |
|
28
|
|
|
} else { |
|
29
|
|
|
$this->getLogger()->info( 'No messages to leave.' ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->getLogger()->info( 'Task UserNotice completed successfully' ); |
|
33
|
|
|
return new TaskResult( self::STATUS_OK ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Leaves a message to the talk page |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $user |
|
40
|
|
|
* @param int $ricNum |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function addMsg( string $user, int $ricNum ) { |
|
43
|
|
|
$this->getLogger()->info( "Leaving msg to $user" ); |
|
44
|
|
|
$msg = $this->msg( 'user-notice-msg' )->params( [ '$num' => $ricNum ] )->text(); |
|
45
|
|
|
|
|
46
|
|
|
$params = [ |
|
47
|
|
|
'title' => "User talk:$user", |
|
48
|
|
|
'section' => 'new', |
|
49
|
|
|
'text' => $msg, |
|
50
|
|
|
'sectiontitle' => $this->getConfig()->get( 'user-notice-title' ), |
|
51
|
|
|
'summary' => $this->getConfig()->get( 'user-notice-summary' ) |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
$this->getController()->editPage( $params ); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|