4
0

update 2023-08-01 08:50:05

This commit is contained in:
Robot 2023-08-01 08:50:05 +02:00
parent 368dc3a410
commit b397c59418
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
3 changed files with 68 additions and 6 deletions

View File

@ -13,6 +13,7 @@
class Book << (F,LightGreen) >> #Green { class Book << (F,LightGreen) >> #Green {
# Books $books # Books $books
+ __construct(Load $load, Insert $insert, ...) + __construct(Load $load, Insert $insert, ...)
+ translations(array $translations) : bool
+ sync(string $translation, int $book) : bool + sync(string $translation, int $book) : bool
- load(string $translation, int $book) : bool - load(string $translation, int $book) : bool
- update(string $translation) : bool - update(string $translation) : bool
@ -30,6 +31,13 @@ note right of Book::__construct
Books $books Books $books
end note end note
note right of Book::translations
Update translations books
since: 2.0.1
return: bool
end note
note right of Book::sync note right of Book::sync
Sync the target being watched Sync the target being watched

View File

@ -59,6 +59,32 @@ final class Book extends Watcher
$this->table = 'book'; $this->table = 'book';
} }
/**
* Update translations books
*
* @param array $translations The translations ids.
*
* @return bool True on success
* @since 2.0.1
*/
public function translations(array $translations): bool
{
foreach ($translations as $translation)
{
if (($abbreviation = $this->load->value(['id' => $translation], 'abbreviation', 'translation')) === null)
{
return false;
}
if (!$this->update($abbreviation))
{
return false;
}
}
return true;
}
/** /**
* Sync the target being watched * Sync the target being watched
* *
@ -161,7 +187,7 @@ final class Book extends Watcher
{ {
// check if the verse exist // check if the verse exist
$match['value'] = (string) $book->nr; $match['value'] = (string) $book->nr;
if (($object = $this->getTarget($match, $local_books)) !== null) if ($local_books !== null && ($object = $this->getTarget($match, $local_books)) !== null)
{ {
$book->id = $object->id; $book->id = $object->id;
$book->created = $this->today; $book->created = $this->today;
@ -174,9 +200,10 @@ final class Book extends Watcher
} }
// check if we have values to insert // check if we have values to insert
$inserted = false;
if ($insert !== []) if ($insert !== [])
{ {
$this->insert->items($insert, $this->table); $inserted = $this->insert->items($insert, $this->table);
} }
// update the local values // update the local values
@ -185,7 +212,7 @@ final class Book extends Watcher
return true; return true;
} }
return false; return $inserted;
} }
} }

View File

@ -31,6 +31,32 @@
$this->table = 'book'; $this->table = 'book';
} }
/**
* Update translations books
*
* @param array $translations The translations ids.
*
* @return bool True on success
* @since 2.0.1
*/
public function translations(array $translations): bool
{
foreach ($translations as $translation)
{
if (($abbreviation = $this->load->value(['id' => $translation], 'abbreviation', 'translation')) === null)
{
return false;
}
if (!$this->update($abbreviation))
{
return false;
}
}
return true;
}
/** /**
* Sync the target being watched * Sync the target being watched
* *
@ -133,7 +159,7 @@
{ {
// check if the verse exist // check if the verse exist
$match['value'] = (string) $book->nr; $match['value'] = (string) $book->nr;
if (($object = $this->getTarget($match, $local_books)) !== null) if ($local_books !== null && ($object = $this->getTarget($match, $local_books)) !== null)
{ {
$book->id = $object->id; $book->id = $object->id;
$book->created = $this->today; $book->created = $this->today;
@ -146,9 +172,10 @@
} }
// check if we have values to insert // check if we have values to insert
$inserted = false;
if ($insert !== []) if ($insert !== [])
{ {
$this->insert->items($insert, $this->table); $inserted = $this->insert->items($insert, $this->table);
} }
// update the local values // update the local values
@ -157,5 +184,5 @@
return true; return true;
} }
return false; return $inserted;
} }