4 Commits

Author SHA1 Message Date
ff34bb9743 Add live-beta note 2024-06-26 18:41:41 -04:00
61127676a2 Update to beta2 of doc lib 2024-06-25 15:55:14 -04:00
5beeee4819 Use option for req-by-ID 2024-06-23 17:09:56 -04:00
a2feaff4da Clean up .NET artifacts 2024-06-23 16:39:35 -04:00
12 changed files with 48 additions and 367 deletions

255
.gitignore vendored
View File

@@ -1,262 +1,7 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
.vscode/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider # JetBrains Rider
.idea/ .idea/
*.sln.iml *.sln.iml
# Ionide VSCode extension
.ionide
src/environment.txt
# PHP ignore files # PHP ignore files
src/vendor src/vendor
src/.env src/.env

View File

@@ -1,3 +0,0 @@
#!/snap/bin/pwsh
Set-Location src/MyPrayerJournal
dotnet publish -c Release -r linux-x64 -p:PublishSingleFile=true --self-contained false --nologo

View File

@@ -6,7 +6,6 @@
"ext-pdo": "*", "ext-pdo": "*",
"ext-sqlite3": "*", "ext-sqlite3": "*",
"bit-badger/pdo-document": "^1", "bit-badger/pdo-document": "^1",
"visus/cuid2": "^4",
"guzzlehttp/guzzle": "^7.8", "guzzlehttp/guzzle": "^7.8",
"guzzlehttp/psr7": "^2.6", "guzzlehttp/psr7": "^2.6",
"http-interop/http-factory-guzzle": "^1.2", "http-interop/http-factory-guzzle": "^1.2",

72
src/composer.lock generated
View File

