Skip to content

Commit 8206e8d

Browse files
committed
Added support for request restore with ajax
1 parent 190f630 commit 8206e8d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Application/UI/Presenter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ public function storeRequest($expiration = '+ 10 minutes')
10921092
$key = Nette\Utils\Random::generate(5);
10931093
} while (isset($session[$key]));
10941094

1095-
$session[$key] = [$this->getUser()->getId(), $this->request];
1095+
$session[$key] = [$this->getUser()->getId(), $this->request, (string) $this->httpRequest->getUrl()];
10961096
$session->setExpiration($expiration, $key);
10971097
return $key;
10981098
}
@@ -1110,7 +1110,11 @@ public function restoreRequest($key)
11101110
return;
11111111
}
11121112
$request = clone $session[$key][1];
1113+
$url = $session[$key][2];
11131114
unset($session[$key]);
1115+
if($this->isAjax()) {
1116+
$this->redirectUrl($url);
1117+
}
11141118
$request->setFlag(Application\Request::RESTORED, TRUE);
11151119
$params = $request->getParameters();
11161120
$params[self::FLASH_KEY] = $this->getParameter(self::FLASH_KEY);

tests/UI/Presenter.storeRequest().phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ class MockUser extends Security\User
8383

8484

8585
$presenter = new TestPresenter();
86+
$url = 'http://www.example.org/foo/bar';
87+
$urlScript = new Http\UrlScript($url);
8688
$presenter->injectPrimary(
8789
NULL,
8890
NULL,
8991
new Application\Routers\SimpleRouter,
90-
new Http\Request(new Http\UrlScript),
92+
new Http\Request($urlScript),
9193
new Http\Response,
9294
$session = new MockSession,
9395
$user = new MockUser
@@ -105,4 +107,4 @@ Assert::same($expiration, $section->testExpiration);
105107
Assert::same($key, $section->testExpirationVariables);
106108
Assert::same($key, $section->testedKeyExistence);
107109
Assert::same($key, $section->storedKey);
108-
Assert::same([$user->getId(), $applicationRequest], $section->storedValue);
110+
Assert::same([$user->getId(), $applicationRequest, $url], $section->storedValue);

0 commit comments

Comments
 (0)