fixes for mysql

This commit is contained in:
Shish 2020-01-30 09:01:19 +00:00
parent f90c8cee3c
commit 831906681e
7 changed files with 24 additions and 21 deletions

View file

@ -66,7 +66,7 @@ class MySQL extends DBEngine
public function set_timeout(PDO $db, int $time): void public function set_timeout(PDO $db, int $time): void
{ {
// These only apply to read-only queries, which appears to be the best we can to mysql-wise // These only apply to read-only queries, which appears to be the best we can to mysql-wise
$db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";"); // $db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";");
} }
} }

View file

@ -768,14 +768,6 @@ function create_tables(Database $db)
<p>{$e->getMessage()}</p>", <p>{$e->getMessage()}</p>",
3 3
); );
} catch (Exception $e) {
throw new InstallerException(
"Unknown Error:",
"<p>An unknown error occurred while trying to insert data into the database.</p>
<p>Please check the server log files for more information.</p>
<p>{$e->getMessage()}</p>",
4
);
} }
} }

View file

@ -1,10 +1,11 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
class ImageBanTest extends ShimmiePHPUnitTestCase class ImageBanTest extends ShimmiePHPUnitTestCase
{ {
private $hash = "feb01bab5698a11dd87416724c7a89e3";
public function testBan() public function testBan()
{ {
$this->log_in_as_admin(); $this->log_in_as_admin();
$hash = "feb01bab5698a11dd87416724c7a89e3";
// Post image // Post image
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
@ -12,8 +13,8 @@ class ImageBanTest extends ShimmiePHPUnitTestCase
$this->assertEquals(200, $page->code); $this->assertEquals(200, $page->code);
// Ban & delete // Ban & delete
send_event(new AddImageHashBanEvent($hash, "test hash ban")); send_event(new AddImageHashBanEvent($this->hash, "test hash ban"));
send_event(new ImageDeletionEvent(Image::by_id($image_id))); send_event(new ImageDeletionEvent(Image::by_id($image_id), true));
// Check deleted // Check deleted
$page = $this->get_page("post/view/$image_id"); $page = $this->get_page("post/view/$image_id");
@ -28,11 +29,16 @@ class ImageBanTest extends ShimmiePHPUnitTestCase
} }
// Remove ban // Remove ban
send_event(new RemoveImageHashBanEvent($hash)); send_event(new RemoveImageHashBanEvent($this->hash));
// Can repost // Can repost
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx");
$page = $this->get_page("post/view/$image_id"); $page = $this->get_page("post/view/$image_id");
$this->assertEquals(200, $page->code); $this->assertEquals(200, $page->code);
} }
public function onNotSuccessfulTest(\Throwable $t): void {
send_event(new RemoveImageHashBanEvent($this->hash));
parent::onNotSuccessfulTest($t); // TODO: Change the autogenerated stub
}
} }

View file

@ -26,7 +26,7 @@ class IPBanTest extends ShimmiePHPUnitTestCase
'42.42.42.42', '42.42.42.42',
'block', 'block',
'unit testing', 'unit testing',
'2099-01-01' '2030-01-01'
)); ));
// Check added // Check added

View file

@ -193,12 +193,14 @@ class Relationships extends Extension
// WHERE id = :pid // WHERE id = :pid
// ", ["pid"=>$parentID]); // ", ["pid"=>$parentID]);
$children = $database->get_one(
"SELECT COUNT(*) FROM images WHERE parent_id=:pid",
["pid"=>$parent_id]
);
$database->execute( $database->execute(
"UPDATE images "UPDATE images
SET has_children = EXISTS ( SET has_children = :has_children WHERE id = :pid",
SELECT 1 FROM images WHERE parent_id = :pid ["has_children"=>$database->scoresql_value_prepare($children>0), "pid"=>$parent_id]
) WHERE id = :pid",
["pid"=>$parent_id]
); );
} }
} }

View file

@ -82,7 +82,10 @@ class RelationshipsTest extends ShimmiePHPUnitTestCase
[$image_1, $image_2, $image_3] = $imgs; [$image_1, $image_2, $image_3] = $imgs;
global $database; global $database;
$database->execute("UPDATE images SET parent_id=NULL, has_children=:false", ["false"=>false]); $database->execute(
"UPDATE images SET parent_id=NULL, has_children=:false",
["false"=>$database->scoresql_value_prepare(false)]
);
// FIXME: send_event(new ImageRelationshipSetEvent($image_2->id, null)); // FIXME: send_event(new ImageRelationshipSetEvent($image_2->id, null));
// refresh data from database // refresh data from database

View file

@ -1,4 +1,4 @@
<?php <?php declare(strict_types=1);
chdir(dirname(dirname(__FILE__))); chdir(dirname(dirname(__FILE__)));
require_once "vendor/autoload.php"; require_once "vendor/autoload.php";
require_once "tests/defines.php"; require_once "tests/defines.php";
@ -67,7 +67,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase
self::log_out(); self::log_out();
foreach ($database->get_col("SELECT id FROM images") as $image_id) { foreach ($database->get_col("SELECT id FROM images") as $image_id) {
send_event(new ImageDeletionEvent(Image::by_id($image_id))); send_event(new ImageDeletionEvent(Image::by_id((int)$image_id), true));
} }
} }