Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Implement Module\ResolvingPendingMetaFilter for posts #56
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Feb 18, 2016
1 parent 3c25ca7 commit 092870b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 4 deletions.
90 changes: 88 additions & 2 deletions inc/Import/Module/ResolvingPendingMetaFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace W2M\Import\Module;

use
W2M\Import\Data;
W2M\Import\Data,
W2M\Import\Filter,
W2M\Import\Type;

/**
* Class ResolvingPendingMetaFilter
Expand Down Expand Up @@ -33,6 +35,90 @@ public function __construct( Data\ImportListeningMetaFilterList $meta_filter_lis
*/
public function resolve_pending_meta_filter() {

// Todo: Iterate over postponed meta filters and re-apply them
/**
* Used to attach process logger
*
* @param Data\ImportListeningMetaFilterList $meta_list
*/
do_action( 'w2m_import_meta_filter_resolving_start', $this->meta_list );

$post_filter_storage = $this->meta_list->get_filters( 'post' );
/**
* @var array $filter_list
* @var Type\MetaRecordIndexInterface $meta_index
*/
foreach ( $post_filter_storage as $filter_list => $meta_index ) {
/* @var array $data */
foreach ( $filter_list as $data )
$this->apply_post_filter( $meta_index, $data[ 'filter' ], $data[ 'meta' ] );
}

// Todo #56: Handle meta data for user, comment and term types
}

/**
* Todo: Exclude this to a separate service object
*
* @param Type\MetaRecordIndexInterface $meta_index
* @param Filter\ValueFilterableInterface $filter
* @param Type\ImportMetaInterface $meta
*/
private function apply_post_filter(
Type\MetaRecordIndexInterface $meta_index,
Filter\ValueFilterableInterface $filter,
Type\ImportMetaInterface $meta
) {

$filtered_value = $this->get_filtered_value( $meta_index, $filter, $meta );
$preview_value = '';
if ( ! $meta->is_single() ) {
$meta_records = $meta->value();
$preview_value = $meta_records[ $meta_index->index() ];
}

update_post_meta(
$meta_index->object_id(),
$meta_index->key(),
$filtered_value,
$preview_value
);
}

/**
* Todo: Exclude this to a separate service object
*
* @param Type\MetaRecordIndexInterface $meta_index
* @param Filter\ValueFilterableInterface $filter
* @param Type\ImportMetaInterface $meta
*
* @return mixed
*/
private function get_filtered_value(
Type\MetaRecordIndexInterface $meta_index,
Filter\ValueFilterableInterface $filter,
Type\ImportMetaInterface $meta
) {

if ( ! $filter->is_filterable( $meta->value(), $meta_index->object_id() ) ) {
/**
* Fires when a filter is not resolvable
*
* @param Filter\ValueFilterableInterface $filter
* @param Type\MetaRecordIndexInterface $meta_index
* @param Type\ImportMetaInterface $meta
*/
do_action( 'w2m_import_meta_filter_not_resolvable', $filter, $meta_index, $meta );
}

if ( $meta->is_single() ) {
return $filter->filter( $meta->value(), $meta_index->object_id() );
}

$meta_records = $meta->value();

return $filter->filter(
$meta_records[ $meta_index->index() ],
$meta_index->object_id()
);
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Use the installer via back-end of your install or ...

* `w2m_import_meta_not_filterable` in `W2M\Import\Service\ImportMetaFilter::filter_value()`
* `w2m_import_meta_filter` in `W2M\Controller\MetaFilterApi::register_filter()`

* `w2m_import_meta_filter_not_resolvable` in `W2M\Import\Module\ResolvingPendingMetaFilter::w2m_import_meta_filter_not_resolvable`

## Other Notes

Expand All @@ -117,4 +117,4 @@ you can use it free of charge on your personal or commercial blog.

### Contact & Feedback
Please let us know if you like the plugin or you hate it or whatever ...
Please fork it, add an issue for ideas and bugs.
Please fork it, add an issue for ideas and bugs.

0 comments on commit 092870b

Please sign in to comment.