Skip to content

Commit

Permalink
fix multi-database - see isue #72
Browse files Browse the repository at this point in the history
  • Loading branch information
mikespub committed Feb 15, 2024
1 parent 19d60cd commit 2895552
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 51 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ x.x.x - TODO
1.5.x - 2023xxxx Maintenance release for 1.x (PHP >= 7.4)
* ...

2.x.x - 2023xxxx To be continued (PHP >= 8.1)
2.x.x - 2024xxxx To be continued (PHP >= 8.1)
* TODO - Fix OPDS 2.0 pagination

2.2.2 - 20240215 Fix multi-database for epub reader and email
* Error sending or reading book from additional dbs - see issue #72 from @malkavi

2.2.1 - 20231116 Consolidate PRs for next release (PHP >= 8.1)
* Support display settings for custom columns - see pull request #69 from @Mikescher
* Add Japanese language file - see pull request #67 from @horus68 translated by Rentaro Yoshidumi
Expand Down
73 changes: 32 additions & 41 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Input/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class Config
{
public const VERSION = '2.2.1';
public const VERSION = '2.2.2';
public const ENDPOINT = [
"index" => "index.php",
"feed" => "feed.php",
Expand Down
4 changes: 2 additions & 2 deletions lib/Output/EPubReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function getComponentContent($book, $component, $params = [])
public static function getContent($idData, $component, $request)
{
/** @var Book */
$book = Book::getBookByDataId($idData);
$book = Book::getBookByDataId($idData, $request->database());
$params = ['data' => $idData, 'db' => $book->getDatabaseId()];

$epub = new static::$epubClass($book->getFilePath('EPUB', $idData));
Expand All @@ -104,7 +104,7 @@ public static function getContent($idData, $component, $request)
*/
public static function getReader($idData, $request)
{
$book = Book::getBookByDataId($idData);
$book = Book::getBookByDataId($idData, $request->database());
$params = ['data' => $idData, 'db' => $book->getDatabaseId()];

try {
Expand Down
6 changes: 4 additions & 2 deletions lib/Output/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace SebLucas\Cops\Output;

use SebLucas\Cops\Input\Config;
use SebLucas\Cops\Input\Request;
use PHPMailer\PHPMailer\PHPMailer;
use SebLucas\Cops\Calibre\Book;

Expand Down Expand Up @@ -59,12 +60,13 @@ public static function checkRequest($idData, $emailDest)
* Summary of sendMail
* @param mixed $idData
* @param string $emailDest
* @param Request $request
* @param bool $dryRun
* @return bool|string
*/
public static function sendMail($idData, $emailDest, $dryRun = false)
public static function sendMail($idData, $emailDest, $request, $dryRun = false)
{
$book = Book::getBookByDataId($idData);
$book = Book::getBookByDataId($idData, $request->database());
$data = $book->getDataById($idData);

if (!file_exists($data->getLocalPath())) {
Expand Down
2 changes: 1 addition & 1 deletion sendtomail.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
exit;
}

if ($error = Mail::sendMail($idData, $emailDest)) {
if ($error = Mail::sendMail($idData, $emailDest, $request)) {
echo localize("mail.messagenotsent");
echo $error;
exit;
Expand Down
10 changes: 7 additions & 3 deletions test/mailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_once __DIR__ . '/config_test.php';
use PHPUnit\Framework\TestCase;
use SebLucas\Cops\Input\Config;
use SebLucas\Cops\Input\Request;
use SebLucas\Cops\Output\Mail;

class MailTest extends TestCase
Expand Down Expand Up @@ -104,21 +105,24 @@ public function testCheckRequestEmailNotValid(): void

public function testSendMailNotFound(): void
{
$this->assertStringStartsWith("No", Mail::sendMail(12, "a@a.com"));
$request = Request::build([]);
$this->assertStringStartsWith("No", Mail::sendMail(12, "a@a.com", $request));
}

public function testSendMailTooBig(): void
{
$old = Mail::$maxSize;
Mail::$maxSize = 0;
$this->assertStringStartsWith("No", Mail::sendMail(20, "a@a.com"));
$request = Request::build([]);
$this->assertStringStartsWith("No", Mail::sendMail(20, "a@a.com", $request));
Mail::$maxSize = $old;
}

public function testSendMailSomeday(): void
{
$request = Request::build([]);
// use dryRun to run preSend() but not actually Send()
$error = Mail::sendMail(20, "a@a.com", true);
$error = Mail::sendMail(20, "a@a.com", $request, true);
$this->assertFalse($error);
}
}
1 change: 1 addition & 0 deletions test/pageMultidatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function providerSearch()

public static function tearDownAfterClass(): void
{
Config::set('calibre_directory', __DIR__ . "/BaseWithSomeBooks/");
Database::clearDb();
}
}

0 comments on commit 2895552

Please sign in to comment.