diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-13 21:51:07 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-13 21:51:07 +0100 |
| commit | cbaedbc5251f3b127bd81242d1344c0cd3e56e0c (patch) | |
| tree | f76273742992d8f06983fd5d6fef37efc85a2c07 /public/update/index.php | |
| parent | 2ab5661583d74b03c86bb4f437616bb634d9c4fc (diff) | |
Implemente redirects
Diffstat (limited to 'public/update/index.php')
| -rw-r--r-- | public/update/index.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/public/update/index.php b/public/update/index.php new file mode 100644 index 0000000..fa6b482 --- /dev/null +++ b/public/update/index.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +use DTS\BookmarkRepository; +use function DTS\Functions\respondAndExit; +use function DTS\Functions\redirectAndExit; + +require_once(__DIR__.'/../../autoload.php'); + +$config = require_once(__DIR__.'/../../config.php'); + +if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') { + respondAndExit(405, 'Method Not Allowed'); +} + +$id = filter_input(INPUT_POST, 'id'); + +$bookmarks = new BookmarkRepository($config['path_to_repository']); + +$bookmark = $bookmarks->find($id); + +if ($bookmark === null) { + respondAndExit(404, 'Not Found'); +} + +$bookmark->url = $_POST['url']; +$bookmark->title = $_POST['title']; +$bookmark->tag = $_POST['tag']; + +if (!$bookmarks->update($bookmark)) { + respondAndExit(500, 'Internal Server Error'); +} + +redirectAndExit('/'); |
