From ef2673d3cf058d94031ee54738f9e9950f86b729 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Mon, 27 Aug 2018 17:40:34 -0300 Subject: [PATCH 01/12] do not attach automatic generated thumbnails to item (#115) --- src/classes/repositories/class-tainacan-items.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 5b1b9268c..194580696 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -425,7 +425,7 @@ class Items extends Repository { $TainacanMedia = \Tainacan\Media::get_instance(); $thumb_blob = $TainacanMedia->get_pdf_cover( $filepath ); if ( $thumb_blob ) { - $thumb_id = $TainacanMedia->insert_attachment_from_blob( $thumb_blob, basename( $filepath ) . '-cover.jpg', $item->get_id() ); + $thumb_id = $TainacanMedia->insert_attachment_from_blob( $thumb_blob, basename( $filepath ) . '-cover.jpg' ); return $thumb_id; } @@ -443,7 +443,7 @@ class Items extends Repository { return $existing_thumb; } else { $TainacanMedia = \Tainacan\Media::get_instance(); - $thumb_id = $TainacanMedia->insert_attachment_from_url( $thumb_url, $item->get_id() ); + $thumb_id = $TainacanMedia->insert_attachment_from_url( $thumb_url ); update_post_meta( $item->get_id(), $meta_key, $thumb_id ); return $thumb_id; From 09e57dd2076d4719bde23598bd54c7ebbecaeda6 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Mon, 27 Aug 2018 17:21:06 -0300 Subject: [PATCH 02/12] Two small changes for making theme list compatible with color change on theme --- src/admin/pages/lists/items-page.vue | 2 +- src/admin/pages/lists/term-items-page.vue | 2 +- src/admin/scss/_tooltips.scss | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/admin/pages/lists/items-page.vue b/src/admin/pages/lists/items-page.vue index f6ccaa385..8885aa5f8 100644 --- a/src/admin/pages/lists/items-page.vue +++ b/src/admin/pages/lists/items-page.vue @@ -52,7 +52,7 @@ {{ $i18n.get('advanced_search') }} + class="is-size-7 is-pulled-right is-hidden-mobile">{{ $i18n.get('advanced_search') }}

{{ $i18n.get('filters') }}

{{ $i18n.get('advanced_search') }} + class="is-size-7 is-pulled-right is-hidden-mobile">{{ $i18n.get('advanced_search') }}

{{ $i18n.get('filters') }}

Date: Tue, 28 Aug 2018 09:47:35 -0300 Subject: [PATCH 03/12] Adds extra loading to prevent blinking while loading metadata in items page. --- src/js/event-bus-search.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/js/event-bus-search.js b/src/js/event-bus-search.js index b6083cf0c..8d40ebe5e 100644 --- a/src/js/event-bus-search.js +++ b/src/js/event-bus-search.js @@ -47,7 +47,6 @@ export default { }, watch: { '$route' (to, from) { - // Should set Collection ID from URL only when in admin. if (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') this.collectionId = !this.$route.params.collectionId ? this.$route.params.collectionId : parseInt(this.$route.params.collectionId); @@ -299,13 +298,12 @@ export default { }, loadItems(to) { - // Forces fetch_only to be filled before any search happens - if (this.$store.getters['search/getPostQuery']['fetch_only'] == undefined) { - this.$emit( 'hasToPrepareMetadataAndFilters', to); - } else { + this.$emit( 'isLoadingItems', true); - this.$emit( 'isLoadingItems', true); - + // Forces fetch_only to be filled before any search happens + if (this.$store.getters['search/getPostQuery']['fetch_only'] == undefined) { + this.$emit( 'hasToPrepareMetadataAndFilters', to); + } else { this.$store.dispatch('collection/fetchItems', { 'collectionId': this.collectionId, 'isOnTheme': (this.$route.name == null), From 19e3b790c6c7e0322b3710d1b21d5779597ef978 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Mon, 27 Aug 2018 18:24:04 -0300 Subject: [PATCH 04/12] change collections rewrite slug --- src/classes/repositories/class-tainacan-collections.php | 3 ++- src/migrations.php | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index a62c0a4cd..5e8df8d22 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -245,7 +245,8 @@ class Collections extends Repository { 'has_archive' => true, 'query_var' => true, 'can_export' => true, - 'rewrite' => true, + /* Translators: The Collections slug - will be the URL for the collections archive */ + 'rewrite' => ['slug' => sanitize_title(_x('collections', 'Slug: the string that will be used to build the URL', 'tainacan'))], 'capability_type' => Entities\Collection::get_capability_type(), 'map_meta_cap' => true, 'supports' => [ diff --git a/src/migrations.php b/src/migrations.php index d3543406c..7467d4e69 100644 --- a/src/migrations.php +++ b/src/migrations.php @@ -273,6 +273,11 @@ class Migrations { } } + + static function refresh_rewrite_rules() { + // needed after we changed the Collections post type rewrite slug + flush_rewrite_rules(false); + } } From 9059eb383379458c804c8d5084a9b3694ca1ffb8 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Tue, 28 Aug 2018 10:33:18 -0300 Subject: [PATCH 05/12] Uses replace instead of push routes on event search bus to prevent browser history messing up. Ref. #85. --- src/js/event-bus-search.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/js/event-bus-search.js b/src/js/event-bus-search.js index 8d40ebe5e..5bd0d2705 100644 --- a/src/js/event-bus-search.js +++ b/src/js/event-bus-search.js @@ -46,7 +46,8 @@ export default { }); }, watch: { - '$route' (to, from) { + '$route' (to, from) { + console.log("router watch"); // Should set Collection ID from URL only when in admin. if (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') this.collectionId = !this.$route.params.collectionId ? this.$route.params.collectionId : parseInt(this.$route.params.collectionId); @@ -290,8 +291,9 @@ export default { this.updateURLQueries(); }, updateURLQueries() { - this.$router.push({query: {}}); - this.$router.push({query: this.$store.getters['search/getPostQuery']}); + console.log("update"); + this.$router.replace({query: {}}); + this.$router.replace({query: this.$store.getters['search/getPostQuery']}); }, updateStoreFromURL() { this.$store.dispatch('search/set_postquery', this.$route.query); @@ -316,7 +318,7 @@ export default { this.$emit( 'hasFiltered', res.hasFiltered); if(res.advancedSearchResults){ - this.$router.push({query: this.$store.getters['search/getPostQuery'],}); + this.$router.replace({query: this.$store.getters['search/getPostQuery'],}); this.$emit('advancedSearchResults', res.advancedSearchResults); } }) From 6f99eb596849f54e98293ffe6a1de746e0778a8f Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Tue, 28 Aug 2018 10:34:55 -0300 Subject: [PATCH 06/12] Removes console logs. --- src/js/event-bus-search.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/js/event-bus-search.js b/src/js/event-bus-search.js index 5bd0d2705..32904f960 100644 --- a/src/js/event-bus-search.js +++ b/src/js/event-bus-search.js @@ -47,7 +47,6 @@ export default { }, watch: { '$route' (to, from) { - console.log("router watch"); // Should set Collection ID from URL only when in admin. if (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') this.collectionId = !this.$route.params.collectionId ? this.$route.params.collectionId : parseInt(this.$route.params.collectionId); @@ -291,7 +290,6 @@ export default { this.updateURLQueries(); }, updateURLQueries() { - console.log("update"); this.$router.replace({query: {}}); this.$router.replace({query: this.$store.getters['search/getPostQuery']}); }, From d80cf9d7ddec93b65e57a843cb9a8f34c3b51d42 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Tue, 28 Aug 2018 11:01:11 -0300 Subject: [PATCH 07/12] adding debug tools to bg process --- .../class-tainacan-background-process.php | 7 ++++- src/classes/libs/wp-background-process.php | 27 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/classes/class-tainacan-background-process.php b/src/classes/class-tainacan-background-process.php index 81af266e5..d6805cec9 100644 --- a/src/classes/class-tainacan-background-process.php +++ b/src/classes/class-tainacan-background-process.php @@ -276,24 +276,29 @@ abstract class Background_Process extends \WP_Background_Process { } } while ( false !== $task && ! $this->time_exceeded() && ! $this->memory_exceeded() ); - + $this->debug('process limit reached'); if ( false !== $task ) { $this->update( $batch->key, $task ); + $this->debug('Batch updated'); } else { $this->close( $batch->key ); + $this->debug('Batch closed'); } $this->unlock_process(); // Start next batch or complete process. if ( ! $this->is_queue_empty() ) { + $this->debug('Dispatch after limit reached'); $this->dispatch(); } else { + $this->debug('Complete'); $this->complete(); $this->write_log($batch->key, ['Process Finished']); } + $this->debug('dying'); wp_die(); } diff --git a/src/classes/libs/wp-background-process.php b/src/classes/libs/wp-background-process.php index d234d7f42..6c3652e71 100644 --- a/src/classes/libs/wp-background-process.php +++ b/src/classes/libs/wp-background-process.php @@ -177,9 +177,9 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { // No data to process. wp_die(); } - + $this->debug('checking nonce'); check_ajax_referer( $this->identifier, 'nonce' ); - + $this->debug('ok!'); $this->handle(); wp_die(); @@ -221,6 +221,7 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { protected function is_process_running() { if ( get_site_transient( $this->identifier . '_process_lock' ) ) { // Process already running. + $this->debug('process already running'); return true; } @@ -235,6 +236,7 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { * defined in the time_exceeded() method. */ protected function lock_process() { + $this->debug('locking process'); $this->start_time = time(); // Set start time of current process. $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute @@ -251,6 +253,7 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { * @return $this */ protected function unlock_process() { + $this->debug('unlocking process'); delete_site_transient( $this->identifier . '_process_lock' ); return $this; @@ -441,17 +444,21 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { * and data exists in the queue. */ public function handle_cron_healthcheck() { + $this->debug('running handle_cron_healthcheck'); if ( $this->is_process_running() ) { // Background process already running. + $this->debug('running handle_cron_healthcheck: process running'); exit; } if ( $this->is_queue_empty() ) { // No data to process. + $this->debug('running handle_cron_healthcheck: queue empty'); $this->clear_scheduled_event(); exit; } + $this->debug('running handle_cron_healthcheck: dispatching'); $this->dispatch(); exit; @@ -475,6 +482,7 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { exit; } + $this->debug('handle_cron_healthcheck_check scheduling event'); $this->schedule_event(); } @@ -485,6 +493,7 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { protected function schedule_event() { if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); + $this->debug('cron event scheduled'); } } @@ -496,6 +505,7 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { if ( $timestamp ) { wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); + $this->debug('cron event unscheduled'); } } @@ -530,5 +540,18 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { */ abstract protected function task( $item ); + /** + * desperate method to help debug bg processes + */ + public function debug($message) { + if ( !defined('TAINACAN_DEBUG_BG_PROCESS') || true !== TAINACAN_DEBUG_BG_PROCESS || !is_string($message) ) { + return; + } + + $message = 'BG_PROCESS: ' . $message; + error_log($message); + + } + } } From 408c58dc31b7a36bcb2b828d28d96331aae02653 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Tue, 28 Aug 2018 11:05:40 -0300 Subject: [PATCH 08/12] avoid notice on test importer --- src/importer/class-tainacan-test-importer.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/importer/class-tainacan-test-importer.php b/src/importer/class-tainacan-test-importer.php index 87939c297..66a594b4a 100644 --- a/src/importer/class-tainacan-test-importer.php +++ b/src/importer/class-tainacan-test-importer.php @@ -690,7 +690,9 @@ class Test_Importer extends Importer { $metadatum->set_name($args['name']); $metadatum->set_collection($collection); $metadatum->set_metadata_type($args['type']); - $metadatum->set_metadata_type_options($args['options']); + if ( isset($args['options']) ) { + $metadatum->set_metadata_type_options($args['options']); + } $metadatum->set_status('publish'); if ($metadatum->validate()) { $metadatum = $this->metadata_repo->insert($metadatum); From b43a599a43f55fa1df4a2d0987fcb087d386b806 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Tue, 28 Aug 2018 13:35:37 -0300 Subject: [PATCH 09/12] Css adjustments. --- src/admin/admin.vue | 2 +- src/admin/components/lists/events-list.vue | 2 +- src/admin/components/lists/items-list.vue | 4 ++-- src/admin/components/lists/processes-list.vue | 2 +- .../components/lists/taxonomies-list.vue | 2 +- src/admin/pages/lists/items-page.vue | 2 +- src/admin/scss/_buttons.scss | 7 +++++++ src/admin/scss/_checkboxes.scss | 2 +- .../scss/_dropdown-and-autocomplete.scss | 6 ++++-- src/admin/scss/_inputs.scss | 12 ++++++++--- src/admin/scss/_modals.scss | 4 +++- .../scss/_repository-level-overrides.scss | 2 +- src/admin/scss/_switches.scss | 2 +- src/admin/scss/_tables.scss | 6 ++++++ src/admin/scss/_tags.scss | 2 ++ src/admin/scss/_tainacan-form.scss | 13 +++++------- src/admin/scss/_view-mode-cards.scss | 20 +++++++++--------- src/admin/scss/_view-mode-grid.scss | 17 +++++++-------- src/admin/scss/_view-mode-records.scss | 21 ++++++++++++------- 19 files changed, 77 insertions(+), 51 deletions(-) diff --git a/src/admin/admin.vue b/src/admin/admin.vue index 68f9dc0ce..f9d323ad7 100644 --- a/src/admin/admin.vue +++ b/src/admin/admin.vue @@ -28,7 +28,7 @@ import TainacanHeader from './components/navigation/tainacan-header.vue'; import TainacanRepositorySubheader from './components/navigation/tainacan-repository-subheader.vue'; - export default { + export default { name: "AdminPage", data(){ return { diff --git a/src/admin/components/lists/events-list.vue b/src/admin/components/lists/events-list.vue index cf5bb34c5..71009b9d8 100644 --- a/src/admin/components/lists/events-list.vue +++ b/src/admin/components/lists/events-list.vue @@ -1,7 +1,7 @@