4
0

update 2023-08-10 10:21:17

This commit is contained in:
Robot 2023-08-10 10:21:17 +02:00
parent 12398086a5
commit e3dbb5dc16
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
6 changed files with 123 additions and 7 deletions

View File

@ -16,6 +16,7 @@ class Chapter << (F,LightGreen) >> #Green {
+ __construct(Load $load, Insert $insert, ...)
+ sync(string $translation, int $book, ...) : bool
+ names(array $books) : bool
+ force(array $books) : bool
- chapter(string $translation, int $book, ...) : bool
- chapters(string $translation, int $book, ...) : bool
- verses(string $translation, int $book, ...) : bool
@ -55,7 +56,14 @@ note right of Chapter::names
return: bool
end note
note left of Chapter::chapter
note left of Chapter::force
Force book chapter sync
since: 2.0.1
return: bool
end note
note right of Chapter::chapter
Load the chapter numbers
since: 2.0.1
@ -67,7 +75,7 @@ note left of Chapter::chapter
int $chapter
end note
note right of Chapter::chapters
note left of Chapter::chapters
Trigger the update of the chapters of a translation-book
since: 2.0.1
@ -79,7 +87,7 @@ note right of Chapter::chapters
bool $updateHash = false
end note
note left of Chapter::verses
note right of Chapter::verses
Load verses
since: 2.0.1
@ -91,7 +99,7 @@ note left of Chapter::verses
int $chapter
end note
note right of Chapter::update
note left of Chapter::update
Trigger the update of the verses of a translation-book-chapter
since: 2.0.1
@ -103,7 +111,7 @@ note right of Chapter::update
int $chapter
end note
note left of Chapter::hash
note right of Chapter::hash
Trigger the update of a chapter hash value
since: 2.0.1

View File

@ -137,6 +137,41 @@ final class Chapter extends Watcher
return true;
}
/**
* Force book chapter sync
*
* @param array $books The books ids.
*
* @return bool True on success
* @since 2.0.1
*/
public function force(array $books): bool
{
foreach ($books as $book)
{
if (($_book = $this->load->item(['id' => $book], 'book')) === null)
{
return false;
}
if (($chapters = $this->load->items(
['abbreviation' => $_book->abbreviation, 'book_nr' => $_book->nr],
'chapter'
)) !== null)
{
foreach ($chapters as $chapter)
{
$this->update->row([
'id' => $chapter->id,
'created' => $this->past
], 'id', 'chapter');
}
}
}
return true;
}
/**
* Load the chapter numbers
*

View File

@ -108,6 +108,41 @@
return true;
}
/**
* Force book chapter sync
*
* @param array $books The books ids.
*
* @return bool True on success
* @since 2.0.1
*/
public function force(array $books): bool
{
foreach ($books as $book)
{
if (($_book = $this->load->item(['id' => $book], 'book')) === null)
{
return false;
}
if (($chapters = $this->load->items(
['abbreviation' => $_book->abbreviation, 'book_nr' => $_book->nr],
'chapter'
)) !== null)
{
foreach ($chapters as $chapter)
{
$this->update->row([
'id' => $chapter->id,
'created' => $this->past
], 'id', 'chapter');
}
}
}
return true;
}
/**
* Load the chapter numbers
*

View File

@ -17,6 +17,8 @@ abstract Watcher #Orange {
# bool $fresh
# bool $force
# ?object $target
# string $today
# string $past
# string $table
+ __construct(Load $load, Insert $insert, ...)
+ forceUpdate() : void

View File

@ -73,6 +73,22 @@ abstract class Watcher
*/
protected ?object $target;
/**
* The today's date
*
* @var string
* @since 2.0.1
*/
protected string $today;
/**
* The two months in the past date
*
* @var string
* @since 2.0.1
*/
protected string $past;
/**
* The target table
*
@ -99,8 +115,10 @@ abstract class Watcher
$this->insert = $insert;
$this->update = $update;
// just in-case we set a date
// just in-case we set some dates
$this->today = (new Date())->toSql();
$this->past = (new Date())->modify('-2 months')->toSql();
}
/**

View File

@ -46,6 +46,22 @@
*/
protected ?object $target;
/**
* The today's date
*
* @var string
* @since 2.0.1
*/
protected string $today;
/**
* The two months in the past date
*
* @var string
* @since 2.0.1
*/
protected string $past;
/**
* The target table
*
@ -72,8 +88,10 @@
$this->insert = $insert;
$this->update = $update;
// just in-case we set a date
// just in-case we set some dates
$this->today = (new Date())->toSql();
$this->past = (new Date())->modify('-2 months')->toSql();
}
/**