From ae6bf8ff883d4681b69a18ba1f80c6250da58be6 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Thu, 2 Aug 2018 21:52:51 -0300 Subject: [PATCH 1/2] add query time to get_items API response --- .../endpoints/class-tainacan-rest-items-controller.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/api/endpoints/class-tainacan-rest-items-controller.php b/src/api/endpoints/class-tainacan-rest-items-controller.php index 11c81c7e3..48f544180 100644 --- a/src/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/api/endpoints/class-tainacan-rest-items-controller.php @@ -216,9 +216,13 @@ class REST_Items_Controller extends REST_Controller { if($request['collection_id']) { $collection_id = $request['collection_id']; } - + + $query_start = microtime(true); + $items = $this->items_repository->fetch($args, $collection_id, 'WP_Query'); + $query_end = microtime(true); + $response = []; $return_template = false; @@ -274,6 +278,8 @@ class REST_Items_Controller extends REST_Controller { $rest_response->header('X-WP-Total', (int) $total_items); $rest_response->header('X-WP-TotalPages', (int) $max_pages); + $rest_response->header('X-Tainacan-Query-Time', $query_end - $query_start); + $rest_response->header('X-Tainacan-Elapsed-Time', microtime(true) - $query_start); return $rest_response; } From 04efa1e52a1b6a36d2cedd0582ef1a5f7b5bb09b Mon Sep 17 00:00:00 2001 From: eduardohumberto Date: Thu, 2 Aug 2018 22:56:45 -0300 Subject: [PATCH 2/2] Importers - save post author in csv importers --- src/importer/class-tainacan-importer.php | 10 ++++++++-- src/importer/class-tainacan-old-tainacan.php | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/importer/class-tainacan-importer.php b/src/importer/class-tainacan-importer.php index b0af6efdd..2fc3d3627 100644 --- a/src/importer/class-tainacan-importer.php +++ b/src/importer/class-tainacan-importer.php @@ -112,6 +112,8 @@ abstract class Importer { private $log = []; private $error_log = []; + + private $author = 0; /** * Wether to abort importer execution. @@ -141,7 +143,9 @@ abstract class Importer { @session_start(); } - $this->id = uniqid(); + $this->id = uniqid(); + $this->author = get_current_user_id(); + $_SESSION['tainacan_importer'][$this->get_id()] = $this; if (!empty($attributess)) { @@ -793,7 +797,7 @@ abstract class Importer { } if( !empty( $itemMetadataArray ) && $collection instanceof Entities\Collection ){ - $item->set_collection( $collection ); + $item->set_collection( $collection ); if( $item->validate() ){ $insertedItem = $Tainacan_Items->insert( $item ); @@ -866,6 +870,8 @@ abstract class Importer { $method_name = $steps[$current_step]['callback']; if (method_exists($this, $method_name)) { + $this->add_log('User in process: ' . $this->author); + wp_set_current_user($this->author); $result = $this->$method_name(); } else { $this->add_error_log( 'Callback not found for step ' . $steps[$current_step]['name']); diff --git a/src/importer/class-tainacan-old-tainacan.php b/src/importer/class-tainacan-old-tainacan.php index 3336d6f4e..40252ff01 100644 --- a/src/importer/class-tainacan-old-tainacan.php +++ b/src/importer/class-tainacan-old-tainacan.php @@ -64,6 +64,12 @@ class Old_Tainacan extends Importer{ * */ public function create_taxonomies() { + + if(!$this->get_url()){ + $this->add_error_log('Site url not found'); + $this->abort(); + return false; + } $this->add_log('Creating taxonomies');