@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare( strict_types=1 ); |
|
| 1 | +<?php declare(strict_types=1); |
|
| 2 | 2 | |
| 3 | 3 | namespace BotRiconferme\Task; |
| 4 | 4 | |
@@ -11,42 +11,42 @@ discard block |
||
| 11 | 11 | * @inheritDoc |
| 12 | 12 | */ |
| 13 | 13 | public function run() : TaskResult { |
| 14 | - $this->getLogger()->info( 'Starting task CreatePage' ); |
|
| 14 | + $this->getLogger()->info('Starting task CreatePage'); |
|
| 15 | 15 | $users = $this->getDataProvider()->getUsersToProcess(); |
| 16 | 16 | |
| 17 | - foreach ( $users as $user => $groups ) { |
|
| 18 | - $this->processUser( $user, $groups ); |
|
| 17 | + foreach ($users as $user => $groups) { |
|
| 18 | + $this->processUser($user, $groups); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - $this->getLogger()->info( 'Task CreatePage completed successfully' ); |
|
| 22 | - return new TaskResult( self::STATUS_OK ); |
|
| 21 | + $this->getLogger()->info('Task CreatePage completed successfully'); |
|
| 22 | + return new TaskResult(self::STATUS_OK); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @param string $user |
| 27 | 27 | * @param array $groups |
| 28 | 28 | */ |
| 29 | - protected function processUser( string $user, array $groups ) { |
|
| 29 | + protected function processUser(string $user, array $groups) { |
|
| 30 | 30 | try { |
| 31 | - $num = $this->getLastPageNum( $user ) + 1; |
|
| 32 | - } catch ( TaskException $e ) { |
|
| 31 | + $num = $this->getLastPageNum($user) + 1; |
|
| 32 | + } catch (TaskException $e) { |
|
| 33 | 33 | // The page was already created. |
| 34 | - $this->getDataProvider()->removeUser( $user ); |
|
| 35 | - $this->getLogger()->warning( $e->getMessage() . "\nRemoving $user." ); |
|
| 34 | + $this->getDataProvider()->removeUser($user); |
|
| 35 | + $this->getLogger()->warning($e->getMessage() . "\nRemoving $user."); |
|
| 36 | 36 | return; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - $baseTitle = $this->getConfig()->get( 'ric-main-page' ) . "/$user"; |
|
| 39 | + $baseTitle = $this->getConfig()->get('ric-main-page') . "/$user"; |
|
| 40 | 40 | $pageTitle = "$baseTitle/$num"; |
| 41 | - $this->doCreatePage( $pageTitle, $user, $groups ); |
|
| 41 | + $this->doCreatePage($pageTitle, $user, $groups); |
|
| 42 | 42 | |
| 43 | - $newText = str_replace( '$title', $pageTitle, $this->getConfig()->get( 'ric-base-page-text' ) ); |
|
| 44 | - if ( $num === 1 ) { |
|
| 45 | - $this->createBasePage( $baseTitle, $newText ); |
|
| 43 | + $newText = str_replace('$title', $pageTitle, $this->getConfig()->get('ric-base-page-text')); |
|
| 44 | + if ($num === 1) { |
|
| 45 | + $this->createBasePage($baseTitle, $newText); |
|
| 46 | 46 | } else { |
| 47 | - $this->updateBasePage( $baseTitle, $newText ); |
|
| 47 | + $this->updateBasePage($baseTitle, $newText); |
|
| 48 | 48 | } |
| 49 | - $this->getDataProvider()->addCreatedPages( $pageTitle ); |
|
| 49 | + $this->getDataProvider()->addCreatedPages($pageTitle); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | * @return int |
| 55 | 55 | * @throws TaskException |
| 56 | 56 | */ |
| 57 | - protected function getLastPageNum( string $user ) : int { |
|
| 58 | - $this->getLogger()->debug( "Retrieving previous pages for $user" ); |
|
| 59 | - $unprefixedTitle = explode( ':', $this->getConfig()->get( 'ric-main-page' ), 2 )[1]; |
|
| 57 | + protected function getLastPageNum(string $user) : int { |
|
| 58 | + $this->getLogger()->debug("Retrieving previous pages for $user"); |
|
| 59 | + $unprefixedTitle = explode(':', $this->getConfig()->get('ric-main-page'), 2)[1]; |
|
| 60 | 60 | $params = [ |
| 61 | 61 | 'action' => 'query', |
| 62 | 62 | 'list' => 'allpages', |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | 'aplimit' => 'max' |
| 66 | 66 | ]; |
| 67 | 67 | |
| 68 | - $res = ( RequestBase::newFromParams( $params ) )->execute(); |
|
| 68 | + $res = (RequestBase::newFromParams($params))->execute(); |
|
| 69 | 69 | |
| 70 | 70 | $last = 0; |
| 71 | - foreach ( $res['query']['allpages'] as $page ) { |
|
| 72 | - if ( $this->pageWasCreatedToday( $page['title'] ) ) { |
|
| 73 | - throw new TaskException( 'Page ' . $page['title'] . ' was already created.' ); |
|
| 71 | + foreach ($res['query']['allpages'] as $page) { |
|
| 72 | + if ($this->pageWasCreatedToday($page['title'])) { |
|
| 73 | + throw new TaskException('Page ' . $page['title'] . ' was already created.'); |
|
| 74 | 74 | } |
| 75 | - $bits = explode( '/', $page['title'] ); |
|
| 76 | - $cur = intval( end( $bits ) ); |
|
| 77 | - if ( is_numeric( $cur ) && $cur > $last ) { |
|
| 75 | + $bits = explode('/', $page['title']); |
|
| 76 | + $cur = intval(end($bits)); |
|
| 77 | + if (is_numeric($cur) && $cur > $last) { |
|
| 78 | 78 | $last = $cur; |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param string $title |
| 86 | 86 | * @return bool |
| 87 | 87 | */ |
| 88 | - private function pageWasCreatedToday( string $title ) : bool { |
|
| 88 | + private function pageWasCreatedToday(string $title) : bool { |
|
| 89 | 89 | $params = [ |
| 90 | 90 | 'action' => 'query', |
| 91 | 91 | 'prop' => 'revisions', |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | 'rvdir' => 'newer' |
| 97 | 97 | ]; |
| 98 | 98 | |
| 99 | - $res = ( RequestBase::newFromParams( $params ) )->execute(); |
|
| 99 | + $res = (RequestBase::newFromParams($params))->execute(); |
|
| 100 | 100 | $data = $res['query']['pages']; |
| 101 | - $time = strtotime( reset( $data )['revisions'][0]['timestamp'] ); |
|
| 102 | - return date( 'z/Y' ) === date( 'z/Y', $time ); |
|
| 101 | + $time = strtotime(reset($data)['revisions'][0]['timestamp']); |
|
| 102 | + return date('z/Y') === date('z/Y', $time); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -107,55 +107,55 @@ discard block |
||
| 107 | 107 | * @param string $user |
| 108 | 108 | * @param array $groups |
| 109 | 109 | */ |
| 110 | - protected function doCreatePage( string $title, string $user, array $groups ) { |
|
| 111 | - $this->getLogger()->info( "Creating page $title" ); |
|
| 112 | - $text = $this->getConfig()->get( 'ric-page-text' ); |
|
| 110 | + protected function doCreatePage(string $title, string $user, array $groups) { |
|
| 111 | + $this->getLogger()->info("Creating page $title"); |
|
| 112 | + $text = $this->getConfig()->get('ric-page-text'); |
|
| 113 | 113 | $textParams = [ |
| 114 | 114 | '$user' => $user, |
| 115 | 115 | '$date' => $groups['sysop'], |
| 116 | 116 | '$burocrate' => $groups['bureaucrat'] ?? '', |
| 117 | 117 | '$checkuser' => $groups['checkuser'] ?? '' |
| 118 | 118 | ]; |
| 119 | - $text = strtr( $text, $textParams ); |
|
| 119 | + $text = strtr($text, $textParams); |
|
| 120 | 120 | |
| 121 | 121 | $params = [ |
| 122 | 122 | 'title' => $title, |
| 123 | 123 | 'text' => $text, |
| 124 | - 'summary' => $this->getConfig()->get( 'ric-page-summary' ) |
|
| 124 | + 'summary' => $this->getConfig()->get('ric-page-summary') |
|
| 125 | 125 | ]; |
| 126 | 126 | |
| 127 | - $this->getController()->editPage( $params ); |
|
| 127 | + $this->getController()->editPage($params); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * @param string $title |
| 132 | 132 | * @param string $newText |
| 133 | 133 | */ |
| 134 | - protected function createBasePage( string $title, string $newText ) { |
|
| 135 | - $this->getLogger()->info( "Creating base page $title" ); |
|
| 134 | + protected function createBasePage(string $title, string $newText) { |
|
| 135 | + $this->getLogger()->info("Creating base page $title"); |
|
| 136 | 136 | |
| 137 | 137 | $params = [ |
| 138 | 138 | 'title' => $title, |
| 139 | 139 | 'text' => $newText, |
| 140 | - 'summary' => $this->getConfig()->get( 'ric-base-page-summary' ) |
|
| 140 | + 'summary' => $this->getConfig()->get('ric-base-page-summary') |
|
| 141 | 141 | ]; |
| 142 | 142 | |
| 143 | - $this->getController()->editPage( $params ); |
|
| 143 | + $this->getController()->editPage($params); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | 147 | * @param string $title |
| 148 | 148 | * @param string $newText |
| 149 | 149 | */ |
| 150 | - protected function updateBasePage( string $title, string $newText ) { |
|
| 151 | - $this->getLogger()->info( "Updating base page $title" ); |
|
| 150 | + protected function updateBasePage(string $title, string $newText) { |
|
| 151 | + $this->getLogger()->info("Updating base page $title"); |
|
| 152 | 152 | |
| 153 | 153 | $params = [ |
| 154 | 154 | 'title' => $title, |
| 155 | 155 | 'appendtext' => $newText, |
| 156 | - 'summary' => $this->getConfig()->get( 'ric-base-page-summary-update' ) |
|
| 156 | + 'summary' => $this->getConfig()->get('ric-base-page-summary-update') |
|
| 157 | 157 | ]; |
| 158 | 158 | |
| 159 | - $this->getController()->editPage( $params ); |
|
| 159 | + $this->getController()->editPage($params); |
|
| 160 | 160 | } |
| 161 | 161 | } |