diff options
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('/'); |
