From 831906681ecb5c2f218dc5fb90956843567fdfb6 Mon Sep 17 00:00:00 2001 From: Shish <shish@shishnet.org> Date: Thu, 30 Jan 2020 09:01:19 +0000 Subject: [PATCH] fixes for mysql --- core/dbengine.php | 2 +- core/util.php | 8 -------- ext/image_hash_ban/test.php | 14 ++++++++++---- ext/ipban/test.php | 2 +- ext/relationships/main.php | 10 ++++++---- ext/relationships/test.php | 5 ++++- tests/bootstrap.php | 4 ++-- 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/core/dbengine.php b/core/dbengine.php index d494d091..c974ab34 100644 --- a/core/dbengine.php +++ b/core/dbengine.php @@ -66,7 +66,7 @@ class MySQL extends DBEngine 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 - $db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";"); + // $db->exec("SET SESSION MAX_EXECUTION_TIME=".$time.";"); } } diff --git a/core/util.php b/core/util.php index 83b2be64..97bd3a74 100644 --- a/core/util.php +++ b/core/util.php @@ -768,14 +768,6 @@ function create_tables(Database $db) <p>{$e->getMessage()}</p>", 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 - ); } } diff --git a/ext/image_hash_ban/test.php b/ext/image_hash_ban/test.php index 3381a618..54c9110f 100644 --- a/ext/image_hash_ban/test.php +++ b/ext/image_hash_ban/test.php @@ -1,10 +1,11 @@ <?php declare(strict_types=1); class ImageBanTest extends ShimmiePHPUnitTestCase { + private $hash = "feb01bab5698a11dd87416724c7a89e3"; + public function testBan() { $this->log_in_as_admin(); - $hash = "feb01bab5698a11dd87416724c7a89e3"; // Post image $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); @@ -12,8 +13,8 @@ class ImageBanTest extends ShimmiePHPUnitTestCase $this->assertEquals(200, $page->code); // Ban & delete - send_event(new AddImageHashBanEvent($hash, "test hash ban")); - send_event(new ImageDeletionEvent(Image::by_id($image_id))); + send_event(new AddImageHashBanEvent($this->hash, "test hash ban")); + send_event(new ImageDeletionEvent(Image::by_id($image_id), true)); // Check deleted $page = $this->get_page("post/view/$image_id"); @@ -28,11 +29,16 @@ class ImageBanTest extends ShimmiePHPUnitTestCase } // Remove ban - send_event(new RemoveImageHashBanEvent($hash)); + send_event(new RemoveImageHashBanEvent($this->hash)); // Can repost $image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx"); $page = $this->get_page("post/view/$image_id"); $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 + } } diff --git a/ext/ipban/test.php b/ext/ipban/test.php index 813a32ac..624a5810 100644 --- a/ext/ipban/test.php +++ b/ext/ipban/test.php @@ -26,7 +26,7 @@ class IPBanTest extends ShimmiePHPUnitTestCase '42.42.42.42', 'block', 'unit testing', - '2099-01-01' + '2030-01-01' )); // Check added diff --git a/ext/relationships/main.php b/ext/relationships/main.php index 8d18657e..ecd7d72b 100644 --- a/ext/relationships/main.php +++ b/ext/relationships/main.php @@ -193,12 +193,14 @@ class Relationships extends Extension // WHERE id = :pid // ", ["pid"=>$parentID]); + $children = $database->get_one( + "SELECT COUNT(*) FROM images WHERE parent_id=:pid", + ["pid"=>$parent_id] + ); $database->execute( "UPDATE images - SET has_children = EXISTS ( - SELECT 1 FROM images WHERE parent_id = :pid - ) WHERE id = :pid", - ["pid"=>$parent_id] + SET has_children = :has_children WHERE id = :pid", + ["has_children"=>$database->scoresql_value_prepare($children>0), "pid"=>$parent_id] ); } } diff --git a/ext/relationships/test.php b/ext/relationships/test.php index 730eefad..5ce7fced 100644 --- a/ext/relationships/test.php +++ b/ext/relationships/test.php @@ -82,7 +82,10 @@ class RelationshipsTest extends ShimmiePHPUnitTestCase [$image_1, $image_2, $image_3] = $imgs; 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)); // refresh data from database diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8a6dc3e3..24bba49a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,4 @@ -<?php +<?php declare(strict_types=1); chdir(dirname(dirname(__FILE__))); require_once "vendor/autoload.php"; require_once "tests/defines.php"; @@ -67,7 +67,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase self::log_out(); 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)); } }