Use auto IDs; drop to PHP 8.2
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\{
|
||||
Configuration, Custom, DocumentException, DocumentList, Exists, Field, Find, Parameters, Patch, Query
|
||||
Configuration, Custom, Document, DocumentException, DocumentList, Exists, Field, Find, Parameters, Patch, Query
|
||||
};
|
||||
use DateTimeInterface;
|
||||
|
||||
@@ -15,16 +15,16 @@ class Feed
|
||||
// ***** CONSTANTS *****
|
||||
|
||||
/** @var int Do not purge items */
|
||||
public const int PURGE_NONE = 0;
|
||||
public const PURGE_NONE = 0;
|
||||
|
||||
/** @var int Purge all read items (will not purge unread items) */
|
||||
public const int PURGE_READ = 1;
|
||||
public const PURGE_READ = 1;
|
||||
|
||||
/** @var int Purge items older than the specified number of days */
|
||||
public const int PURGE_BY_DAYS = 2;
|
||||
public const PURGE_BY_DAYS = 2;
|
||||
|
||||
/** @var int Purge items in number greater than the specified number of items to keep */
|
||||
public const int PURGE_BY_COUNT = 3;
|
||||
public const PURGE_BY_COUNT = 3;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -187,10 +187,7 @@ class Feed
|
||||
return ['error' => "Already subscribed to feed $feed->url"];
|
||||
}
|
||||
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
INSERT INTO feed (data)
|
||||
VALUES (json_set(:data, '$.id', (SELECT coalesce(max(data->>'id'), 0) + 1 FROM feed)))
|
||||
SQL, Parameters::json(':data', self::fromParsed($feed)));
|
||||
Document::insert(Table::FEED, self::fromParsed($feed));
|
||||
|
||||
$doc = Find::firstByFields(Table::FEED, $fields, static::class);
|
||||
if (!$doc) return ['error' => 'Could not retrieve inserted feed'];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\{Custom, DocumentException, Parameters, Patch};
|
||||
use BitBadger\PDODocument\{Document, DocumentException, Patch};
|
||||
|
||||
/**
|
||||
* An item from a feed
|
||||
@@ -57,17 +57,14 @@ class Item
|
||||
*/
|
||||
public static function add(int $feedId, ParsedItem $parsed): void
|
||||
{
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
INSERT INTO item (data)
|
||||
VALUES (json_set(:data, '$.id', (SELECT coalesce(max(data->>'id'), 0) + 1 FROM item)))
|
||||
SQL, Parameters::json(':data', new static(
|
||||
feed_id: $feedId,
|
||||
title: $parsed->title,
|
||||
item_guid: $parsed->guid,
|
||||
item_link: $parsed->link,
|
||||
published_on: $parsed->publishedOn,
|
||||
updated_on: $parsed->updatedOn,
|
||||
content: $parsed->content)));
|
||||
Document::insert(Table::ITEM, new static(
|
||||
feed_id: $feedId,
|
||||
title: $parsed->title,
|
||||
item_guid: $parsed->guid,
|
||||
item_link: $parsed->link,
|
||||
published_on: $parsed->publishedOn,
|
||||
updated_on: $parsed->updatedOn,
|
||||
content: $parsed->content));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,11 +11,11 @@ use BitBadger\PDODocument\Mapper\{DocumentMapper, ExistsMapper};
|
||||
class ItemWithFeed extends Item
|
||||
{
|
||||
/** @var string The body of the `FROM` clause to join item and feed */
|
||||
public const string FROM_WITH_JOIN = Table::ITEM . ' INNER JOIN ' . Table::FEED
|
||||
public const FROM_WITH_JOIN = Table::ITEM . ' INNER JOIN ' . Table::FEED
|
||||
. ' ON ' . Table::ITEM . ".data->>'feed_id' = " . Table::FEED . ".data->>'id'";
|
||||
|
||||
/** @var string The `SELECT` clause to add the feed as a property to the item's document */
|
||||
public const string SELECT_WITH_FEED =
|
||||
public const SELECT_WITH_FEED =
|
||||
'SELECT json_set(' . Table::ITEM . ".data, '$.feed', json(" . Table::FEED . '.data)) AS data FROM '
|
||||
. self::FROM_WITH_JOIN;
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace FeedReaderCentral;
|
||||
class Key {
|
||||
|
||||
/** @var string The $_SESSION key for the current user's e-mail address */
|
||||
public const string USER_EMAIL = 'FRC_USER_EMAIL';
|
||||
public const USER_EMAIL = 'FRC_USER_EMAIL';
|
||||
|
||||
/** @var string The $_SESSION key for the current user's ID */
|
||||
public const string USER_ID = 'FRC_USER_ID';
|
||||
public const USER_ID = 'FRC_USER_ID';
|
||||
|
||||
/** @var string The $_REQUEST key for the array of user messages to display */
|
||||
public const string USER_MSG = 'FRC_USER_MSG';
|
||||
public const USER_MSG = 'FRC_USER_MSG';
|
||||
}
|
||||
|
||||
@@ -22,16 +22,16 @@ class ParsedFeed
|
||||
public array $items = [];
|
||||
|
||||
/** @var string The XML namespace for Atom feeds */
|
||||
public const string ATOM_NS = 'http://www.w3.org/2005/Atom';
|
||||
public const ATOM_NS = 'http://www.w3.org/2005/Atom';
|
||||
|
||||
/** @var string The XML namespace for the `<content:encoded>` tag that allows HTML content in a feed */
|
||||
public const string CONTENT_NS = 'http://purl.org/rss/1.0/modules/content/';
|
||||
public const CONTENT_NS = 'http://purl.org/rss/1.0/modules/content/';
|
||||
|
||||
/** @var string The XML namespace for XHTML */
|
||||
public const string XHTML_NS = 'http://www.w3.org/1999/xhtml';
|
||||
public const XHTML_NS = 'http://www.w3.org/1999/xhtml';
|
||||
|
||||
/** @var string The user agent for Feed Reader Central's refresh requests */
|
||||
private const string USER_AGENT =
|
||||
private const USER_AGENT =
|
||||
'FeedReaderCentral/' . FRC_VERSION . ' +https://bitbadger.solutions/open-source/feed-reader-central';
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\DocumentException;
|
||||
use BitBadger\PDODocument\Field;
|
||||
use BitBadger\PDODocument\Patch;
|
||||
use BitBadger\PDODocument\{DocumentException, Field, Patch};
|
||||
|
||||
/**
|
||||
* Security functions
|
||||
@@ -12,22 +10,22 @@ use BitBadger\PDODocument\Patch;
|
||||
class Security
|
||||
{
|
||||
/** @var int Run as a single user requiring no password */
|
||||
public const int SINGLE_USER = 0;
|
||||
public const SINGLE_USER = 0;
|
||||
|
||||
/** @var int Run as a single user requiring a password */
|
||||
public const int SINGLE_USER_WITH_PASSWORD = 1;
|
||||
public const SINGLE_USER_WITH_PASSWORD = 1;
|
||||
|
||||
/** @var int Require users to provide e-mail address and password */
|
||||
public const int MULTI_USER = 2;
|
||||
public const MULTI_USER = 2;
|
||||
|
||||
/** @var string The e-mail address for the single user */
|
||||
public const string SINGLE_USER_EMAIL = 'solouser@example.com';
|
||||
public const SINGLE_USER_EMAIL = 'solouser@example.com';
|
||||
|
||||
/** @var string The password for the single user with no password */
|
||||
public const string SINGLE_USER_PASSWORD = 'no-password-required';
|
||||
public const SINGLE_USER_PASSWORD = 'no-password-required';
|
||||
|
||||
/** @var string The password algorithm to use for our passwords */
|
||||
public const string PW_ALGORITHM = PASSWORD_DEFAULT;
|
||||
public const PW_ALGORITHM = PASSWORD_DEFAULT;
|
||||
|
||||
/**
|
||||
* Verify a user's password
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace FeedReaderCentral;
|
||||
class Table
|
||||
{
|
||||
/** @var string The user table */
|
||||
public const string USER = 'frc_user';
|
||||
public const USER = 'frc_user';
|
||||
|
||||
/** @var string The feed table */
|
||||
public const string FEED = 'feed';
|
||||
public const FEED = 'feed';
|
||||
|
||||
/** @var string The item table */
|
||||
public const string ITEM = 'item';
|
||||
public const ITEM = 'item';
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\{Custom, DocumentException, Field, Find, Parameters, Query};
|
||||
use BitBadger\PDODocument\{Custom, Document, DocumentException, Field, Find, Parameters, Query};
|
||||
use BitBadger\PDODocument\Mapper\ExistsMapper;
|
||||
|
||||
/**
|
||||
@@ -40,10 +40,7 @@ class User
|
||||
*/
|
||||
public static function add(string $email, string $password): void
|
||||
{
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
INSERT INTO user (data)
|
||||
VALUES (json_set(:data, '$.id', (SELECT coalesce(max(data->>'id'), 0) + 1 FROM user)))
|
||||
SQL, Parameters::json(':data', new User(email: $email, password: $password)));
|
||||
Document::insert(Table::USER, new User(email: $email, password: $password));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user