Fix issue with book ids and names not handling integers correctly.
This commit is contained in:
parent
66c26bdfa3
commit
9fec3f7c05
|
@ -117,8 +117,8 @@ class UlbXmlImportHandler
|
|||
$this->document = $this->openBook($filepath);
|
||||
|
||||
$book = Book::create([
|
||||
'id' => strtolower($bookTitle),
|
||||
'name' => ucfirst($bookTitle),
|
||||
'id' => $this->prepareBookId($bookTitle),
|
||||
'name' => $this->prepareBookName($bookTitle),
|
||||
]);
|
||||
|
||||
$chapterCollection = $this->document->getElementsByTagName('chapter');
|
||||
|
@ -471,4 +471,37 @@ class UlbXmlImportHandler
|
|||
|
||||
return $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bookTitle
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareBookName(string $bookTitle) : string
|
||||
{
|
||||
$parts = $this->parseBookTitle($bookTitle);
|
||||
return !isset($parts[1]) ? ucfirst($parts[0]) : $parts[0] . " " . ucfirst($parts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bookTitle
|
||||
* @return string
|
||||
*/
|
||||
protected function prepareBookId(string $bookTitle) : string
|
||||
{
|
||||
$parts = $this->parseBookTitle($bookTitle);
|
||||
return !isset($parts[1]) ? strtolower($parts[0]) : $parts[0] . " " . strtolower($parts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bookTitle
|
||||
* @return array|string[]
|
||||
*/
|
||||
protected function parseBookTitle(string $bookTitle) : array
|
||||
{
|
||||
if (is_int((int) substr($bookTitle, 0, 1))) {
|
||||
return [ substr($bookTitle, 0, 1), substr($bookTitle, 1) ];
|
||||
} else {
|
||||
return [ $bookTitle ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue