From 0452de1be9669f8976feacee05130bfd3b32c5c9 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 2 Feb 2020 15:53:05 +0000 Subject: [PATCH 1/5] flush stdout after each CLI logging call --- core/logging.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/logging.php b/core/logging.php index da3072a8..ae76d01c 100644 --- a/core/logging.php +++ b/core/logging.php @@ -25,6 +25,7 @@ function log_msg(string $section, int $priority, string $message, ?string $flash if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') && ($priority >= $threshold)) { print date("c")." $section: $message\n"; + ob_flush(); } if (!is_null($flash)) { $page->flash($flash); From 7cf5c2a28ce18600290e339dd1b4f13803fc405e Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 2 Feb 2020 15:53:20 +0000 Subject: [PATCH 2/5] bump size of index cli search --- ext/index/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/index/main.php b/ext/index/main.php index 0652646f..9218468a 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -154,7 +154,7 @@ class Index extends Extension } if ($event->cmd == "search") { $query = count($event->args) > 0 ? Tag::explode($event->args[0]) : []; - $items = Image::find_images(0, 100, $query); + $items = Image::find_images(0, 1000, $query); foreach ($items as $item) { print("{$item->hash}\n"); } From 9d704183c7d626c0a2cdb44bbd981f26df7de9f4 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 2 Feb 2020 17:00:33 +0000 Subject: [PATCH 3/5] actually do bulk actions from CLI --- ext/bulk_actions/main.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/bulk_actions/main.php b/ext/bulk_actions/main.php index 1516baae..d6b3e674 100644 --- a/ext/bulk_actions/main.php +++ b/ext/bulk_actions/main.php @@ -104,11 +104,11 @@ class BulkActions extends Extension if (count($event->args) < 2) { return; } - $query = $event->args[0]; - $items = $this->yield_search_results($event->args[1]); - $newEvent = new BulkActionEvent($event->args[0], $items); - var_dump($newEvent); - # send_event($newEvent); + $action = $event->args[0]; + $query = $event->args[1]; + $items = $this->yield_search_results($query); + log_info("bulk_actions", "Performing $action on {$event->args[1]}"); + send_event(new BulkActionEvent($event->args[0], $items)); } } From d880dc79970fb7a9a564a11eddef1ee9b31206c0 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 2 Feb 2020 17:00:55 +0000 Subject: [PATCH 4/5] don't fail to trace CLI --- index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 8be28854..f0010b7e 100644 --- a/index.php +++ b/index.php @@ -152,7 +152,10 @@ try { $_tracer->end(); if (TRACE_FILE) { - if ((microtime(true) - $_shm_load_start) > TRACE_THRESHOLD && $_SERVER["REQUEST_URI"] != "/upload") { + if ( + (microtime(true) - $_shm_load_start) > TRACE_THRESHOLD + && ($_SERVER["REQUEST_URI"] ?? "") != "/upload" + ) { $_tracer->flush(TRACE_FILE); } } From 116bd8d6e5b48ed94ecd476f198bd58e04c7af73 Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 2 Feb 2020 17:01:17 +0000 Subject: [PATCH 5/5] media logging --- ext/media/main.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ext/media/main.php b/ext/media/main.php index cc2202a8..8ae1ce92 100644 --- a/ext/media/main.php +++ b/ext/media/main.php @@ -164,8 +164,9 @@ class Media extends Extension $failed = 0; foreach ($event->items as $image) { try { + log_debug("media", "Rescanning media for {$image->hash} ({$image->id})"); send_event(new MediaCheckPropertiesEvent($image)); - $image->save_media_properties(); + $image->save_to_db(); $total++; } catch (MediaException $e) { $failed++; @@ -370,10 +371,10 @@ class Media extends Extension exec($cmd, $output, $ret); if ((int)$ret == (int)0) { - log_debug('Media', "Generating thumbnail with command `$cmd`, returns $ret"); + log_debug('media', "Generating thumbnail with command `$cmd`, returns $ret"); return true; } else { - log_error('Media', "Generating thumbnail with command `$cmd`, returns $ret"); + log_error('media', "Generating thumbnail with command `$cmd`, returns $ret"); return false; } } @@ -402,11 +403,11 @@ class Media extends Extension exec($cmd, $output, $ret); if ((int)$ret == (int)0) { - log_debug('Media', "Getting media data `$cmd`, returns $ret"); + log_debug('media', "Getting media data `$cmd`, returns $ret"); $output = implode($output); return json_decode($output, true); } else { - log_error('Media', "Getting media data `$cmd`, returns $ret"); + log_error('media', "Getting media data `$cmd`, returns $ret"); return []; } } @@ -614,7 +615,7 @@ class Media extends Extension if ($ret != 0) { throw new MediaException("Resizing image with command `$cmd`, returns $ret, outputting " . implode("\r\n", $output)); } else { - log_debug('Media', "Generating thumbnail with command `$cmd`, returns $ret"); + log_debug('media', "Generating thumbnail with command `$cmd`, returns $ret"); } } @@ -928,7 +929,7 @@ class Media extends Extension } else { $size = [1, 1]; } - log_debug('Media', "Getting video size with `$cmd`, returns $output -- $size[0], $size[1]"); + log_debug('media', "Getting video size with `$cmd`, returns $output -- $size[0], $size[1]"); return $size; }