formatting
This commit is contained in:
parent
aabc69033b
commit
55c6854003
29 changed files with 128 additions and 106 deletions
|
@ -34,7 +34,7 @@ abstract class DBEngine
|
||||||
return 'CREATE TABLE '.$name.' ('.$data.')';
|
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
|
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
|
// 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.";");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PostgreSQL extends DBEngine
|
class PostgreSQL extends DBEngine
|
||||||
|
@ -123,7 +122,6 @@ class PostgreSQL extends DBEngine
|
||||||
{
|
{
|
||||||
$db->exec("SET statement_timeout TO ".$time.";");
|
$db->exec("SET statement_timeout TO ".$time.";");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// shimmie functions for export to sqlite
|
// shimmie functions for export to sqlite
|
||||||
|
|
|
@ -730,9 +730,11 @@ class Image
|
||||||
"INSERT INTO tags(tag) VALUES (:tag)",
|
"INSERT INTO tags(tag) VALUES (:tag)",
|
||||||
["tag"=>$tag]
|
["tag"=>$tag]
|
||||||
);
|
);
|
||||||
$database->execute($database->scoreql_to_sql(
|
$database->execute(
|
||||||
|
$database->scoreql_to_sql(
|
||||||
"INSERT INTO image_tags(image_id, tag_id)
|
"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]
|
["id"=>$this->id, "tag"=>$tag]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -83,5 +83,4 @@ abstract class Permissions
|
||||||
public const CRON_ADMIN = "cron_admin";
|
public const CRON_ADMIN = "cron_admin";
|
||||||
public const APPROVE_IMAGE = "approve_image";
|
public const APPROVE_IMAGE = "approve_image";
|
||||||
public const APPROVE_COMMENT = "approve_comment";
|
public const APPROVE_COMMENT = "approve_comment";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -360,8 +360,10 @@ function get_dir_contents(string $dir): array
|
||||||
}
|
}
|
||||||
$results = array_diff(
|
$results = array_diff(
|
||||||
scandir(
|
scandir(
|
||||||
$dir),
|
$dir
|
||||||
['..', '.']);
|
),
|
||||||
|
['..', '.']
|
||||||
|
);
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
@ -378,7 +380,8 @@ function scan_dir(string $path): array
|
||||||
$path,
|
$path,
|
||||||
FilesystemIterator::KEY_AS_PATHNAME |
|
FilesystemIterator::KEY_AS_PATHNAME |
|
||||||
FilesystemIterator::CURRENT_AS_FILEINFO |
|
FilesystemIterator::CURRENT_AS_FILEINFO |
|
||||||
FilesystemIterator::SKIP_DOTS);
|
FilesystemIterator::SKIP_DOTS
|
||||||
|
);
|
||||||
foreach (new RecursiveIteratorIterator($ite) as $filename => $cur) {
|
foreach (new RecursiveIteratorIterator($ite) as $filename => $cur) {
|
||||||
try {
|
try {
|
||||||
$filesize = $cur->getSize();
|
$filesize = $cur->getSize();
|
||||||
|
|
|
@ -79,15 +79,18 @@ class Approval extends Extension
|
||||||
switch ($approval_action) {
|
switch ($approval_action) {
|
||||||
case "approve_all":
|
case "approve_all":
|
||||||
$database->set_timeout(300000); // These updates can take a little bit
|
$database->set_timeout(300000); // These updates can take a little bit
|
||||||
$database->execute($database->scoreql_to_sql(
|
$database->execute(
|
||||||
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE approved = SCORE_BOOL_N"),
|
$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]
|
["approved_by_id"=>$user->id]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "disapprove_all":
|
case "disapprove_all":
|
||||||
$database->set_timeout(300000); // These updates can take a little bit
|
$database->set_timeout(300000); // These updates can take a little bit
|
||||||
$database->execute($database->scoreql_to_sql(
|
$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;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
@ -168,8 +171,10 @@ class Approval extends Extension
|
||||||
{
|
{
|
||||||
global $database, $user;
|
global $database, $user;
|
||||||
|
|
||||||
$database->execute($database->scoreql_to_sql(
|
$database->execute(
|
||||||
"UPDATE images SET approved = SCORE_BOOL_Y, approved_by_id = :approved_by_id WHERE id = :id AND approved = SCORE_BOOL_N"),
|
$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]
|
["approved_by_id"=>$user->id, "id"=>$image_id]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -178,8 +183,10 @@ class Approval extends Extension
|
||||||
{
|
{
|
||||||
global $database, $user;
|
global $database, $user;
|
||||||
|
|
||||||
$database->execute($database->scoreql_to_sql(
|
$database->execute(
|
||||||
"UPDATE images SET approved = SCORE_BOOL_N, approved_by_id = NULL WHERE id = :id AND approved = SCORE_BOOL_Y"),
|
$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]
|
["id"=>$image_id]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ abstract class CronUploaderConfig
|
||||||
|
|
||||||
$config->set_string(self::KEY, $upload_key);
|
$config->set_string(self::KEY, $upload_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_user(): int
|
public static function get_user(): int
|
||||||
|
|
|
@ -203,24 +203,29 @@ class CronUploader extends Extension
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->theme->display_documentation(
|
$this->theme->display_documentation(
|
||||||
$running, $queue_dirinfo, $uploaded_dirinfo, $failed_dirinfo,
|
$running,
|
||||||
$this->get_cron_cmd(), $this->get_cron_url(), $logs
|
$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();
|
$dir = CronUploaderConfig::get_dir();
|
||||||
return join_path($dir, self::QUEUE_DIR);
|
return join_path($dir, self::QUEUE_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_uploaded_dir()
|
public function get_uploaded_dir()
|
||||||
{
|
{
|
||||||
$dir = CronUploaderConfig::get_dir();
|
$dir = CronUploaderConfig::get_dir();
|
||||||
return join_path($dir, self::UPLOADED_DIR);
|
return join_path($dir, self::UPLOADED_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_failed_dir()
|
public function get_failed_dir()
|
||||||
{
|
{
|
||||||
$dir = CronUploaderConfig::get_dir();
|
$dir = CronUploaderConfig::get_dir();
|
||||||
return join_path($dir, self::FAILED_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->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, "(" . gettype($e) . ") " . $e->getMessage());
|
||||||
$this->log_message(SCORE_LOG_ERROR, $e->getTraceAsString());
|
$this->log_message(SCORE_LOG_ERROR, $e->getTraceAsString());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +351,6 @@ class CronUploader extends Extension
|
||||||
flock($lockfile, LOCK_UN);
|
flock($lockfile, LOCK_UN);
|
||||||
fclose($lockfile);
|
fclose($lockfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function move_uploaded(string $path, string $filename, string $output_subdir, bool $corrupt = false)
|
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 const PARTIAL_DOWNLOAD_EXTENSIONS = ['crdownload','part'];
|
||||||
|
|
||||||
private function is_skippable_file(string $path) {
|
private function is_skippable_file(string $path)
|
||||||
|
{
|
||||||
$info = pathinfo($path);
|
$info = pathinfo($path);
|
||||||
|
|
||||||
if (in_array(strtolower($info['extension']), self::PARTIAL_DOWNLOAD_EXTENSIONS)) {
|
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));
|
$page->set_data(implode("\r\n", $this->output_buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,15 @@
|
||||||
|
|
||||||
class CronUploaderTheme extends Themelet
|
class CronUploaderTheme extends Themelet
|
||||||
{
|
{
|
||||||
public function display_documentation(bool $running, array $queue_dirinfo, array $uploaded_dirinfo, array $failed_dirinfo,
|
public function display_documentation(
|
||||||
string $cron_cmd, string $cron_url, ?array $log_entries)
|
bool $running,
|
||||||
{
|
array $queue_dirinfo,
|
||||||
|
array $uploaded_dirinfo,
|
||||||
|
array $failed_dirinfo,
|
||||||
|
string $cron_cmd,
|
||||||
|
string $cron_url,
|
||||||
|
?array $log_entries
|
||||||
|
) {
|
||||||
global $page;
|
global $page;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,10 @@ class DanbooruApi extends Extension
|
||||||
} elseif (isset($_GET['name'])) {
|
} elseif (isset($_GET['name'])) {
|
||||||
$namelist = explode(",", $_GET['name']);
|
$namelist = explode(",", $_GET['name']);
|
||||||
foreach ($namelist as $name) {
|
foreach ($namelist as $name) {
|
||||||
$sqlresult = $database->get_all($database->scoreql_to_sql(
|
$sqlresult = $database->get_all(
|
||||||
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"),
|
$database->scoreql_to_sql(
|
||||||
|
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"
|
||||||
|
),
|
||||||
[$name]
|
[$name]
|
||||||
);
|
);
|
||||||
foreach ($sqlresult as $row) {
|
foreach ($sqlresult as $row) {
|
||||||
|
|
|
@ -52,8 +52,6 @@ class HelpPages extends Extension
|
||||||
$pages = $this->get_pages();
|
$pages = $this->get_pages();
|
||||||
|
|
||||||
if ($event->page_matches("help")) {
|
if ($event->page_matches("help")) {
|
||||||
|
|
||||||
|
|
||||||
if ($event->count_args() == 0) {
|
if ($event->count_args() == 0) {
|
||||||
$name = array_key_first($pages);
|
$name = array_key_first($pages);
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
|
|
|
@ -6,5 +6,4 @@ abstract class MediaConfig
|
||||||
const CONVERT_PATH = "media_convert_path";
|
const CONVERT_PATH = "media_convert_path";
|
||||||
const VERSION = "ext_media_version";
|
const VERSION = "ext_media_version";
|
||||||
const MEM_LIMIT = 'media_mem_limit';
|
const MEM_LIMIT = 'media_mem_limit';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,19 @@ class MediaResizeEvent extends Event
|
||||||
public $ignore_aspect_ratio;
|
public $ignore_aspect_ratio;
|
||||||
public $allow_upscale;
|
public $allow_upscale;
|
||||||
|
|
||||||
public function __construct(String $engine, string $input_path, string $input_type, string $output_path,
|
public function __construct(
|
||||||
int $target_width, int $target_height,
|
String $engine,
|
||||||
|
string $input_path,
|
||||||
|
string $input_type,
|
||||||
|
string $output_path,
|
||||||
|
int $target_width,
|
||||||
|
int $target_height,
|
||||||
bool $ignore_aspect_ratio = false,
|
bool $ignore_aspect_ratio = false,
|
||||||
string $target_format = null,
|
string $target_format = null,
|
||||||
int $target_quality = 80,
|
int $target_quality = 80,
|
||||||
bool $minimize = false,
|
bool $minimize = false,
|
||||||
bool $allow_upscale = true)
|
bool $allow_upscale = true
|
||||||
{
|
) {
|
||||||
assert(in_array($engine, MediaEngine::ALL));
|
assert(in_array($engine, MediaEngine::ALL));
|
||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
$this->input_path = $input_path;
|
$this->input_path = $input_path;
|
||||||
|
@ -54,5 +59,4 @@ class MediaCheckPropertiesEvent extends Event
|
||||||
$this->file_name = $file_name;
|
$this->file_name = $file_name;
|
||||||
$this->ext = $ext;
|
$this->ext = $ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ class DataUploadEvent extends Event
|
||||||
assert(is_array($metadata["tags"]));
|
assert(is_array($metadata["tags"]));
|
||||||
assert(is_string($metadata["source"]) || is_null($metadata["source"]));
|
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->metadata = $metadata;
|
||||||
|
|
||||||
$this->set_tmpname($tmpname);
|
$this->set_tmpname($tmpname);
|
||||||
|
|
Reference in a new issue