From c7c45694127daad0522267abdd41d31a80ee1394 Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Mon, 5 Nov 2018 23:33:22 +0700 Subject: [PATCH] Combine all the separate importer views into a single one. --- classes/Tasks/BackgroundProcess.php | 6 +- classes/Tasks/BatchManager.php | 10 +- classes/Tools/Rekognition/RekognitionTool.php | 16 +- classes/Tools/Storage/StorageTool.php | 32 ++- .../regenerator.php => importer/importer.php} | 56 +++--- views/importer/regeneration-instructions.php | 3 + views/importer/rekognition-instructions.php | 8 + .../storage-importer-instructions.php | 8 + .../rekognizer/ilab-rekognizer-processor.php | 188 ----------------- views/storage/ilab-storage-importer.php | 190 ------------------ 10 files changed, 99 insertions(+), 418 deletions(-) rename views/{storage/regenerator.php => importer/importer.php} (69%) create mode 100644 views/importer/regeneration-instructions.php create mode 100644 views/importer/rekognition-instructions.php create mode 100644 views/importer/storage-importer-instructions.php delete mode 100644 views/rekognizer/ilab-rekognizer-processor.php delete mode 100644 views/storage/ilab-storage-importer.php diff --git a/classes/Tasks/BackgroundProcess.php b/classes/Tasks/BackgroundProcess.php index b6e6dd22..d4b60997 100755 --- a/classes/Tasks/BackgroundProcess.php +++ b/classes/Tasks/BackgroundProcess.php @@ -523,5 +523,9 @@ public function cancel_process() { */ abstract public function task( $item ); - abstract public static function cancelAll(); + /** + * Override in subclasses to handle this process being cancelled. + */ + public static function cancelAll() { + } } \ No newline at end of file diff --git a/classes/Tasks/BatchManager.php b/classes/Tasks/BatchManager.php index 9cc2944c..2c233ab1 100644 --- a/classes/Tasks/BatchManager.php +++ b/classes/Tasks/BatchManager.php @@ -75,7 +75,6 @@ public static function boot() { }); add_action('ilab_media_tools_run_batch_hook', function(){ - Logger::info('Running ilab_media_tools_run_batch_hook'); BatchManager::instance()->dispatchBatchesIfNeeded(); }); @@ -272,7 +271,7 @@ public function stats($batch) { if (($totalTime > 0) && ($current > 1)) { $postsPerSecond = ($totalTime / ($current - 1)); if ($postsPerSecond > 0) { - $postsPerMinute = 60 / $postsPerMinute; + $postsPerMinute = 60 / $postsPerSecond; $eta = ($total - $current) / $postsPerMinute; } } @@ -280,7 +279,7 @@ public function stats($batch) { return [ 'running' => $this->status($batch), 'current' => $current, - 'file' => $this->currentFile($batch), + 'currentFile' => $this->currentFile($batch), 'total' => $total, 'totalTime' => $totalTime, 'lastTime' => $this->lastTime($batch), @@ -288,7 +287,7 @@ public function stats($batch) { 'eta' => $eta, 'progress' => $progress, 'postsPerMinute' => $postsPerMinute, - 'cancelling' => $this->shouldCancel($batch) + 'shouldCancel' => $this->shouldCancel($batch) ]; } @@ -347,12 +346,9 @@ public function addToBatchAndRun($batch, $postIDs) { public function dispatchBatchesIfNeeded() { foreach(static::$batchClasses as $batch => $batchClass) { if ($this->status($batch)) { - Logger::info("ilab_media_tools_run_batch_hook - $batch running"); $lastRun = $this->lastRun($batch); - Logger::info("ilab_media_tools_run_batch_hook - Last run ".(time() - $lastRun)." seconds ago."); if ((time() - $lastRun) > 60) { - Logger::info("ilab_media_tools_run_batch_hook - Restarting"); $this->setLastRun($batch, time()); /** @var BackgroundProcess $process */ diff --git a/classes/Tools/Rekognition/RekognitionTool.php b/classes/Tools/Rekognition/RekognitionTool.php index a56d98af..a4917040 100644 --- a/classes/Tools/Rekognition/RekognitionTool.php +++ b/classes/Tools/Rekognition/RekognitionTool.php @@ -528,10 +528,20 @@ public function renderImporter() { $stats['total'] = count($attachments); } - $stats['running'] = ($stats['running']) ? 'running' : 'idle'; + $stats['status'] = ($stats['running']) ? 'running' : 'idle'; $stats['enabled'] = $this->enabled(); - echo View::render_view( 'rekognizer/ilab-rekognizer-processor.php', $stats); + $stats['title'] = 'Rekognizer Importer'; + $stats['disabledText'] = 'enable Rekognizer'; + $stats['instructions'] = View::render_view('importer/rekognition-instructions.php', []); + $stats['commandLine'] = 'wp rekognition process'; + $stats['commandTitle'] = 'Process Images'; + $stats['cancelCommandTitle'] = 'Cancel Import'; + $stats['cancelAction'] = 'ilab_rekognizer_cancel_process'; + $stats['startAction'] = 'ilab_rekognizer_process_images'; + $stats['progressAction'] = 'ilab_rekognizer_process_progress'; + + echo View::render_view('importer/importer.php', $stats); } /** @@ -578,7 +588,7 @@ public function processImages() { */ public function processProgress() { $stats = BatchManager::instance()->stats('rekognizer'); - $stats['running'] = ($stats['running']) ? 'running' : 'idle'; + $stats['status'] = ($stats['running']) ? 'running' : 'idle'; header('Content-type: application/json'); echo json_encode($stats); diff --git a/classes/Tools/Storage/StorageTool.php b/classes/Tools/Storage/StorageTool.php index 3f66a5d8..6bd6d856 100644 --- a/classes/Tools/Storage/StorageTool.php +++ b/classes/Tools/Storage/StorageTool.php @@ -1618,10 +1618,20 @@ public function renderRegenerator() { $stats['total'] = count($attachments); } - $stats['running'] = ($stats['running']) ? 'running' : 'idle'; + $stats['status'] = ($stats['running']) ? 'running' : 'idle'; $stats['enabled'] = $this->enabled(); - echo View::render_view('storage/regenerator.php', $stats); + $stats['title'] = 'Regenerate Thumbnails'; + $stats['instructions'] = View::render_view('importer/regeneration-instructions.php', []); + $stats['disabledText'] = 'enable Storage'; + $stats['commandLine'] = 'wp mediacloud regenerate'; + $stats['commandTitle'] = 'Regenerate Thumbnails'; + $stats['cancelCommandTitle'] = 'Cancel Regeneration'; + $stats['cancelAction'] = 'ilab_media_cloud_cancel_regenerate'; + $stats['startAction'] = 'ilab_media_cloud_regenerate_files'; + $stats['progressAction'] = 'ilab_media_cloud_regenerate_progress'; + + echo View::render_view('importer/importer.php', $stats); } /** @@ -1630,7 +1640,7 @@ public function renderRegenerator() { public function regenerateProgress() { $stats = BatchManager::instance()->stats('thumbnails'); - $stats['running'] = ($stats['running']) ? 'running' : 'idle'; + $stats['status'] = ($stats['running']) ? 'running' : 'idle'; $stats['enabled'] = $this->enabled(); header('Content-type: application/json'); @@ -1691,10 +1701,20 @@ public function renderImporter() { $stats['total'] = count($attachments); } - $stats['running'] = ($stats['running']) ? 'running' : 'idle'; + $stats['status'] = ($stats['running']) ? 'running' : 'idle'; $stats['enabled'] = $this->enabled(); - echo View::render_view('storage/ilab-storage-importer.php', $stats); + $stats['title'] = 'Storage Importer'; + $stats['instructions'] = View::render_view('importer/storage-importer-instructions.php', []); + $stats['disabledText'] = 'enable Storage'; + $stats['commandLine'] = 'wp mediacloud import'; + $stats['commandTitle'] = 'Import Uploads'; + $stats['cancelCommandTitle'] = 'Cancel Import'; + $stats['cancelAction'] = 'ilab_s3_cancel_import'; + $stats['startAction'] = 'ilab_s3_import_media'; + $stats['progressAction'] = 'ilab_s3_import_progress'; + + echo View::render_view('importer/importer.php', $stats); } /** @@ -1703,7 +1723,7 @@ public function renderImporter() { public function importProgress() { $stats = BatchManager::instance()->stats('storage'); - $stats['running'] = ($stats['running']) ? 'running' : 'idle'; + $stats['status'] = ($stats['running']) ? 'running' : 'idle'; $stats['enabled'] = $this->enabled(); header('Content-type: application/json'); diff --git a/views/storage/regenerator.php b/views/importer/importer.php similarity index 69% rename from views/storage/regenerator.php rename to views/importer/importer.php index 0d8d58d4..7868858e 100644 --- a/views/storage/regenerator.php +++ b/views/importer/importer.php @@ -8,11 +8,11 @@ } .s3-importer-progress-container { - display: relative; + position: relative; width: 100%; - height: 18px; - background: lightgray; - border-radius: 8px; + height: 32px; + background: #AAA; + border-radius: 16px; overflow: hidden; } @@ -46,41 +46,51 @@ #s3-timing-stats { display: none; } + + #s3-importer-status-text { + position: absolute; + left: 16px; top:0px; bottom: 0px; right: 16px; + display: flex; + align-items: center; + color: white; + font-weight: bold; + }
-

Regenerate Thumbnails

+

{{$title}}

-

This tool will rebuild all of the thumbnails for all of your images.

-

Depending on the number of items you have, this could take anywhere from a minute to several hours. This process runs in the background until it's finished. Once you've started the process, please check this page for progress.

-

If you don't have any of the source files on your WordPress server, this will download what it can from your storage service. Obviously this can be very slow going if you are processsing a lot of images. If you only want to regenerate thubmnails for a select group of images, use the bulk action in the media library's list view.

+ {{$instructions}}

Using WP-CLI

You can run this importer process from the command line using WP-CLI:

- wp mediacloud regenerate + {{$commandLine}}
- Regenerate Thumbnails + {{$commandTitle}} - Please enable storage before using this tool. + Please {{$disabledText}} before using this tool.
-
+

Cancelling ... This may take a minute ...

-

The thumbnail regeneration is currently running. Regenerating thumbnails for '{{$currentFile}}' ({{$current}} of {{$total}}). {{number_format($postsPerMinute, 1)}} posts per minute, ETA: {{number_format($eta, 2)}}.

-
+
+
+
Processing '{{$currentFile}}' ({{$current}} of {{$total}}). {{number_format($postsPerMinute, 1)}} posts per minute, ETA: {{number_format($eta, 2)}}.
+
- + +
diff --git a/views/storage/ilab-storage-importer.php b/views/storage/ilab-storage-importer.php deleted file mode 100644 index 771d67c2..00000000 --- a/views/storage/ilab-storage-importer.php +++ /dev/null @@ -1,190 +0,0 @@ - -
-
- -

Storage Importer

-
-
-
-

This tool will import any media and documents you are currently hosting on this server to your cloud storage service.

-

Depending on the number of items you have, this could take anywhere from a minute to several hours. This process runs in the background until it's finished. Once you've started the process, please check this page for progress.

-

Note:

-
    -
  1. If you upload any files while this process is running, you'll need to run this tool again after it finishes.
  2. -
  3. This process DOES NOT delete your files on your server, you'll have to do that yourself manually.
  4. -
  5. You MUST HAVE storage enabled and working in Tools Settings before running this task.
  6. -
-
-

Using WP-CLI

-

You can run this importer process from the command line using WP-CLI:

- - wp mediacloud import - -
-
- - Import Uploads - - Please enable storage before using this tool. - -
-
-
-
-

Cancelling ... This may take a minute ...

-

Storage importer is currently running. Importing '{{$currentFile}}' ({{$current}} of {{$total}}). {{number_format($postsPerMinute, 1)}} posts per minute, ETA: {{number_format($eta, 2)}}.

-
-
-
-
- -
-
-
- \ No newline at end of file