4
0
Fork 0

update 2023-08-01 07:50:04

This commit is contained in:
Robot 2023-08-01 07:50:04 +02:00
parent 861f56ba6d
commit 368dc3a410
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
6 changed files with 116 additions and 2 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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
```

View File

@ -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();
}
}
}

View File

@ -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();
}
}