Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: getChapters() not getting chapters #71

Closed
cgdmohamed opened this issue Apr 5, 2024 · 2 comments
Closed

[Bug]: getChapters() not getting chapters #71

cgdmohamed opened this issue Apr 5, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@cgdmohamed
Copy link

cgdmohamed commented Apr 5, 2024

`
public function upload(Request $request)
{
$request->validate([
'epub_file' => 'required|mimes:epub'
]);

    $filename = 'eb_' . uniqid() . '.epub';
    $path = $request->file('epub_file')->storeAs('epubs', $filename);

    $ebook = Ebook::read(storage_path('app/' . $path));

    // Access metadata and properties of the eBook
    $title = $ebook->getTitle();
    $author = $ebook->getAuthorMain();
    $description = $ebook->getDescription() ?? 'No Description added';
    $coverImage = $ebook->getCover();

    // Store cover image
    $coverPath = null;
    if ($coverImage) {
        $coverFilename = 'cover_' . uniqid() . '.png'; // Assuming cover image format is PNG
        $coverContents = $coverImage->getContents();
        $fullPath = 'covers/' . $coverFilename;
        Storage::put($fullPath, $coverContents);
        $coverPath = $fullPath; // Store the full path including 'storage/app'
    }

    // Create a new book
    $book = Book::create([
        'name' => $title,
        'author' => $author,
        'isbn' => null,
        'book_cover' => $coverPath,
        'description' => $description
    ]);

    // Get chapters from the EPUB
    $epub = $ebook->getParser()?->getEpub();
    $chapters = $epub->getChapters(); // Ensure this line is correctly retrieving chapters
    dd($chapters); // Debug to check if chapters are now correctly retrieved

    // Save chapters to database
    foreach ($chapters as $index => $chapter) {
        Chapter::create([
            'title' => $chapter->label(), // Use label() method to get the chapter label
            'content' => $chapter->content(), // Use content() method to get the chapter content
            'book_id' => $book->id,
            'src' => $chapter->source(), // Use source() method to get the chapter source
        ]);
    }

    return redirect()->route('books.index')->with('success', 'Book uploaded successfully. File name: ' . $filename);
}

`

What happened?

Upon attempting to upload an EPUB file through the upload function, the process completes successfully without any errors reported. However, upon inspection, it's found that no chapters are created in the database despite the EPUB containing multiple chapters.

How to reproduce the bug

Expected Behavior:
After the file is uploaded, the function should extract chapters from the EPUB file and save them to the database. These chapters should be retrievable and displayed for the user.

Actual Behavior:
After uploading an EPUB file, the function successfully creates a book entry in the database with the correct title, author, cover image, and description. However, no chapters are created or saved in the database, even though the EPUB contains multiple chapters.

Debugging Steps Undertaken:

Checked the $chapters variable after retrieving it from the EPUB file. Used dd($chapters) to ensure that chapters are correctly retrieved. However, the dump shows an empty array, indicating that no chapters are being extracted.
Verified that the EPUB file contains multiple chapters by manually inspecting the file using EPUB reader software.

Package Version

2.3.8

PHP Version

8.2

Which operating systems does with happen with?

Windows

Notes

No response

@cgdmohamed cgdmohamed added the bug Something isn't working label Apr 5, 2024
@ewilan-riviere ewilan-riviere self-assigned this Apr 5, 2024
@basitcodeenv
Copy link
Contributor

Facing same issue!

ewilan-riviere added a commit that referenced this issue Jul 15, 2024
Fix issue #71 with PR #89 by @basitcodeenv, thanks!
@ewilan-riviere ewilan-riviere mentioned this issue Jul 15, 2024
@ewilan-riviere
Copy link
Contributor

ewilan-riviere commented Jul 15, 2024

Should be fixed with PR #89 by @basitcodeenv, thanks!
Update to v2.6.6

ewilan-riviere added a commit that referenced this issue Jul 16, 2024
Hotfix PR #91 for issue #71 by @basitcodeenv, thanks!
@ewilan-riviere ewilan-riviere mentioned this issue Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants