mirror of
https://github.com/standardebooks/web.git
synced 2025-07-16 11:26:37 -04:00
Replace Library::GetEbookByIdentifier with Ebook::GetByIdentifier
The new method throws an exception instead of returning null.
This commit is contained in:
parent
7350891cd5
commit
572fd90fed
2 changed files with 25 additions and 26 deletions
|
@ -607,15 +607,14 @@ class Ebook{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CreateOrUpdate(): void{
|
public function CreateOrUpdate(): void{
|
||||||
$existingEbook = Library::GetEbookByIdentifier($this->Identifier);
|
try{
|
||||||
|
$existingEbook = Ebook::GetByIdentifier($this->Identifier);
|
||||||
if($existingEbook === null){
|
$this->EbookId = $existingEbook->EbookId;
|
||||||
$this->Create();
|
$this->Save();
|
||||||
return;
|
}
|
||||||
|
catch(Exceptions\EbookNotFoundException){
|
||||||
|
$this->Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->EbookId = $existingEbook->EbookId;
|
|
||||||
$this->Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function InsertTagStrings(): void{
|
private function InsertTagStrings(): void{
|
||||||
|
@ -936,6 +935,24 @@ class Ebook{
|
||||||
// ORM METHODS
|
// ORM METHODS
|
||||||
// ***********
|
// ***********
|
||||||
|
|
||||||
|
public static function GetByIdentifier(?string $identifier): ?Ebook{
|
||||||
|
if($identifier === null){
|
||||||
|
throw new Exceptions\EbookNotFoundException('Invalid identifier: ' . $identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Db::Query('
|
||||||
|
SELECT *
|
||||||
|
from Ebooks
|
||||||
|
where Identifier = ?
|
||||||
|
', [$identifier], 'Ebook');
|
||||||
|
|
||||||
|
if(sizeof($result) == 0){
|
||||||
|
throw new Exceptions\EbookNotFoundException('Invalid identifier: ' . $identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result[0];
|
||||||
|
}
|
||||||
|
|
||||||
public function Create(): void{
|
public function Create(): void{
|
||||||
$this->Validate();
|
$this->Validate();
|
||||||
|
|
||||||
|
|
|
@ -673,24 +673,6 @@ class Library{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetEbookByIdentifier(?string $identifier): ?Ebook{
|
|
||||||
if($identifier === null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = Db::Query('
|
|
||||||
SELECT *
|
|
||||||
from Ebooks
|
|
||||||
where Identifier = ?
|
|
||||||
', [$identifier], 'Ebook');
|
|
||||||
|
|
||||||
if(sizeof($result) == 0){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exceptions\AppException
|
* @throws Exceptions\AppException
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue