From 368dc3a410ade55f659b75f8bcd7edf9b10cb6cc Mon Sep 17 00:00:00 2001 From: aB0t Date: Tue, 1 Aug 2023 07:50:04 +0200 Subject: [PATCH] update 2023-08-01 07:50:04 --- .../README.md | 9 +++++++ .../code.php | 25 +++++++++++++++++++ .../code.power | 25 +++++++++++++++++++ .../README.md | 9 +++++++ .../code.php | 25 ++++++++++++++++++- .../code.power | 25 ++++++++++++++++++- 6 files changed, 116 insertions(+), 2 deletions(-) diff --git a/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/README.md b/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/README.md index 9639c6a..8286d9e 100644 --- a/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/README.md +++ b/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/README.md @@ -15,9 +15,11 @@ abstract Watcher #Orange { # Insert $insert # Update $update # bool $fresh + # bool $force # ?object $target # string $table + __construct(Load $load, Insert $insert, ...) + + forceUpdate() : void + isNew() : bool # hold() : bool # bump() : bool @@ -35,6 +37,13 @@ note right of Watcher::__construct Update $update end note +note right of Watcher::forceUpdate + The switch to force a local update + + since: 2.0.1 + return: void +end note + note right of Watcher::isNew The see if new target is newly installed diff --git a/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/code.php b/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/code.php index eb9277c..2496e2f 100644 --- a/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/code.php +++ b/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/code.php @@ -57,6 +57,14 @@ abstract class Watcher */ protected bool $fresh = false; + /** + * The force update + * + * @var bool + * @since 2.0.1 + */ + protected bool $force = false; + /** * The target * @@ -95,6 +103,17 @@ abstract class Watcher $this->today = (new Date())->toSql(); } + /** + * The switch to force a local update + * + * @return void + * @since 2.0.1 + */ + public function forceUpdate(): void + { + $this->force = true; + } + /** * The see if new target is newly installed * @@ -114,6 +133,12 @@ abstract class Watcher */ protected function hold(): bool { + // if we are being forced + if ($this->force) + { + return false; // we no longer hold, but force an update + } + // Create DateTime objects from the strings try { $today = new \DateTime($this->today); diff --git a/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/code.power b/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/code.power index 5f7977a..7941358 100644 --- a/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/code.power +++ b/src/37e36c41-16a7-4c5d-972c-99acad5fd0b1/code.power @@ -30,6 +30,14 @@ */ protected bool $fresh = false; + /** + * The force update + * + * @var bool + * @since 2.0.1 + */ + protected bool $force = false; + /** * The target * @@ -68,6 +76,17 @@ $this->today = (new Date())->toSql(); } + /** + * The switch to force a local update + * + * @return void + * @since 2.0.1 + */ + public function forceUpdate(): void + { + $this->force = true; + } + /** * The see if new target is newly installed * @@ -87,6 +106,12 @@ */ protected function hold(): bool { + // if we are being forced + if ($this->force) + { + return false; // we no longer hold, but force an update + } + // Create DateTime objects from the strings try { $today = new \DateTime($this->today); diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md b/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md index ad83aae..ac26cd6 100644 --- a/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md +++ b/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md @@ -26,6 +26,7 @@ class Watcher << (F,LightGreen) >> #Green { + getLastChapter(string $translation, int $book) : ?int + getNextBook(string $translation, int $book, ...) : ?int + getPreviousBook(string $translation, int $book, ...) : ?int + - forceUpdate(bool $state) : void } note right of Watcher::__construct @@ -50,6 +51,7 @@ note left of Watcher::sync string $translation int $book int $chapter + bool $force = false end note note right of Watcher::isNew @@ -123,6 +125,13 @@ note left of Watcher::getPreviousBook int $book int $try end note + +note right of Watcher::forceUpdate + The method to set the update state + + since: 2.0.1 + return: void +end note @enduml ``` diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php index b1e7f4f..c88f4e2 100644 --- a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php +++ b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php @@ -93,12 +93,16 @@ final class Watcher * @param string $translation The translation. * @param int $book The book number. * @param int $chapter The chapter number. + * @param bool $force The switch to force an update. * * @return bool True on success * @since 2.0.1 */ - public function sync(string $translation, int $book, int $chapter): bool + public function sync(string $translation, int $book, int $chapter, bool $force = false): bool { + // set the update state + $this->forceUpdate($force); + // is the translation details in sync if (!$this->translation->sync($translation)) { @@ -315,6 +319,25 @@ final class Watcher } return $this->getPreviousBook($translation, $previous, $try); + } + + /** + * The method to set the update state + * + * @param bool $state The switch to force an update. + * + * @return void + * @since 2.0.1 + */ + private function forceUpdate(bool $state): void + { + // force all updates + if ($state) + { + $this->translation->forceUpdate(); + $this->book->forceUpdate(); + $this->chapter->forceUpdate(); + } } } diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power index f28167d..048d19c 100644 --- a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power +++ b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power @@ -66,12 +66,16 @@ * @param string $translation The translation. * @param int $book The book number. * @param int $chapter The chapter number. + * @param bool $force The switch to force an update. * * @return bool True on success * @since 2.0.1 */ - public function sync(string $translation, int $book, int $chapter): bool + public function sync(string $translation, int $book, int $chapter, bool $force = false): bool { + // set the update state + $this->forceUpdate($force); + // is the translation details in sync if (!$this->translation->sync($translation)) { @@ -288,4 +292,23 @@ } return $this->getPreviousBook($translation, $previous, $try); + } + + /** + * The method to set the update state + * + * @param bool $state The switch to force an update. + * + * @return void + * @since 2.0.1 + */ + private function forceUpdate(bool $state): void + { + // force all updates + if ($state) + { + $this->translation->forceUpdate(); + $this->book->forceUpdate(); + $this->chapter->forceUpdate(); + } } \ No newline at end of file