@@ -4,7 +4,7 @@
"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": "d19a824cbca9da75d5b5dafbc9fa1367", "content-hash": "d03cca0e9df6892b1154d46aa43ddfe9",
"packages": [ "packages": [
{ {
"name": "auth0/auth0-php", "name": "auth0/auth0-php",
@@ -107,16 +107,17 @@
}, },
{ {
"name": "bit-badger/pdo-document", "name": "bit-badger/pdo-document",
"version": "v1.0.0-beta1", "version": "v1.0.0-beta2",
"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": "124426fa12069aa93e75f7e2946eb2c5ff83a591" "reference": "50854275a8b39074966cf00370f30b3e68edc6e7"
}, },
"require": { "require": {
"ext-pdo": "*", "ext-pdo": "*",
"netresearch/jsonmapper": "^4", "netresearch/jsonmapper": "^4",
"php": ">=8.2" "php": ">=8.2",
"phpoption/phpoption": "^1.9"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^11" "phpunit/phpunit": "^11"
@@ -141,11 +142,12 @@
"role": "Developer" "role": "Developer"
} }
], ],
"description": "Treat SQLite (and soon PostgreSQL) as a document store", "description": "Treat SQLite and PostgreSQL as document stores",
"keywords": [ "keywords": [
"database", "database",
"document", "document",
"pdo", "pdo",
"postgresql",
"sqlite" "sqlite"
], ],
"support": { "support": {
@@ -153,7 +155,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-21T13:46:41+00:00" "time": "2024-06-25T14:42:26+00:00"
}, },
{ {
"name": "composer/semver", "name": "composer/semver",
@@ -2244,64 +2246,6 @@
], ],
"time": "2024-05-31T15:07:36+00:00" "time": "2024-05-31T15:07:36+00:00"
}, },
{
"name": "visus/cuid2",
"version": "4.1.0",
"source": {
"type": "git",
"url": "https://github.com/visus-io/php-cuid2.git",
"reference": "17c9b3098d556bb2556a084c948211333cc19c79"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/visus-io/php-cuid2/zipball/17c9b3098d556bb2556a084c948211333cc19c79",
"reference": "17c9b3098d556bb2556a084c948211333cc19c79",
"shasum": ""
},
"require": {
"php": "^8.1"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.29",
"ext-ctype": "*",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^10.0",
"squizlabs/php_codesniffer": "^3.7",
"vimeo/psalm": "^5.4"
},
"suggest": {
"ext-gmp": "*"
},
"type": "library",
"autoload": {
"files": [
"src/compat.php"
],
"psr-4": {
"Visus\\Cuid2\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alan Brault",
"email": "alan.brault@visus.io"
}
],
"description": "A PHP library for generating collision-resistant ids (CUIDs).",
"keywords": [
"cuid",
"identifier"
],
"support": {
"issues": "https://github.com/visus-io/php-cuid2/issues",
"source": "https://github.com/visus-io/php-cuid2/tree/4.1.0"
},
"time": "2024-05-14T13:23:35+00:00"
},
{ {
"name": "vlucas/phpdotenv", "name": "vlucas/phpdotenv",
"version": "v5.6.0", "version": "v5.6.0",

View File

@@ -1,6 +1,6 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use BitBadger\PDODocument\{Configuration, Custom, Definition, Document, Mode}; use BitBadger\PDODocument\{AutoId, Configuration, Custom, Definition, Document, Mode};
use BitBadger\PDODocument\Mapper\ArrayMapper; use BitBadger\PDODocument\Mapper\ArrayMapper;
use MyPrayerJournal\Domain\{History, Note, Recurrence, RecurrencePeriod, Request, RequestAction}; use MyPrayerJournal\Domain\{History, Note, Recurrence, RecurrencePeriod, Request, RequestAction};
use MyPrayerJournal\Table; use MyPrayerJournal\Table;
@@ -18,6 +18,8 @@ echo 'Found ' . sizeof($reqs) . ' requests; migrating to v4...' . PHP_EOL;
Configuration::resetPDO(); Configuration::resetPDO();
Configuration::$mode = Mode::SQLite; Configuration::$mode = Mode::SQLite;
Configuration::$pdoDSN = 'sqlite:./data/mpj.db'; Configuration::$pdoDSN = 'sqlite:./data/mpj.db';
Configuration::$autoId = AutoId::RandomString;
Configuration::$idStringLength = 12;
Definition::ensureTable(Table::REQUEST); Definition::ensureTable(Table::REQUEST);
@@ -29,29 +31,26 @@ function convertDate(string $date): string
foreach ($reqs as $reqJson) { foreach ($reqs as $reqJson) {
$req = json_decode($reqJson['data']); $req = json_decode($reqJson['data']);
$notes = array_map(fn(stdClass $note) => new Note(convertDate($note->asOf), $note->notes), $req->notes ?? []);
$history = array_map(fn(stdClass $hist) =>
new History(
asOf: convertDate($hist->asOf),
action: RequestAction::from($hist->status),
text: property_exists($hist, 'text') ? $hist->text : null),
$req->history);
$recurParts = explode(' ', $req->recurrence); $recurParts = explode(' ', $req->recurrence);
$recurPeriod = RecurrencePeriod::from(end($recurParts)); $recurPeriod = RecurrencePeriod::from(end($recurParts));
$recur = match ($recurPeriod) { $recur = match ($recurPeriod) {
RecurrencePeriod::Immediate => new Recurrence(RecurrencePeriod::Immediate), RecurrencePeriod::Immediate => new Recurrence(RecurrencePeriod::Immediate),
default => new Recurrence($recurPeriod, (int)$recurParts[0]) default => new Recurrence($recurPeriod, (int)$recurParts[0])
}; };
$v4Req = new Request( Document::insert(Table::REQUEST, new Request(
id: $req->id,
enteredOn: convertDate($req->enteredOn), enteredOn: convertDate($req->enteredOn),
userId: $req->userId, userId: $req->userId,
snoozedUntil: property_exists($req, 'snoozedUntil') ? convertDate($req->snoozedUntil) : null, snoozedUntil: property_exists($req, 'snoozedUntil') ? convertDate($req->snoozedUntil) : null,
showAfter: property_exists($req, 'showAfter') ? convertDate($req->showAfter) : null, showAfter: property_exists($req, 'showAfter') ? convertDate($req->showAfter) : null,
recurrence: $recur, recurrence: $recur,
history: $history, history: array_map(fn(stdClass $hist) =>
notes: $notes); new History(
Document::insert(Table::REQUEST, $v4Req); asOf: convertDate($hist->asOf),
action: RequestAction::from($hist->status),
text: property_exists($hist, 'text') ? $hist->text : null),
$req->history),
notes: array_map(fn(stdClass $note) =>
new Note(convertDate($note->asOf), $note->notes), $req->notes ?? [])));
} }
echo PHP_EOL . 'done' . PHP_EOL; echo PHP_EOL . 'done' . PHP_EOL;

View File

@@ -25,6 +25,6 @@ class Note
public static function byRequestId(string $id): array public static function byRequestId(string $id): array
{ {
$req = Request::byId($id); $req = Request::byId($id);
return $req ? $req->notes : []; return $req->isDefined() ? $req->get()->notes : [];
} }
} }

