formatting

This commit is contained in:
Shish 2019-11-02 19:57:34 +00:00
parent aabc69033b
commit 55c6854003
29 changed files with 128 additions and 106 deletions

View file

@ -34,7 +34,7 @@ abstract class DBEngine
return 'CREATE TABLE '.$name.' ('.$data.')';
}
public abstract function set_timeout(PDO $db, int $time);
abstract public function set_timeout(PDO $db, int $time);
}
class MySQL extends DBEngine
@ -76,7 +76,6 @@ class MySQL extends DBEngine
// 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.";");
}
}
class PostgreSQL extends DBEngine
@ -123,7 +122,6 @@ class PostgreSQL extends DBEngine
{
$db->exec("SET statement_timeout TO ".$time.";");
}
}
// shimmie functions for export to sqlite

View file

@ -730,9 +730,11 @@ class Image
"INSERT INTO tags(tag) VALUES (:tag)",
["tag"=>$tag]
);
$database->execute($database->scoreql_to_sql(
$database->execute(
$database->scoreql_to_sql(
"INSERT INTO image_tags(image_id, tag_id)
VALUES(:id, (SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)))"),
VALUES(:id, (SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)))"
),
["id"=>$this->id, "tag"=>$tag]
);
} else {

View file

@ -83,5 +83,4 @@ abstract class Permissions
public const CRON_ADMIN = "cron_admin";
public const APPROVE_IMAGE = "approve_image";
public const APPROVE_COMMENT = "approve_comment";
}

View file

