Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / notification / controller / PhabricatorNotificationClearController.php
blob6712591e12ab5b67c621241a1670fcda364f60d0
1 <?php
3 final class PhabricatorNotificationClearController
4 extends PhabricatorNotificationController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $chrono_key = $request->getStr('chronoKey');
10 if ($request->isDialogFormPost()) {
11 $should_clear = true;
12 } else {
13 $should_clear = $request->hasCSRF();
16 if ($should_clear) {
17 $table = new PhabricatorFeedStoryNotification();
19 queryfx(
20 $table->establishConnection('w'),
21 'UPDATE %T SET hasViewed = 1 '.
22 'WHERE userPHID = %s AND hasViewed = 0 and chronologicalKey <= %s',
23 $table->getTableName(),
24 $viewer->getPHID(),
25 $chrono_key);
27 PhabricatorUserCache::clearCache(
28 PhabricatorUserNotificationCountCacheType::KEY_COUNT,
29 $viewer->getPHID());
31 return id(new AphrontReloadResponse())
32 ->setURI('/notification/');
35 $dialog = new AphrontDialogView();
36 $dialog->setUser($viewer);
37 $dialog->addCancelButton('/notification/');
38 if ($chrono_key) {
39 $dialog->setTitle(pht('Really mark all notifications as read?'));
40 $dialog->addHiddenInput('chronoKey', $chrono_key);
42 $is_serious =
43 PhabricatorEnv::getEnvConfig('phabricator.serious-business');
44 if ($is_serious) {
45 $dialog->appendChild(
46 pht(
47 'All unread notifications will be marked as read. You can not '.
48 'undo this action.'));
49 } else {
50 $dialog->appendChild(
51 pht(
52 "You can't ignore your problems forever, you know."));
55 $dialog->addSubmitButton(pht('Mark All Read'));
56 } else {
57 $dialog->setTitle(pht('No notifications to mark as read.'));
58 $dialog->appendChild(pht('You have no unread notifications.'));
61 return id(new AphrontDialogResponse())->setDialog($dialog);