Use auto IDs; drop to PHP 8.2
This commit is contained in:
parent
08fd589481
commit
3cafb318dc
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/** The current Feed Reader Central version */
|
/** The current Feed Reader Central version */
|
||||||
|
|
||||||
use BitBadger\PDODocument\Configuration;
|
use BitBadger\PDODocument\{AutoId, Configuration};
|
||||||
use FeedReaderCentral\Data;
|
use FeedReaderCentral\Data;
|
||||||
|
|
||||||
const FRC_VERSION = '1.0.0-beta1';
|
const FRC_VERSION = '1.0.0-beta1';
|
||||||
|
@ -27,6 +27,7 @@ require __DIR__ . '/vendor/autoload.php';
|
||||||
require 'user-config.php';
|
require 'user-config.php';
|
||||||
|
|
||||||
Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', DATABASE_NAME]);
|
Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', DATABASE_NAME]);
|
||||||
|
Configuration::$autoId = AutoId::Number;
|
||||||
Data::ensureDb();
|
Data::ensureDb();
|
||||||
|
|
||||||
/** @var string The date the world wide web was created */
|
/** @var string The date the world wide web was created */
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"name": "bit-badger/feed-reader-central",
|
"name": "bit-badger/feed-reader-central",
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"require": {
|
"require": {
|
||||||
|
"php": ">=8.2",
|
||||||
"bit-badger/pdo-document": "^1",
|
"bit-badger/pdo-document": "^1",
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
|
|
11
src/composer.lock
generated
11
src/composer.lock
generated
|
@ -4,20 +4,20 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "f074a197e429ac24507becc14e0d99c3",
|
"content-hash": "4f0add59e384feb6787acf3685c9e031",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "bit-badger/pdo-document",
|
"name": "bit-badger/pdo-document",
|
||||||
"version": "v1.0.0-alpha1",
|
"version": "v1.0.0-alpha2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.bitbadger.solutions/bit-badger/pdo-document",
|
"url": "https://git.bitbadger.solutions/bit-badger/pdo-document",
|
||||||
"reference": "f784f3e52cc1e4691fa347eefc82a2e4587c7f38"
|
"reference": "330e27218756df8b93081a17dead8aaec789b071"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
"netresearch/jsonmapper": "^4",
|
"netresearch/jsonmapper": "^4",
|
||||||
"php": ">=8.3"
|
"php": ">=8.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^11"
|
"phpunit/phpunit": "^11"
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
"rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss",
|
"rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss",
|
||||||
"source": "https://git.bitbadger.solutions/bit-badger/pdo-document"
|
"source": "https://git.bitbadger.solutions/bit-badger/pdo-document"
|
||||||
},
|
},
|
||||||
"time": "2024-06-08T23:58:45+00:00"
|
"time": "2024-06-11T11:07:56+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "netresearch/jsonmapper",
|
"name": "netresearch/jsonmapper",
|
||||||
|
@ -115,6 +115,7 @@
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
|
"php": ">=8.2",
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace FeedReaderCentral;
|
namespace FeedReaderCentral;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{
|
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;
|
use DateTimeInterface;
|
||||||
|
|
||||||
|
@ -15,16 +15,16 @@ class Feed
|
||||||
// ***** CONSTANTS *****
|
// ***** CONSTANTS *****
|
||||||
|
|
||||||
/** @var int Do not purge items */
|
/** @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) */
|
/** @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 */
|
/** @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 */
|
/** @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
|
* Constructor
|
||||||
|
@ -187,10 +187,7 @@ class Feed
|
||||||
return ['error' => "Already subscribed to feed $feed->url"];
|
return ['error' => "Already subscribed to feed $feed->url"];
|
||||||
}
|
}
|
||||||
|
|
||||||
Custom::nonQuery(<<<'SQL'
|
Document::insert(Table::FEED, self::fromParsed($feed));
|
||||||
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)));
|
|
||||||
|
|
||||||
$doc = Find::firstByFields(Table::FEED, $fields, static::class);
|
$doc = Find::firstByFields(Table::FEED, $fields, static::class);
|
||||||
if (!$doc) return ['error' => 'Could not retrieve inserted feed'];
|
if (!$doc) return ['error' => 'Could not retrieve inserted feed'];
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace FeedReaderCentral;
|
namespace FeedReaderCentral;
|
||||||
|
|
||||||
use BitBadger\PDODocument\{Custom, DocumentException, Parameters, Patch};
|
use BitBadger\PDODocument\{Document, DocumentException, Patch};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An item from a feed
|
* An item from a feed
|
||||||
|
@ -57,17 +57,14 @@ class Item
|
||||||
*/
|
*/
|
||||||
public static function add(int $feedId, ParsedItem $parsed): void
|
public static function add(int $feedId, ParsedItem $parsed): void
|
||||||
{
|
{
|
||||||
Custom::nonQuery(<<<'SQL'
|
Document::insert(Table::ITEM, new static(
|
||||||
INSERT INTO item (data)
|
feed_id: $feedId,
|
||||||
VALUES (json_set(:data, '$.id', (SELECT coalesce(max(data->>'id'), 0) + 1 FROM item)))
|
title: $parsed->title,
|
||||||
SQL, Parameters::json(':data', new static(
|
item_guid: $parsed->guid,
|
||||||
feed_id: $feedId,
|
item_link: $parsed->link,
|
||||||
title: $parsed->title,
|
published_on: $parsed->publishedOn,
|
||||||
item_guid: $parsed->guid,
|
updated_on: $parsed->updatedOn,
|
||||||
item_link: $parsed->link,
|
content: $parsed->content));
|
||||||
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
|
class ItemWithFeed extends Item
|
||||||
{
|
{
|
||||||
/** @var string The body of the `FROM` clause to join item and feed */
|
/** @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'";
|
. ' 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 */
|
/** @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 '
|
'SELECT json_set(' . Table::ITEM . ".data, '$.feed', json(" . Table::FEED . '.data)) AS data FROM '
|
||||||
. self::FROM_WITH_JOIN;
|
. self::FROM_WITH_JOIN;
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@ namespace FeedReaderCentral;
|
||||||
class Key {
|
class Key {
|
||||||
|
|
||||||
/** @var string The $_SESSION key for the current user's e-mail address */
|
/** @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 */
|
/** @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 */
|
/** @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 = [];
|
public array $items = [];
|
||||||
|
|
||||||
/** @var string The XML namespace for Atom feeds */
|
/** @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 */
|
/** @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 */
|
/** @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 */
|
/** @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';
|
'FeedReaderCentral/' . FRC_VERSION . ' +https://bitbadger.solutions/open-source/feed-reader-central';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
namespace FeedReaderCentral;
|
namespace FeedReaderCentral;
|
||||||
|
|
||||||
use BitBadger\PDODocument\DocumentException;
|
use BitBadger\PDODocument\{DocumentException, Field, Patch};
|
||||||
use BitBadger\PDODocument\Field;
|
|
||||||
use BitBadger\PDODocument\Patch;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Security functions
|
* Security functions
|
||||||
|
@ -12,22 +10,22 @@ use BitBadger\PDODocument\Patch;
|
||||||
class Security
|
class Security
|
||||||
{
|
{
|
||||||
/** @var int Run as a single user requiring no password */
|
/** @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 */
|
/** @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 */
|
/** @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 */
|
/** @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 */
|
/** @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 */
|
/** @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
|
* Verify a user's password
|
||||||
|
|
|
@ -8,11 +8,11 @@ namespace FeedReaderCentral;
|
||||||
class Table
|
class Table
|
||||||
{
|
{
|
||||||
/** @var string The user table */
|
/** @var string The user table */
|
||||||
public const string USER = 'frc_user';
|
public const USER = 'frc_user';
|
||||||
|
|
||||||
/** @var string The feed table */
|
/** @var string The feed table */
|
||||||
public const string FEED = 'feed';
|
public const FEED = 'feed';
|
||||||
|
|
||||||
/** @var string The item table */
|
/** @var string The item table */
|
||||||
public const string ITEM = 'item';
|
public const ITEM = 'item';
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace FeedReaderCentral;
|
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;
|
use BitBadger\PDODocument\Mapper\ExistsMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,10 +40,7 @@ class User
|
||||||
*/
|
*/
|
||||||
public static function add(string $email, string $password): void
|
public static function add(string $email, string $password): void
|
||||||
{
|
{
|
||||||
Custom::nonQuery(<<<'SQL'
|
Document::insert(Table::USER, new User(email: $email, password: $password));
|
||||||
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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user