@ -360,8 +360,10 @@ function get_dir_contents(string $dir): array
}
$results = array_diff(
scandir(
$dir),
['..', '.']);
$dir
),
['..', '.']
);
return $results;
}
@ -378,7 +380,8 @@ function scan_dir(string $path): array
$path,
FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::SKIP_DOTS);
FilesystemIterator::SKIP_DOTS
);
foreach (new RecursiveIteratorIterator($ite) as $filename => $cur) {
try {
$filesize = $cur->getSize();

View file

@ -79,15 +79,18 @@ class Approval extends Extension
switch ($approval_action) {
case "approve_all":
$database->set_timeout(300000); // These updates can take a little bit
$database->execute($database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE approved = SCORE_BOOL_N"),
$database->execute(
$database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE approved = SCORE_BOOL_N"
),
["approved_by_id"=>$user->id]
);
break;
case "disapprove_all":
$database->set_timeout(300000); // These updates can take a little bit
$database->execute($database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE approved = SCORE_BOOL_Y"));
"UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE approved = SCORE_BOOL_Y"
));
break;
default:
@ -168,8 +171,10 @@ class Approval extends Extension
{
global $database, $user;
$database->execute($database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE id = :id AND approved = SCORE_BOOL_N"),
$database->execute(
$database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE id = :id AND approved = SCORE_BOOL_N"
),
["approved_by_id"=>$user->id, "id"=>$image_id]
);
}
@ -178,8 +183,10 @@ class Approval extends Extension
{
global $database, $user;
$database->execute($database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE id = :id AND approved = SCORE_BOOL_Y"),
$database->execute(
$database->scoreql_to_sql(
"UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE id = :id AND approved = SCORE_BOOL_Y"
),
["id"=>$image_id]
);
}

View file

@ -22,7 +22,6 @@ abstract class CronUploaderConfig
$config->set_string(self::KEY, $upload_key);
}
}
public static function get_user(): int

View file

@ -203,24 +203,29 @@ class CronUploader extends Extension
}
$this->theme->display_documentation(
$running, $queue_dirinfo, $uploaded_dirinfo, $failed_dirinfo,
$this->get_cron_cmd(), $this->get_cron_url(), $logs
$running,
$queue_dirinfo,
$uploaded_dirinfo,
$failed_dirinfo,
$this->get_cron_cmd(),
$this->get_cron_url(),
$logs
);
}
function get_queue_dir()
public function get_queue_dir()
{
$dir = CronUploaderConfig::get_dir();
return join_path($dir, self::QUEUE_DIR);
}
function get_uploaded_dir()
public function get_uploaded_dir()
{
$dir = CronUploaderConfig::get_dir();
return join_path($dir, self::UPLOADED_DIR);
}
function get_failed_dir()
public function get_failed_dir()
{
$dir = CronUploaderConfig::get_dir();
return join_path($dir, self::FAILED_DIR);
@ -329,8 +334,6 @@ class CronUploader extends Extension
$this->move_uploaded($img[0], $img[1], $output_subdir, true);
$this->log_message(SCORE_LOG_ERROR, "(" . gettype($e) . ") " . $e->getMessage());
$this->log_message(SCORE_LOG_ERROR, $e->getTraceAsString());
}
}
@ -348,7 +351,6 @@ class CronUploader extends Extension
flock($lockfile, LOCK_UN);
fclose($lockfile);
}
}
private function move_uploaded(string $path, string $filename, string $output_subdir, bool $corrupt = false)
@ -424,7 +426,8 @@ class CronUploader extends Extension
private const PARTIAL_DOWNLOAD_EXTENSIONS = ['crdownload','part'];
private function is_skippable_file(string $path) {
private function is_skippable_file(string $path)
{
$info = pathinfo($path);
if (in_array(strtolower($info['extension']), self::PARTIAL_DOWNLOAD_EXTENSIONS)) {
@ -499,4 +502,3 @@ class CronUploader extends Extension
$page->set_data(implode("\r\n", $this->output_buffer));
}
}

View file

@ -2,9 +2,15 @@
class CronUploaderTheme extends Themelet
{
public function display_documentation(bool $running, array $queue_dirinfo, array $uploaded_dirinfo, array $failed_dirinfo,
string $cron_cmd, string $cron_url, ?array $log_entries)
{
public function display_documentation(
bool $running,
array $queue_dirinfo,
array $uploaded_dirinfo,
array $failed_dirinfo,
string $cron_cmd,
string $cron_url,
?array $log_entries
) {
global $page;

View file

@ -90,8 +90,10 @@ class DanbooruApi extends Extension
} elseif (isset($_GET['name'])) {
$namelist = explode(",", $_GET['name']);
foreach ($namelist as $name) {
$sqlresult = $database->get_all($database->scoreql_to_sql(
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"),
$sqlresult = $database->get_all(
$database->scoreql_to_sql(
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"
),
[$name]
);
foreach ($sqlresult as $row) {

View file

@ -52,8 +52,6 @@ class HelpPages extends Extension
$pages = $this->get_pages();
if ($event->page_matches("help")) {
if ($event->count_args() == 0) {
$name = array_key_first($pages);
$page->set_mode(PageMode::REDIRECT);

View file

@ -6,5 +6,4 @@ abstract class MediaConfig
const CONVERT_PATH = "media_convert_path";
const VERSION = "ext_media_version";
const MEM_LIMIT = 'media_mem_limit';
}

View file

@ -14,14 +14,19 @@ class MediaResizeEvent extends Event
public $ignore_aspect_ratio;
public $allow_upscale;
public function __construct(String $engine, string $input_path, string $input_type, string $output_path,
int $target_width, int $target_height,
public function __construct(
String $engine,
string $input_path,
string $input_type,
string $output_path,
int $target_width,
int $target_height,
bool $ignore_aspect_ratio = false,
string $target_format = null,
int $target_quality = 80,
bool $minimize = false,
bool $allow_upscale = true)
{
bool $allow_upscale = true
) {
assert(in_array($engine, MediaEngine::ALL));
$this->engine = $engine;
$this->input_path = $input_path;
@ -54,5 +59,4 @@ class MediaCheckPropertiesEvent extends Event
$this->file_name = $file_name;
$this->ext = $ext;
}
}

View file

@ -35,6 +35,9 @@ class DataUploadEvent extends Event
assert(is_array($metadata["tags"]));
assert(is_string($metadata["source"]) || is_null($metadata["source"]));
// DB limits to 64 char filenames
$metadata['filename'] = substr($metadata['filename'], 0, 63);
$this->metadata = $metadata;
$this->set_tmpname($tmpname);