Merge branch 'develop' of https://github.com/tainacan/tainacan into develop

This commit is contained in:
weryques 2018-07-27 22:38:26 -03:00
commit 3af62e3539
9 changed files with 261 additions and 71 deletions

View File

@ -6,6 +6,7 @@
<!-- Filter menu compress button --> <!-- Filter menu compress button -->
<button <button
v-if="!openAdvancedSearch" v-if="!openAdvancedSearch"
class="is-hidden-mobile"
id="filter-menu-compress-button" id="filter-menu-compress-button"
:class="{'filter-menu-compress-button-top-repo': isRepositoryLevel}" :class="{'filter-menu-compress-button-top-repo': isRepositoryLevel}"
:style="{ top: !isOnTheme ? '152px' : (searchControlHeight + 6) + 'px' }" :style="{ top: !isOnTheme ? '152px' : (searchControlHeight + 6) + 'px' }"
@ -16,7 +17,7 @@
<aside <aside
:style="{ top: searchControlHeight + 'px' }" :style="{ top: searchControlHeight + 'px' }"
v-show="!isFiltersMenuCompressed && !openAdvancedSearch" v-show="!isFiltersMenuCompressed && !openAdvancedSearch"
class="filters-menu tainacan-form"> class="filters-menu tainacan-form is-hidden-mobile">
<b-loading <b-loading
:is-full-page="false" :is-full-page="false"
:active.sync="isLoadingFilters"/> :active.sync="isLoadingFilters"/>
@ -87,6 +88,7 @@
</router-link> </router-link>
</div> </div>
</section> </section>
</aside> </aside>
<!-- ITEMS LIST AREA (ASIDE THE ASIDE) ------------------------- --> <!-- ITEMS LIST AREA (ASIDE THE ASIDE) ------------------------- -->
@ -348,6 +350,13 @@
</b-field> </b-field>
</div> </div>
<!-- Filters mobile modal button -->
<div class="search-control-item is-hidden-tablet">
<button
@click="isFilterModalActive = !isFilterModalActive"
class="button is-secondary">{{ $i18n.get('filters') }}</button>
</div>
<!-- Text simple search (used on mobile, instead of the one from filter list)--> <!-- Text simple search (used on mobile, instead of the one from filter list)-->
<div class="is-hidden-tablet search-control-item"> <div class="is-hidden-tablet search-control-item">
<div class="search-area"> <div class="search-area">
@ -569,7 +578,58 @@
!openAdvancedSearch"/> !openAdvancedSearch"/>
</div> </div>
</div> </div>
<b-modal
class="tainacan-form filters-mobile-modal is-hidden-tablet"
:active.sync="isFilterModalActive"
:width="736">
<div class="modal-inner-content">
<h3 class="has-text-weight-semibold">{{ $i18n.get('filters') }}</h3>
<a
v-if="!isLoadingFilters &&
((filters.length >= 0 &&
isRepositoryLevel) || filters.length > 0)"
class="collapse-all is-size-7"
@click="collapseAll = !collapseAll">
{{ collapseAll ? $i18n.get('label_collapse_all') : $i18n.get('label_expand_all') }}
<b-icon
type="is-secondary"
size="is-small"
:icon=" collapseAll ? 'menu-down' : 'menu-right'" />
</a>
<br>
<br>
<filters-items-list
v-if="!isLoadingFilters &&
((filters.length >= 0 &&
isRepositoryLevel) || filters.length > 0)"
:filters="filters"
:collapsed="collapseAll"
:is-repository-level="isRepositoryLevel"/>
<section
v-else
class="is-grouped-centered section">
<div class="content has-text-gray has-text-centered">
<p>
<b-icon
icon="filter"
size="is-large"/>
</p>
<p>{{ $i18n.get('info_there_is_no_filter' ) }}</p>
<router-link
v-if="!isOnTheme"
id="button-create-filter"
:to="isRepositoryLevel ? $routerHelper.getNewFilterPath() : $routerHelper.getNewCollectionFilterPath(collectionId)"
tag="button"
class="button is-secondary is-centered">
{{ $i18n.getFrom('filters', 'new_item') }}
</router-link>
</div>
</section>
</div>
</b-modal>
</div> </div>
</template> </template>
@ -604,7 +664,8 @@
advancedSearchResults: false, advancedSearchResults: false,
isDoSearch: false, isDoSearch: false,
searchControlHeight: 0, searchControlHeight: 0,
sortingMetadata: [] sortingMetadata: [],
isFilterModalActive: false
} }
}, },
props: { props: {
@ -1300,6 +1361,7 @@
} }
</style> </style>

View File

@ -7,3 +7,4 @@
@import "../../../node_modules/bulma/sass/components/tabs.sass" @import "../../../node_modules/bulma/sass/components/tabs.sass"
@import "../../../node_modules/bulma/sass/elements/button.sass" @import "../../../node_modules/bulma/sass/elements/button.sass"
@import "../../../node_modules/bulma/sass/grid/columns.sass" @import "../../../node_modules/bulma/sass/grid/columns.sass"
@import "../../../node_modules/bulma/sass/components/modal.sass"

View File

@ -24,16 +24,17 @@ export default {
// Buefy imports // Buefy imports
@import "../../node_modules/buefy/src/scss/components/_datepicker.scss"; @import "../../node_modules/buefy/src/scss/components/_datepicker.scss";
$speed-slow: 0.5s; @import "../../node_modules/buefy/src/scss/utils/_all.scss";
@import "../../node_modules/buefy/src/scss/utils/_functions.scss";
@import "../../node_modules/buefy/src/scss/components/_checkbox.scss"; @import "../../node_modules/buefy/src/scss/components/_checkbox.scss";
@import "../../node_modules/buefy/src/scss/components/_radio.scss"; @import "../../node_modules/buefy/src/scss/components/_radio.scss";
@import "../../node_modules/buefy/src/scss/components/_tag.scss"; @import "../../node_modules/buefy/src/scss/components/_tag.scss";
@import "../../node_modules/buefy/src/scss/components/_loading.scss"; @import "../../node_modules/buefy/src/scss/components/_loading.scss";
@import "../../node_modules/buefy/src/scss/components/_dropdown.scss"; @import "../../node_modules/buefy/src/scss/components/_dropdown.scss";
@import "../../node_modules/buefy/src/scss/components/_modal.scss";
// Tainacan imports // Tainacan imports
@import "../admin/scss/_tables.scss"; @import "../admin/scss/_tables.scss";
@import "../admin/scss/_modals.scss";
@import "../admin/scss/_pagination.scss"; @import "../admin/scss/_pagination.scss";
@import "../admin/scss/_tags.scss"; @import "../admin/scss/_tags.scss";
@import "../admin/scss/_selects.scss"; @import "../admin/scss/_selects.scss";
@ -269,5 +270,33 @@ export default {
} }
} }
.filters-mobile-modal {
// top: 95px;
.modal-close {
right: calc(8.3333333% + 20px);
background-color: $gray1;
&:hover {
background-color: $gray1;
}
&::before, &::after {
background-color: $secondary;
}
}
.modal-content {
margin: 0 8.3333333% 0 0;
padding: 24px $page-side-padding;
border-radius: 0;
height: 100%;
max-height: 100%;
overflow-y: auto;
h3 {
font-size: 100%;
}
}
}
} }
</style> </style>

View File

@ -254,8 +254,6 @@ abstract class Background_Process extends \WP_Background_Process {
// while we are debugging performance // while we are debugging performance
$newRequest = true; $newRequest = true;
do {
$batch = $this->get_batch(); $batch = $this->get_batch();
if ($newRequest) { if ($newRequest) {
@ -264,23 +262,27 @@ abstract class Background_Process extends \WP_Background_Process {
} }
// TODO: find a way to catch and log PHP errors as // TODO: find a way to catch and log PHP errors as
$task = $batch;
do {
try { try {
$task = $this->task( $batch ); $task = $this->task( $task );
} catch (\Exception $e) { } catch (\Exception $e) {
// TODO: Add Stacktrace // TODO: Add Stacktrace
$this->write_error_log($batch->key, ['Fatal Error: ' . $e->getMessage()]); $this->write_error_log($batch->key, ['Fatal Error: ' . $e->getMessage()]);
$this->write_error_log($batch->key, ['Process aborted']); $this->write_error_log($batch->key, ['Process aborted']);
$task = false; $task = false;
} }
} while ( false !== $task && ! $this->time_exceeded() && ! $this->memory_exceeded() );
// Update or close current batch.
if ( false !== $task ) { if ( false !== $task ) {
$this->update( $batch->key, $task ); $this->update( $batch->key, $task );
} else { } else {
$this->close( $batch->key ); $this->close( $batch->key );
} }
} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
$this->unlock_process(); $this->unlock_process();

View File

@ -59,9 +59,15 @@ if ( ! class_exists( 'WP_Background_Process' ) ) {
$this->cron_hook_identifier = $this->identifier . '_cron'; $this->cron_hook_identifier = $this->identifier . '_cron';
$this->cron_interval_identifier = $this->identifier . '_cron_interval'; $this->cron_interval_identifier = $this->identifier . '_cron_interval';
$this->cron_hook_check_identifier = $this->identifier . '_cron_check';
add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
add_action( $this->cron_hook_check_identifier, array( $this, 'handle_cron_healthcheck_check' ) );
add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
if ( ! wp_next_scheduled( $this->cron_hook_check_identifier ) ) {
wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_check_identifier );
}
} }
/** /**
@ -451,6 +457,28 @@ if ( ! class_exists( 'WP_Background_Process' ) ) {
exit; exit;
} }
/**
* Checks the healthcheck
*
* If there is an open process, not running, and not scheduled. schedule it.
*
*/
public function handle_cron_healthcheck_check() {
if ( $this->is_process_running() ) {
// Background process already running.
exit;
}
if ( $this->is_queue_empty() ) {
// No data to process.
$this->clear_scheduled_event();
exit;
}
$this->schedule_event();
}
/** /**
* Schedule event * Schedule event
*/ */

View File

@ -13,6 +13,29 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
abstract class Repository { abstract class Repository {
public $entities_type = '\Tainacan\Entities\Entity'; public $entities_type = '\Tainacan\Entities\Entity';
/**
* If set to false, no logs will be generated upon insertion or update
*
* use enable_logs() and disable_logs() to set the values
* @var bool
*/
private $use_logs = true;
/**
* Disable creation of logs while inerting and updating entities
*/
public function disable_logs() {
$this->use_logs = false;
}
/**
* Enable creation of logs while inerting and updating entities
* if it was disabled
*/
public function enable_logs() {
$this->use_logs = true;
}
/** /**
* Register hooks * Register hooks
*/ */
@ -81,6 +104,8 @@ abstract class Repository {
$old = ''; $old = '';
$diffs = []; $diffs = [];
if ($this->use_logs) {
if ( $obj->get_id() ) { if ( $obj->get_id() ) {
$old = $obj->get_repository()->fetch( $obj->get_id() ); $old = $obj->get_repository()->fetch( $obj->get_id() );
@ -93,6 +118,7 @@ abstract class Repository {
$diffs = $this->diff( $old, $obj ); $diffs = $this->diff( $old, $obj );
} }
}
$map = $this->get_map(); $map = $this->get_map();
@ -137,9 +163,10 @@ abstract class Repository {
} }
// TODO: Logs for header image insert and update // TODO: Logs for header image insert and update
if ($this->use_logs) {
do_action( 'tainacan-insert', $obj, $diffs, $is_update ); do_action( 'tainacan-insert', $obj, $diffs, $is_update );
do_action( 'tainacan-insert-' . $obj->get_post_type(), $obj ); do_action( 'tainacan-insert-' . $obj->get_post_type(), $obj );
}
// return a brand new object // return a brand new object
return new $this->entities_type( $obj->WP_Post ); return new $this->entities_type( $obj->WP_Post );
} }

View File

@ -125,17 +125,9 @@ class CSV extends Importer {
} }
/** /**
* insert processed item from source to Tainacan, adapted to insert their attachments and document * @inheritdoc
*
* @param array $processed_item Associative array with metadatum source's as index with
* its value or values
* @param integer $collection_index The index in the $this->collections array of the collection the item is beeing inserted into
*
* @return Tainacan\Entities\Item Item inserted
*/ */
public function insert( $processed_item, $collection_index ) { public function after_inserted_item( $inserted_item, $collection_index ) {
$inserted_item = parent::insert( $processed_item, $collection_index );
$column_document = $this->get_option('document_index'); $column_document = $this->get_option('document_index');
$column_attachment = $this->get_option('attachment_index'); $column_attachment = $this->get_option('attachment_index');
@ -155,8 +147,6 @@ class CSV extends Importer {
$this->handle_attachment( $values[$column_attachment], $inserted_item); $this->handle_attachment( $values[$column_attachment], $inserted_item);
} }
} }
return $inserted_item;
} }
/** /**
@ -308,6 +298,44 @@ class CSV extends Importer {
* method responsible to insert the item document * method responsible to insert the item document
*/ */
private function handle_attachment( $column_value, $item_inserted){ private function handle_attachment( $column_value, $item_inserted){
$TainacanMedia = \Tainacan\Media::get_instance();
$attachments = explode( $this->get_option('multivalued_delimiter'), $column_value);
if( $attachments ){
foreach( $attachments as $attachment ){
if( strpos($column_value,'file:') !== 0 ){
$this->add_log('Attachment must have "file:" previously the path or url ');
continue;
}
$correct_value = substr($column_value, 5);
if( filter_var($correct_value, FILTER_VALIDATE_URL) ){
$id = $TainacanMedia->insert_attachment_from_url($correct_value, $item_inserted->get_id());
if(!$id){
$this->add_log('Error in Attachment file imported from URL ' . $correct_value);
return false;
}
$this->add_log('Attachment file URL imported from ' . $correct_value);
continue;
}
$server_path_files = $this->get_option('server_path');
$id = $TainacanMedia->insert_attachment_from_file($correct_value, $item_inserted->get_id());
if(!$id){
$this->add_log('Error in Attachment file imported from server ' . $correct_value);
continue;
}
$this->add_log('Attachment file in Server imported from ' . $correct_value);
}
}
} }
} }

