diff --git a/src/composer.json b/src/composer.json index cc8af6b..c54d440 100644 --- a/src/composer.json +++ b/src/composer.json @@ -6,7 +6,6 @@ "ext-pdo": "*", "ext-sqlite3": "*", "bit-badger/pdo-document": "^1", - "visus/cuid2": "^4", "guzzlehttp/guzzle": "^7.8", "guzzlehttp/psr7": "^2.6", "http-interop/http-factory-guzzle": "^1.2", diff --git a/src/composer.lock b/src/composer.lock index b9e6d91..3ab3a8e 100644 --- a/src/composer.lock +++ b/src/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d19a824cbca9da75d5b5dafbc9fa1367", + "content-hash": "d03cca0e9df6892b1154d46aa43ddfe9", "packages": [ { "name": "auth0/auth0-php", @@ -107,16 +107,17 @@ }, { "name": "bit-badger/pdo-document", - "version": "v1.0.0-beta1", + "version": "v1.0.0-beta2", "source": { "type": "git", "url": "https://git.bitbadger.solutions/bit-badger/pdo-document", - "reference": "124426fa12069aa93e75f7e2946eb2c5ff83a591" + "reference": "50854275a8b39074966cf00370f30b3e68edc6e7" }, "require": { "ext-pdo": "*", "netresearch/jsonmapper": "^4", - "php": ">=8.2" + "php": ">=8.2", + "phpoption/phpoption": "^1.9" }, "require-dev": { "phpunit/phpunit": "^11" @@ -141,11 +142,12 @@ "role": "Developer" } ], - "description": "Treat SQLite (and soon PostgreSQL) as a document store", + "description": "Treat SQLite and PostgreSQL as document stores", "keywords": [ "database", "document", "pdo", + "postgresql", "sqlite" ], "support": { @@ -153,7 +155,7 @@ "rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss", "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", @@ -2244,64 +2246,6 @@ ], "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", "version": "v5.6.0", diff --git a/src/convert-from-v3.php b/src/convert-from-v3.php index 3ced31c..0b2685d 100644 --- a/src/convert-from-v3.php +++ b/src/convert-from-v3.php @@ -1,6 +1,6 @@ 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); + $req = json_decode($reqJson['data']); $recurParts = explode(' ', $req->recurrence); $recurPeriod = RecurrencePeriod::from(end($recurParts)); $recur = match ($recurPeriod) { RecurrencePeriod::Immediate => new Recurrence(RecurrencePeriod::Immediate), default => new Recurrence($recurPeriod, (int)$recurParts[0]) }; - $v4Req = new Request( - id: $req->id, + Document::insert(Table::REQUEST, new Request( enteredOn: convertDate($req->enteredOn), userId: $req->userId, snoozedUntil: property_exists($req, 'snoozedUntil') ? convertDate($req->snoozedUntil) : null, showAfter: property_exists($req, 'showAfter') ? convertDate($req->showAfter) : null, recurrence: $recur, - history: $history, - notes: $notes); - Document::insert(Table::REQUEST, $v4Req); + 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), + notes: array_map(fn(stdClass $note) => + new Note(convertDate($note->asOf), $note->notes), $req->notes ?? []))); } echo PHP_EOL . 'done' . PHP_EOL; diff --git a/src/lib/Domain/Request.php b/src/lib/Domain/Request.php index 84adda5..8cb9656 100644 --- a/src/lib/Domain/Request.php +++ b/src/lib/Domain/Request.php @@ -8,8 +8,7 @@ use DateTimeImmutable; use Exception; use JsonSerializable; use MyPrayerJournal\Table; -use PhpOption\{None, Option, Some}; -use Visus\Cuid2\Cuid2; +use PhpOption\{None, Option}; /** * A prayer request @@ -30,12 +29,7 @@ class Request implements JsonSerializable public function __construct(public string $id = '', public string $enteredOn = '', public string $userId = '', public ?string $snoozedUntil = null, public ?string $showAfter = null, public Recurrence $recurrence = new Recurrence(RecurrencePeriod::Immediate), - public array $history = [], public array $notes = []) - { - if ($id == '') { - $this->id = (new Cuid2())->toString(); - } - } + public array $history = [], public array $notes = []) { } /** * Get the current text for this request @@ -118,7 +112,7 @@ class Request implements JsonSerializable public static function byId(string $id): Option { $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(); } /** diff --git a/src/start.php b/src/start.php index 1581354..e889aa7 100644 --- a/src/start.php +++ b/src/start.php @@ -1,7 +1,7 @@