Update to beta2 of doc lib
This commit is contained in:
parent
5beeee4819
commit
61127676a2
@ -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
72
src/composer.lock
generated
@ -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",
|
||||||
|
@ -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;
|
||||||
@ -16,8 +16,10 @@ $reqs = Custom::array('SELECT data FROM mpj.request', [], new ArrayMapper());
|
|||||||
echo 'Found ' . sizeof($reqs) . ' requests; migrating to v4...' . PHP_EOL;
|
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);
|
||||||
|
|
||||||
@ -28,30 +30,27 @@ 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;
|
||||||
|
@ -8,8 +8,7 @@ use DateTimeImmutable;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
use MyPrayerJournal\Table;
|
use MyPrayerJournal\Table;
|
||||||
use PhpOption\{None, Option, Some};
|
use PhpOption\{None, Option};
|
||||||
use Visus\Cuid2\Cuid2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A prayer request
|
* A prayer request
|
||||||
@ -30,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
|
||||||
@ -118,7 +112,7 @@ class Request implements JsonSerializable
|
|||||||
public static function byId(string $id): Option
|
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']) ? Some::create($req) : None::create();
|
return ($req->getOrElse(new Request('x'))->userId == $_SESSION['user_id']) ? $req : None::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
||||||
@ -24,8 +24,11 @@ if (php_sapi_name() != 'cli') {
|
|||||||
$_REQUEST['time_zone'] = $_SERVER['HTTP_X_TIME_ZONE'] ?? 'Etc/UTC';
|
$_REQUEST['time_zone'] = $_SERVER['HTTP_X_TIME_ZONE'] ?? 'Etc/UTC';
|
||||||
}
|
}
|
||||||
|
|
||||||
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']);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user