View File

@ -770,6 +770,9 @@ abstract class Importer {
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Items->disable_logs();
$Tainacan_Metadata->disable_logs();
$item = new Entities\Item(); $item = new Entities\Item();
$itemMetadataArray = []; $itemMetadataArray = [];
@ -824,6 +827,8 @@ abstract class Importer {
if($insertedItem->validate()) { if($insertedItem->validate()) {
$insertedItem = $Tainacan_Items->update( $insertedItem ); $insertedItem = $Tainacan_Items->update( $insertedItem );
$this->after_inserted_item( $insertedItem, $collection_index );
} else { } else {
$this->add_error_log( 'Error publishing Item' ); $this->add_error_log( 'Error publishing Item' );
$this->add_error_log( $insertedItem->get_errors() ); $this->add_error_log( $insertedItem->get_errors() );
@ -839,6 +844,14 @@ abstract class Importer {
} }
/**
* allow importers executes process after item is insertes
* @param array $insertedItem Associative array with inserted item
* @param integer $collection_index The index in the $this->collections array of the collection the item is beeing inserted into
*
*/
public function after_inserted_item($insertedItem, $collection_index){}
/** /**
* runs one iteration * runs one iteration
*/ */

View File

@ -396,7 +396,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
'458', '458',
utf8_decode( 'Data 33||Rééço' ), utf8_decode( 'Data 33||Rééço' ),
'file:https://d33wubrfki0l68.cloudfront.net/1dbc465f56f3a812f09666f522fa226efd947cfa/a4d9f/images/smashing-cat/newsletter-fish-cat.svg||file:https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/58f72418-b5ee-4765-8e80-e463623a921d/01-httparchive-opt-small.png', 'file:https://d33wubrfki0l68.cloudfront.net/1dbc465f56f3a812f09666f522fa226efd947cfa/a4d9f/images/smashing-cat/newsletter-fish-cat.svg||file:https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/58f72418-b5ee-4765-8e80-e463623a921d/01-httparchive-opt-small.png',
'file:https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg?auto=compress&cs=tinysrgb&h=350'), 'file:https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg'),
array('Data 41', '459', 'Data 43||limbbo', 'file:photos/SamplePNGImage_100kbmb.png||file:audios/SampleAudio_0.4mb.mp3', 'url:http://www.pdf995.com/samples/pdf.pdf'), array('Data 41', '459', 'Data 43||limbbo', 'file:photos/SamplePNGImage_100kbmb.png||file:audios/SampleAudio_0.4mb.mp3', 'url:http://www.pdf995.com/samples/pdf.pdf'),
array('Data 51', '500', 'Data 53', 'file:http://techslides.com/demos/samples/sample.mp4', '') array('Data 51', '500', 'Data 53', 'file:http://techslides.com/demos/samples/sample.mp4', '')
); );