View File

@@ -2,12 +2,13 @@
namespace MyPrayerJournal\Domain; namespace MyPrayerJournal\Domain;
use BitBadger\PDODocument\{Custom, DocumentException, DocumentList, Find, Mapper\DocumentMapper}; use BitBadger\PDODocument\{Custom, DocumentException, DocumentList, Find};
use BitBadger\PDODocument\Mapper\DocumentMapper;
use DateTimeImmutable; use DateTimeImmutable;
use Exception; use Exception;
use JsonSerializable; use JsonSerializable;
use MyPrayerJournal\Table; use MyPrayerJournal\Table;
use Visus\Cuid2\Cuid2; use PhpOption\{None, Option};
/** /**
* A prayer request * A prayer request
@@ -28,12 +29,7 @@ class Request implements JsonSerializable
public function __construct(public string $id = '', public string $enteredOn = '', public string $userId = '', public function __construct(public string $id = '', public string $enteredOn = '', public string $userId = '',
public ?string $snoozedUntil = null, public ?string $showAfter = null, public ?string $snoozedUntil = null, public ?string $showAfter = null,
public Recurrence $recurrence = new Recurrence(RecurrencePeriod::Immediate), public Recurrence $recurrence = new Recurrence(RecurrencePeriod::Immediate),
public array $history = [], public array $notes = []) public array $history = [], public array $notes = []) { }
{
if ($id == '') {
$this->id = (new Cuid2())->toString();
}
}
/** /**
* Get the current text for this request * Get the current text for this request
@@ -110,13 +106,13 @@ class Request implements JsonSerializable
* Find a request by its ID * Find a request by its ID
* *
* @param string $id The ID of the request * @param string $id The ID of the request
* @return Request|false The request if it is found and belongs to the current user, false if not * @return Option<Request> The request (if it is found and belongs to the current user)
* @throws DocumentException If any is encountered * @throws DocumentException If any is encountered
*/ */
public static function byId(string $id): Request|false public static function byId(string $id): Option
{ {
$req = Find::byId(Table::REQUEST, $id, self::class); $req = Find::byId(Table::REQUEST, $id, self::class);
return ($req && $req->userId == $_SESSION['user_id']) ? $req : false; return ($req->getOrElse(new Request('x'))->userId == $_SESSION['user_id']) ? $req : None::create();
} }
/** /**

View File

@@ -87,7 +87,7 @@ Layout::pageHead('Documentation'); ?>
Now&rdquo;). The &ldquo;Answered&rdquo; link shows all requests that have been marked answered. The Now&rdquo;). The &ldquo;Answered&rdquo; link shows all requests that have been marked answered. The
&ldquo;Snoozed&rdquo; link only shows snoozed requests. &ldquo;Snoozed&rdquo; link only shows snoozed requests.
<h3 class="mb-3 mt-4">Final Notes</h3> <h3 id=notes class="mb-3 mt-4">Final Notes</h3>
<ul> <ul>
<li>If you encounter errors, please <li>If you encounter errors, please
<a href=https://git.bitbadger.solutions/bit-badger/myPrayerJournal/issues target=_blank rel=noopener>file an <a href=https://git.bitbadger.solutions/bit-badger/myPrayerJournal/issues target=_blank rel=noopener>file an

View File

@@ -1,6 +1,6 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use MyPrayerJournal\UI\Layout; use MyPrayerJournal\UI\Component;use MyPrayerJournal\UI\Layout;
require '../start.php'; require '../start.php';
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found(); if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
@@ -14,5 +14,8 @@ Layout::pageHead('Welcome'); ?>
<p>This site is open and available for anyone who wants to use it. To get started, simply click the &ldquo;Log <p>This site is open and available for anyone who wants to use it. To get started, simply click the &ldquo;Log
On&rdquo; link above, and log on with either a Microsoft or Google account. You can also learn more about the On&rdquo; link above, and log on with either a Microsoft or Google account. You can also learn more about the
site at the &ldquo;Docs&rdquo; link, also above. site at the &ldquo;Docs&rdquo; link, also above.
<hr>
<p><em>This is an in-progress upgrade from v3 to v4; if you encounter errors, see
<?=Component::pageLink('/docs#notes', 'the documentation')?> on reporting them.</em>
</article><?php </article><?php
Layout::pageFoot(); Layout::pageFoot();

View File

@@ -13,13 +13,12 @@ $isNew = $_GET['id'] == 'new';
$req = match ($isNew) { $req = match ($isNew) {
true => new Request('new'), true => new Request('new'),
false => Request::byId($_GET['id']) false => Request::byId($_GET['id'])->getOrCall(not_found(...))
}; };
if (!$req) not_found();
$cancelLink = match (true) { $cancelLink = match (true) {
str_ends_with($_SERVER['HTTP_REFERER'] ?? '', 'active.php') => '/requests/active', str_ends_with($_SERVER['HTTP_REFERER'] ?? '', 'active') => '/requests/active',
str_ends_with($_SERVER['HTTP_REFERER'] ?? '', 'snoozed.php') => '/requests/snoozed', str_ends_with($_SERVER['HTTP_REFERER'] ?? '', 'snoozed') => '/requests/snoozed',
default => '/journal' default => '/journal'
}; };
$action = $_GET['id'] == 'new' ? 'Add' : 'Edit'; $action = $_GET['id'] == 'new' ? 'Add' : 'Edit';

View File

@@ -26,8 +26,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
see_other('/journal'); see_other('/journal');
case 'PATCH': case 'PATCH':
$req = Request::byId($_PATCH['requestId']); $req = Request::byId($_PATCH['requestId'])->getOrCall(not_found(...));
if (!$req) not_found();
$patch = []; $patch = [];
// update recurrence if changed // update recurrence if changed
if ($recurrence != $req->recurrence) { if ($recurrence != $req->recurrence) {

View File

@@ -1,7 +1,7 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use Auth0\SDK\Exception\ConfigurationException; use Auth0\SDK\Exception\ConfigurationException;
use BitBadger\PDODocument\{Configuration, Definition, DocumentException, Mode}; use BitBadger\PDODocument\{AutoId, Configuration, Definition, DocumentException, Mode};
use Dotenv\Dotenv; use Dotenv\Dotenv;
use MyPrayerJournal\{Auth, Table}; use MyPrayerJournal\{Auth, Table};
use MyPrayerJournal\Domain\Request; use MyPrayerJournal\Domain\Request;
@@ -26,6 +26,9 @@ if (php_sapi_name() != 'cli') {
Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', 'mpj.db']); Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', 'mpj.db']);
Configuration::$mode = Mode::SQLite; Configuration::$mode = Mode::SQLite;
Configuration::$autoId = AutoId::RandomString;
Configuration::$idStringLength = 12;
Definition::ensureTable(Table::REQUEST); Definition::ensureTable(Table::REQUEST);
Definition::ensureFieldIndex(Table::REQUEST, 'user', ['userId']); Definition::ensureFieldIndex(Table::REQUEST, 'user', ['userId']);
@@ -79,8 +82,5 @@ function validate_request(string $id, array $methods, bool $redirect = true): Re
Auth::requireUser($redirect); Auth::requireUser($redirect);
$req = Request::byId($id); return Request::byId($id)->getOrCall(not_found(...));
if (!$req) not_found();
return $req;
} }