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

Commit

Permalink
Connect the ImportMetaFilter to WpPostImporter #56
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Feb 14, 2016
1 parent 37fc7de commit d63ceca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
28 changes: 28 additions & 0 deletions inc/Import/Filter/PassThroughImportMetaFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Filter;

use
W2M\Import\Type;

/**
* Class PassThroughImportMetaFilter
*
* Just a dummy filter which passes the given value through.
*
* @package W2M\Import\Filter
*/
class PassThroughImportMetaFilter implements ImportMetaFilterInterface {

/**
* @param Type\ImportMetaInterface $meta
* @param int $object_id
*
* @return mixed (The filtered value)
*/
public function filter_value( Type\ImportMetaInterface $meta, $object_id ) {

return $meta->value();
}

}
23 changes: 19 additions & 4 deletions inc/Import/Service/Importer/WpPostImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use
W2M\Import\Data,
W2M\Import\Filter,
W2M\Import\Type,
W2M\Import\Module,
WP_Post,
Expand All @@ -27,17 +28,30 @@ class WpPostImporter implements PostImporterInterface {
*/
private $http;

/**
* @var Filter\ImportMetaFilterInterface $meta_filter
*/
private $meta_filter;

/**
* @param Data\MultiTypeIdMapperInterface $id_mapper
* @param WP_Http $http (Optional)
* @param Filter\ImportMetaFilterInterface $meta_filter (Optional)
*/
public function __construct(
Data\MultiTypeIdMapperInterface $id_mapper,
WP_Http $http = NULL
WP_Http $http = NULL,
Filter\ImportMetaFilterInterface $meta_filter = NULL
) {

$this->id_mapper = $id_mapper;
$this->http = $http ? $http : new WP_Http;
$this->http = $http
? $http
: new WP_Http;

$this->meta_filter = $meta_filter
? $meta_filter
: new Filter\PassThroughImportMetaFilter;
}

/**
Expand Down Expand Up @@ -179,7 +193,7 @@ public function import_post( Type\ImportPostInterface $import_post ) {
$update_post_meta_result = update_post_meta(
$local_id,
$meta->key(),
$meta->value()
$this->meta_filter->filter_value( $meta, $local_id )
);
if ( $update_post_meta_result ) {
continue;
Expand All @@ -193,7 +207,8 @@ public function import_post( Type\ImportPostInterface $import_post ) {
)
);
} else {
foreach ( $meta->value() as $v ) {
$meta_records = $this->meta_filter->filter_value( $meta, $local_id );
foreach ( $meta_records as $v ) {
$add_post_meta_result = add_post_meta(
$local_id,
$meta->key(),
Expand Down

0 comments on commit d63ceca

Please sign in to comment.