From ca733b17ea9c25888ef408a6853a55daa81caaed Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Sun, 10 Mar 2024 18:18:22 -0300 Subject: [PATCH 1/5] chore: using `uniqid` to generate log file names --- ...n-rest-background-processes-controller.php | 5 ++- .../class-tainacan-background-process.php | 39 +++++++++++++++++-- .../exporter/class-tainacan-exporter.php | 1 - src/migrations.php | 14 +++++++ 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-background-processes-controller.php b/src/classes/api/endpoints/class-tainacan-rest-background-processes-controller.php index 8ee93813c..e071a9d33 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-background-processes-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-background-processes-controller.php @@ -242,8 +242,9 @@ class REST_Background_Processes_Controller extends REST_Controller { } public function prepare_item_for_response($item, $request) { - $item->log = $this->get_log_url($item->ID, $item->action); - $item->error_log = $this->get_log_url($item->ID, $item->action, 'error'); + $key_log = $item->bg_uuid ?? $item->ID; + $item->log = $this->get_log_url($key_log, $item->action); + $item->error_log = $this->get_log_url($key_log, $item->action, 'error'); $nonce = wp_create_nonce( 'wp_rest' ); $item->output = str_replace("&_wpnonce=[nonce]", "&_wpnonce=$nonce", $item->output); return $item; diff --git a/src/classes/class-tainacan-background-process.php b/src/classes/class-tainacan-background-process.php index 2a5d1c8a9..1f932839d 100644 --- a/src/classes/class-tainacan-background-process.php +++ b/src/classes/class-tainacan-background-process.php @@ -114,7 +114,8 @@ abstract class Background_Process extends \Tainacan_WP_Background_Process { 'action' => $this->action, 'name' => $this->get_name(), 'queued_on' => date('Y-m-d H:i:s'), - 'status' => 'waiting' + 'status' => 'waiting', + 'bg_uuid' => uniqid(), ] ); $this->ID = $wpdb->insert_id; @@ -263,6 +264,7 @@ abstract class Background_Process extends \Tainacan_WP_Background_Process { $batch->key = $query->ID; $batch->data = maybe_unserialize( $query->data ); $batch->status = $query->status; + $batch->bg_uuid = $query->bg_uuid; if ($batch->status != 'running') { $this->open($batch->key); @@ -271,6 +273,33 @@ abstract class Background_Process extends \Tainacan_WP_Background_Process { return $batch; } + + /** + * Get batch by key ID + * + * @return stdClass Return the batch + */ + protected function get_batch_by_key($key) { + global $wpdb; + + $table = $this->table; + + $query = $wpdb->get_row( $wpdb->prepare( " + SELECT * + FROM {$table} + WHERE action = %s + AND ID = %s + LIMIT 1 + ", $this->action, $key ) ); + + $batch = new \stdClass(); + $batch->key = $query->ID; + $batch->data = maybe_unserialize( $query->data ); + $batch->status = $query->status; + $batch->bg_uuid = $query->bg_uuid; + return $batch; + } + /** * Handle * @@ -428,10 +457,14 @@ abstract class Background_Process extends \Tainacan_WP_Background_Process { } protected function write_log($key, $log) { - $this->write_log_to_file($key, $log); + $batch = $this->get_batch_by_key($key); + $key_log = $batch->bg_uuid ?? $key; + $this->write_log_to_file($key_log, $log); } protected function write_error_log($key, $log) { - $this->write_log_to_file($key, $log, 'error'); + $batch = $this->get_batch_by_key($key); + $key_log = $batch->bg_uuid ?? $key; + $this->write_log_to_file($key_log, $log, 'error'); } private function recursive_stingify_log_array(array $log, $break = true) { diff --git a/src/classes/exporter/class-tainacan-exporter.php b/src/classes/exporter/class-tainacan-exporter.php index 523a378e9..71f2479c3 100644 --- a/src/classes/exporter/class-tainacan-exporter.php +++ b/src/classes/exporter/class-tainacan-exporter.php @@ -689,7 +689,6 @@ abstract class Exporter { $upload_dir_info = wp_upload_dir(); $prefix = $this->get_id(); $upload_dir = trailingslashit( $upload_dir_info['basedir'] ); - // $upload_url = trailingslashit( $upload_dir_info['baseurl'] ); $exporter_folder = 'tainacan/exporter'; $file_suffix = "{$exporter_folder}/{$prefix}_{$key}"; diff --git a/src/migrations.php b/src/migrations.php index 424dff8fb..161362a44 100644 --- a/src/migrations.php +++ b/src/migrations.php @@ -509,6 +509,20 @@ class Migrations { ); } + + static function alter_table_tnc_bg_process_add_uuid() { + global $wpdb; + // update default order by "creation_date" to "date" + $table_name = $wpdb->prefix . 'tnc_bg_process'; + $column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table_name' AND column_name = 'bg_uuid'" ); + + if(empty($column_exists)) { + $wpdb->query(" + ALTER TABLE $table_name + ADD bg_uuid text NULL + "); + } + } } From 74d88a1728b8207441a9a88f1f1eaac1916742bf Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Sun, 10 Mar 2024 18:18:42 -0300 Subject: [PATCH 2/5] feat: update readme.txt --- src/readme.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/readme.txt b/src/readme.txt index 4f50e8a45..54cf8efdb 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -1,6 +1,6 @@ === Tainacan === -Contributors: andrebenedito, daltonmartins, fabianobn, jacsonp, leogermani, weryques, wetah, eduardohumberto, ravipassos, jessicafpx, marinagiolo, omarceloavila, vnmedeiros, tainacan, r-guimaraes, suelanesilva, ccaio, alanargomes, ateneagarcia123, rodrigo0freire, clarandreozzi -Tags: museums, libraries, archives, GLAM, collections, repository +Contributors: andrebenedito, daltonmartins, fabianobn, jacsonp, leogermani, weryques, wetah, eduardohumberto, ravipassos, jessicafpx, marinagiolo, omarceloavila, vnmedeiros, tainacan, suelanesilva, ccaio, alanargomes, ateneagarcia123, rodrigo0freire, clarandreozzi +Tags: museums, archives, GLAM, collections, repository Requires at least: 5.9 Tested up to: 6.4 Requires PHP: 7.0 @@ -9,13 +9,13 @@ License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html -Tainacan is an open-source, powerful and flexible digital repository platform for WordPress. With all the tools of a professional repository platform, you can manage and publish your digital collections as easily as posting to your blog. It is versatile and can be used to create a digital collection, a digital library or a digital repository for your institutional or personal collection. +Tainacan is an open-source, powerful and flexible digital repository platform for WordPress. == Description == [Tainacan](https://tainacan.org/) is an [open-source](https://github.com/tainacan/tainacan), powerful and flexible digital repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform. It can be used for the creation of a digital collection, a digital library or a digital repository for your institutional or personal collection. -Tainacan aims to facilitate the activities of organizing, documenting, disseminating and displaying digital objects based on simple and accessible principles of digital curation. The plugin integrates with the WordPress block engine, making it easy to reuse objects for different and varied uses. +Tainacan aims to facilitate the activities of organizing, documenting, disseminating and displaying digital objects based on simple and accessible principles of digital curation. The plugin integrates with the WordPress block engine, making it easy to reuse objects for different and varied uses. You can manage and publish your digital collections as easily as posting to your blog. It is versatile and can be used to create a digital collection, a digital library or a digital repository for your institutional or personal collection. From 84985b01caf1036910b4f4f31b96a64428432be3 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Sun, 10 Mar 2024 18:41:19 -0300 Subject: [PATCH 3/5] fix: check user permission on bg-import and bg-export --- .../api/endpoints/class-tainacan-rest-exporters-controller.php | 2 +- .../api/endpoints/class-tainacan-rest-importers-controller.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-exporters-controller.php b/src/classes/api/endpoints/class-tainacan-rest-exporters-controller.php index 6cae2e0b1..e9ff9e251 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-exporters-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-exporters-controller.php @@ -111,7 +111,7 @@ class REST_Exporters_Controller extends REST_Controller { * @throws \Exception */ public function export_permissions_check($request) { - return true; + return current_user_can('manage_tainacan'); } public function get_registered_exporters() { diff --git a/src/classes/api/endpoints/class-tainacan-rest-importers-controller.php b/src/classes/api/endpoints/class-tainacan-rest-importers-controller.php index e45f1b654..5f58e2a7e 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-importers-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-importers-controller.php @@ -137,7 +137,7 @@ class REST_Importers_Controller extends REST_Controller { */ public function import_permissions_check($request){ // TODO - return true; + return current_user_can('manage_tainacan'); } /** From a9ae240e6fe1747052b824dcb2bd53ce803be616 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Mon, 11 Mar 2024 09:07:58 -0300 Subject: [PATCH 4/5] release: update version 0.20.8 --- src/readme.txt | 2 +- src/tainacan.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/readme.txt b/src/readme.txt index 54cf8efdb..b8730873e 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -4,7 +4,7 @@ Tags: museums, archives, GLAM, collections, repository Requires at least: 5.9 Tested up to: 6.4 Requires PHP: 7.0 -Stable tag: 0.20.7 +Stable tag: 0.20.8 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html diff --git a/src/tainacan.php b/src/tainacan.php index 87b9b204e..6a760fd9c 100644 --- a/src/tainacan.php +++ b/src/tainacan.php @@ -5,17 +5,17 @@ Plugin URI: https://tainacan.org/ Description: Open source, powerful and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional repository platform. Author: Tainacan.org Author URI: https://tainacan.org/ -Version: 0.20.7 +Version: 0.20.8 Requires at least: 5.9 Tested up to: 6.4 Requires PHP: 7.0 -Stable tag: 0.20.7 +Stable tag: 0.20.8 Text Domain: tainacan License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html */ -const TAINACAN_VERSION = '0.20.7'; +const TAINACAN_VERSION = '0.20.8'; defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); $TAINACAN_BASE_URL = plugins_url('', __FILE__); From 710f94ccc0e1b6378d54771dae6f4f984a492dc7 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 11 Mar 2024 16:43:37 -0300 Subject: [PATCH 5/5] Hide export and import links if user does not have 'manage_tainacan' capability. --- src/views/admin/components/navigation/primary-menu.vue | 4 ++-- .../components/navigation/tainacan-repository-subheader.vue | 3 +-- src/views/admin/pages/home-page.vue | 4 ++-- src/views/admin/pages/lists/collections-page.vue | 4 +++- src/views/admin/pages/lists/items-page.vue | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/views/admin/components/navigation/primary-menu.vue b/src/views/admin/components/navigation/primary-menu.vue index 94ef1516c..1914c7647 100644 --- a/src/views/admin/components/navigation/primary-menu.vue +++ b/src/views/admin/components/navigation/primary-menu.vue @@ -103,7 +103,7 @@ {{ $i18n.get('capabilities') }} -
  • +
  • {{ $i18n.get('importers') }}
  • -
  • +