| Conditions | 21 |
| Paths | 50 |
| Total Lines | 105 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 26 | public function sendBulk($page) |
||
| 27 | { |
||
| 28 | $subscriberManager = new SubscriberManager(); |
||
| 29 | if (!$subscriberManager->isenabled()) { |
||
| 30 | return 0; |
||
| 31 | } |
||
| 32 | |||
| 33 | /** @var DokuWiki_Auth_Plugin $auth */ |
||
| 34 | global $auth; |
||
| 35 | global $conf; |
||
| 36 | global $USERINFO; |
||
| 37 | /** @var Input $INPUT */ |
||
| 38 | global $INPUT; |
||
| 39 | $count = 0; |
||
| 40 | |||
| 41 | $subscriptions = $subscriberManager->subscribers($page, null, ['digest', 'list']); |
||
| 42 | |||
| 43 | // remember current user info |
||
| 44 | $olduinfo = $USERINFO; |
||
| 45 | $olduser = $INPUT->server->str('REMOTE_USER'); |
||
| 46 | |||
| 47 | foreach ($subscriptions as $target => $users) { |
||
| 48 | if (!$this->lock($target)) { |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | |||
| 52 | foreach ($users as $user => $info) { |
||
| 53 | list($style, $lastupdate) = $info; |
||
| 54 | |||
| 55 | $lastupdate = (int)$lastupdate; |
||
| 56 | if ($lastupdate + $conf['subscribe_time'] > time()) { |
||
| 57 | // Less than the configured time period passed since last |
||
| 58 | // update. |
||
| 59 | continue; |
||
| 60 | } |
||
| 61 | |||
| 62 | // Work as the user to make sure ACLs apply correctly |
||
| 63 | $USERINFO = $auth->getUserData($user); |
||
| 64 | $INPUT->server->set('REMOTE_USER', $user); |
||
| 65 | if ($USERINFO === false) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | if (!$USERINFO['mail']) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | |||
| 72 | if (substr($target, -1, 1) === ':') { |
||
| 73 | // subscription target is a namespace, get all changes within |
||
| 74 | $changes = getRecentsSince($lastupdate, null, getNS($target)); |
||
|
|
|||
| 75 | } else { |
||
| 76 | // single page subscription, check ACL ourselves |
||
| 77 | if (auth_quickaclcheck($target) < AUTH_READ) { |
||
| 78 | continue; |
||
| 79 | } |
||
| 80 | $meta = p_get_metadata($target); |
||
| 81 | $changes = [$meta['last_change']]; |
||
| 82 | } |
||
| 83 | |||
| 84 | // Filter out pages only changed in small and own edits |
||
| 85 | $change_ids = []; |
||
| 86 | foreach ($changes as $rev) { |
||
| 87 | $n = 0; |
||
| 88 | while (!is_null($rev) && $rev['date'] >= $lastupdate && |
||
| 89 | ($INPUT->server->str('REMOTE_USER') === $rev['user'] || |
||
| 90 | $rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) { |
||
| 91 | $pagelog = new PageChangeLog($rev['id']); |
||
| 92 | $rev = $pagelog->getRevisions($n++, 1); |
||
| 93 | $rev = (count($rev) > 0) ? $rev[0] : null; |
||
| 94 | } |
||
| 95 | |||
| 96 | if (!is_null($rev) && $rev['date'] >= $lastupdate) { |
||
| 97 | // Some change was not a minor one and not by myself |
||
| 98 | $change_ids[] = $rev['id']; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | // send it |
||
| 103 | if ($style === 'digest') { |
||
| 104 | foreach ($change_ids as $change_id) { |
||
| 105 | $this->sendDigest( |
||
| 106 | $USERINFO['mail'], |
||
| 107 | $change_id, |
||
| 108 | $lastupdate |
||
| 109 | ); |
||
| 110 | $count++; |
||
| 111 | } |
||
| 112 | } else { |
||
| 113 | if ($style === 'list') { |
||
| 114 | $this->sendList($USERINFO['mail'], $change_ids, $target); |
||
| 115 | $count++; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | // TODO: Handle duplicate subscriptions. |
||
| 119 | |||
| 120 | // Update notification time. |
||
| 121 | $subscriberManager->add($target, $user, $style, time()); |
||
| 122 | } |
||
| 123 | $this->unlock($target); |
||
| 124 | } |
||
| 125 | |||
| 126 | // restore current user info |
||
| 127 | $USERINFO = $olduinfo; |
||
| 128 | $INPUT->server->set('REMOTE_USER', $olduser); |
||
| 129 | return $count; |
||
| 130 | } |
||
| 131 | |||
| 262 |