From edc9a218b7d31f3318b39a2036274450b92c9d01 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 8 Jun 2024 13:34:14 -0400 Subject: [PATCH] Fix doc update-by-ID problem - Rework imports for pages - Ready for final end-to-end test before merge --- src/composer.lock | 4 +- src/lib/Feed.php | 2 - src/lib/ItemList.php | 2 +- src/public/bookmark.php | 6 +-- src/public/feed/index.php | 26 +++++------ src/public/feed/items.php | 9 ++-- src/public/feeds.php | 11 ++--- src/public/index.php | 4 +- src/public/item.php | 11 ++--- src/public/user/log-on.php | 3 +- src/start.php | 90 +++++++++++++++++--------------------- src/user-config.dist.php | 3 +- 12 files changed, 67 insertions(+), 104 deletions(-) diff --git a/src/composer.lock b/src/composer.lock index 342b234..7edaf93 100644 --- a/src/composer.lock +++ b/src/composer.lock @@ -12,7 +12,7 @@ "source": { "type": "git", "url": "https://git.bitbadger.solutions/bit-badger/pdo-document", - "reference": "2d8f8b6e8728f8fbe0d801e2bc529a678f65ad9b" + "reference": "a10ecbb1cdfdf6dd8ab3c1884b09d9ba987b7ff5" }, "require": { "ext-pdo": "*", @@ -36,7 +36,7 @@ "Test\\Integration\\SQLite\\": "./tests/integration/sqlite" } }, - "time": "2024-06-08T14:49:52+00:00" + "time": "2024-06-08T16:57:13+00:00" }, { "name": "netresearch/jsonmapper", diff --git a/src/lib/Feed.php b/src/lib/Feed.php index 32a0503..d567d76 100644 --- a/src/lib/Feed.php +++ b/src/lib/Feed.php @@ -269,9 +269,7 @@ class Feed */ public static function retrieveById(int $feedId): static|false { - define('PDO_DOC_DEBUG_SQL', true); $doc = Find::byId(Table::FEED, $feedId, static::class); - echo "Feed $feedId: " . ($doc ? 'found it' : 'not found'); return $doc && $doc->user_id == $_SESSION[Key::USER_ID] ? $doc : false; } } diff --git a/src/lib/ItemList.php b/src/lib/ItemList.php index 5874353..0a4292a 100644 --- a/src/lib/ItemList.php +++ b/src/lib/ItemList.php @@ -53,7 +53,7 @@ class ItemList $this->dbList = Custom::list( ItemWithFeed::SELECT_WITH_FEED . ' WHERE ' . Query::whereByFields(array_filter($allFields, fn($it) => $it->paramName <> ':search')) - . $searchWhere, + . "$searchWhere ORDER BY coalesce(item.data->>'updated_on', item.data->>'published_on') DESC", Parameters::addFields($allFields, []), new DocumentMapper(ItemWithFeed::class)); } catch (DocumentException $ex) { $this->error = "$ex"; diff --git a/src/public/bookmark.php b/src/public/bookmark.php index 44ddc86..14a543a 100644 --- a/src/public/bookmark.php +++ b/src/public/bookmark.php @@ -6,10 +6,8 @@ * This will display a button which will either add or remove a bookmark for a given item. */ -use BitBadger\PDODocument\DocumentException; -use BitBadger\PDODocument\Patch; -use FeedReaderCentral\ItemWithFeed; -use FeedReaderCentral\Table; +use BitBadger\PDODocument\{DocumentException, Patch}; +use FeedReaderCentral\{ItemWithFeed, Table}; include '../start.php'; diff --git a/src/public/feed/index.php b/src/public/feed/index.php index f15776a..2caaaf3 100644 --- a/src/public/feed/index.php +++ b/src/public/feed/index.php @@ -6,18 +6,14 @@ * Allows users to add, edit, and delete feeds */ -use BitBadger\PDODocument\Delete; -use BitBadger\PDODocument\DocumentException; -use BitBadger\PDODocument\Field; -use FeedReaderCentral\Feed; -use FeedReaderCentral\Security; -use FeedReaderCentral\Table; +use BitBadger\PDODocument\{Delete, DocumentException, Field}; +use FeedReaderCentral\{Feed, Security, Table}; include '../../start.php'; Security::verifyUser(); -$feedId = $_GET['id'] ?? ''; +$feedId = key_exists('id', $_GET) ? (int)$_GET['id'] : -1; if ($_SERVER['REQUEST_METHOD'] == 'DELETE') { try { @@ -37,10 +33,11 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($isNew) { $result = Feed::add($_POST['url']); } else { - $toEdit = Feed::retrieveById($_POST['id']); + $feedId = (int)$_POST['id']; + $toEdit = Feed::retrieveById($feedId); $result = $toEdit ? Feed::update($toEdit, $_POST['url']) - : ['error' => "Feed {$_POST['id']} not found"]; + : ['error' => "Feed $feedId not found"]; } if (key_exists('ok', $result)) { add_info('Feed saved successfully'); @@ -53,16 +50,13 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { } } -if ($feedId == 'new') { - $title = 'Add RSS Feed'; - $feed = new Feed(); - $feed->id = $_GET['id']; +if ($feedId == -1) { + $title = 'Add RSS Feed'; + $feed = new Feed(id: -1); } else { $title = 'Edit RSS Feed'; if ($feedId == 'error') { - $feed = new Feed(); - $feed->id = $_POST['id'] ?? ''; - $feed->url = $_POST['url'] ?? ''; + $feed = new Feed(id: (int)$_POST['id'], url: $_POST['url'] ?? ''); } elseif (!($feed = Feed::retrieveById((int)$feedId))) not_found(); } diff --git a/src/public/feed/items.php b/src/public/feed/items.php index a688cf2..2a9fd02 100644 --- a/src/public/feed/items.php +++ b/src/public/feed/items.php @@ -6,8 +6,7 @@ * Lists items in a given feed (all, unread, or bookmarked) */ -use FeedReaderCentral\Feed; -use FeedReaderCentral\ItemList; +use FeedReaderCentral\{Feed, ItemList}; include '../../start.php'; @@ -22,11 +21,11 @@ $list = match (true) { default => ItemList::allForFeed($feed->id) }; -page_head(($list->itemType != '' ? "$list->itemType Items | " : '') . strip_tags($feed['title'])); +page_head(($list->itemType != '' ? "$list->itemType Items | " : '') . strip_tags($feed->title)); if ($list->itemType == '') { - echo '

' . htmlentities($feed['title']) . '

'; + echo '

' . htmlentities($feed->title) . '

'; } else { - echo '

' . htmlentities($feed['title']) . '

'; + echo '

' . htmlentities($feed->title) . '

'; echo "
$list->itemType Items
"; } $list->render(); diff --git a/src/public/feeds.php b/src/public/feeds.php index 3506e05..2abb3a4 100644 --- a/src/public/feeds.php +++ b/src/public/feeds.php @@ -6,14 +6,9 @@ * List feeds and provide links for maintenance actions */ -use BitBadger\PDODocument\Custom; -use BitBadger\PDODocument\Field; -use BitBadger\PDODocument\Mapper\ArrayMapper; -use BitBadger\PDODocument\Mapper\DocumentMapper; -use BitBadger\PDODocument\Query; -use FeedReaderCentral\Feed; -use FeedReaderCentral\Key; -use FeedReaderCentral\Table; +use BitBadger\PDODocument\{Custom, Field, Query}; +use BitBadger\PDODocument\Mapper\{ArrayMapper, DocumentMapper}; +use FeedReaderCentral\{Feed, Key, Table}; include '../start.php'; diff --git a/src/public/index.php b/src/public/index.php index 741dada..3c9e241 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -6,8 +6,7 @@ * Displays a list of unread or bookmarked items for the current user */ -use FeedReaderCentral\Feed; -use FeedReaderCentral\ItemList; +use FeedReaderCentral\{Feed, ItemList}; include '../start.php'; @@ -21,7 +20,6 @@ if (key_exists('refresh', $_GET)) { add_error(nl2br($refreshResult['error'])); } } -//const PDO_DOC_DEBUG_SQL = true; $list = match (true) { key_exists('bookmarked', $_GET) => ItemList::allBookmarked(), diff --git a/src/public/item.php b/src/public/item.php index 0694fc5..cb90263 100644 --- a/src/public/item.php +++ b/src/public/item.php @@ -6,11 +6,8 @@ * Retrieves and displays an item from a feed belonging to the current user */ -use BitBadger\PDODocument\DocumentException; -use BitBadger\PDODocument\Delete; -use BitBadger\PDODocument\Patch; -use FeedReaderCentral\ItemWithFeed; -use FeedReaderCentral\Table; +use BitBadger\PDODocument\{Delete, DocumentException, Patch}; +use FeedReaderCentral\{ItemWithFeed, Table}; include '../start.php'; @@ -38,9 +35,7 @@ $from = $_GET['from'] ?? '/'; if ($_SERVER['REQUEST_METHOD'] == 'DELETE') { try { - if (ItemWithFeed::existsById($id)) { - Delete::byId(Table::ITEM, $id); - } + if (ItemWithFeed::existsById($id)) Delete::byId(Table::ITEM, $id); } catch (DocumentException $ex) { add_error("$ex"); } diff --git a/src/public/user/log-on.php b/src/public/user/log-on.php index 62020e5..44bc257 100644 --- a/src/public/user/log-on.php +++ b/src/public/user/log-on.php @@ -9,8 +9,7 @@ include '../../start.php'; -use FeedReaderCentral\Key; -use FeedReaderCentral\Security; +use FeedReaderCentral\{Key, Security}; Security::verifyUser(redirectIfAnonymous: false); diff --git a/src/start.php b/src/start.php index b73be31..207e9c0 100644 --- a/src/start.php +++ b/src/start.php @@ -1,8 +1,6 @@ true, 'cookie_samesite' => 'Strict']); -//const PDO_DOC_DEBUG_SQL = true; - /** * Add a message to be displayed at the top of the page * @@ -66,26 +62,25 @@ function nav_link(string $link, bool $isFirst = false): void */ function title_bar(): void { - $version = display_version(); ?> -
-
Feed Reader Central
- -
-
" + . "
Feed Reader Central$version
" + . "' + . '
'; } /** @@ -94,28 +89,24 @@ function title_bar(): void */ function page_head(string $title): void { - global $is_htmx; ?> - - - - <?=$title?> | Feed Reader Central - - - - -' + . "$title | Feed Reader Central"; + if (!$is_htmx) { + echo '' + . "" + . ''; + } + echo ''; if (!$is_htmx) title_bar(); - if (sizeof($messages = $_SESSION[Key::USER_MSG] ?? []) > 0) { ?> -
-
- {$msg['level']}
"?> - -
-
0) { + echo '
'; + array_walk($messages, function ($msg) { + echo '
' + . ($msg['level'] == 'INFO' ? '' : "{$msg['level']}
") + . $msg['message'] . '
'; + }); + echo '
'; $_SESSION[Key::USER_MSG] = []; } } @@ -125,11 +116,8 @@ function page_head(string $title): void */ function page_foot(): void { - global $is_htmx; ?> -
'; ?> - -' . ($is_htmx ? '' : '') . ''; session_commit(); } diff --git a/src/user-config.dist.php b/src/user-config.dist.php index 97066e0..117ccbe 100644 --- a/src/user-config.dist.php +++ b/src/user-config.dist.php @@ -8,8 +8,7 @@ * On initial installation, rename this file to user-config.php and configure it as desired */ -use FeedReaderCentral\Feed; -use FeedReaderCentral\Security; +use FeedReaderCentral\{Feed, Security}; /** * Which security model should the application use? Options are: