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

Commit

Permalink
Provide Interfaces for import data writing #26 #32
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Dec 18, 2015
1 parent ed8235c commit 623cafc
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 5 deletions.
2 changes: 2 additions & 0 deletions inc/Import/Iterator/XmlNodeIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function valid() {

/**
* closes the reader and re-open the URI
*
* Todo: consider if it is necessary or even reliable
*/
public function rewind() {

Expand Down
54 changes: 54 additions & 0 deletions inc/Import/Service/MlpTranslationConnector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Service;

use
W2M\Import\Type,
W2M\Import\Data,
Mlp_Language_Api_Interface,
WP_Error,
WP_Post;

class MlpTranslationConnector implements TranslationConnectorInterface {

/**
* @var Mlp_Language_Api_Interface
*/
private $mlp_language_api;

/**
* @var Data\IdMapperInterface
*/
private $id_mapper;

/**
* @param Mlp_Language_Api_Interface $mlp_language_api
* @param Data\IdMapperInterface $id_mapper
*/
public function __construct(
Mlp_Language_Api_Interface $mlp_language_api,
Data\IdMapperInterface $id_mapper
) {

$this->mlp_language_api = $mlp_language_api;
$this->id_mapper = $id_mapper;
}
/**
* @param $new_term
* @param Type\ImportTermInterface $import_term
* @return bool|WP_Error
*/
public function link_term( $new_term, Type\ImportTermInterface $import_term ) {
// TODO: Implement link_term() method.
}

/**
* @param WP_Post $new_post
* @param Type\ImportPostInterface $import_post
* @return bool|WP_Error
*/
public function link_post( WP_Post $new_post, Type\ImportPostInterface $import_post ) {
// TODO: Implement link_post() method.
}

}
24 changes: 24 additions & 0 deletions inc/Import/Service/ObjectImporterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Service;

use
W2M\Import\Type;

interface ObjectImporterInterface {

/**
* @param Type\ImportTermInterface $term
*
* @return bool|\WP_Error
*/
public function import_term( Type\ImportTermInterface $term );

/**
* @param Type\ImportPostInterface $post
*
* @return bool|\WP_Error
*/
public function import_post( Type\ImportPostInterface $post );

}
27 changes: 27 additions & 0 deletions inc/Import/Service/TranslationConnectorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Service;

use
W2M\Import\Type,
WP_Error,
WP_Post;

interface TranslationConnectorInterface {

/**
* @param $new_term
* @param Type\ImportTermInterface $import_term
*
* @return bool|WP_Error
*/
public function link_term( $new_term, Type\ImportTermInterface $import_term );

/**
* @param WP_Post $new_post
* @param Type\ImportPostInterface $import_post
*
* @return bool|WP_Error
*/
public function link_post( WP_Post $new_post, Type\ImportPostInterface $import_post );
}
81 changes: 81 additions & 0 deletions inc/Import/Service/WpObjectImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Service;

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

class WpObjectImporter implements ObjectImporterInterface {

/**
* @var TranslationConnectorInterface
*/
private $translation_connector;

/**
* @var Data\IdMapperInterface
*/
private $id_mapper;

/**
* Todo: specify this
*/
private $ancestor_resolver;

/**
* @param TranslationConnectorInterface $translation_connector
* @param Data\IdMapperInterface $id_mapper
* @param $ancestor_resolver (Not specified yet)
*/
public function __construct(
TranslationConnectorInterface $translation_connector,
Data\IdMapperInterface $id_mapper,
$ancestor_resolver
) {

$this->translation_connector = $translation_connector;
$this->id_mapper = $id_mapper;
$this->ancestor_resolver = $ancestor_resolver;
}

/**
* @param Type\ImportTermInterface $term
* @return bool|\WP_Error
*/
public function import_term( Type\ImportTermInterface $term ) {

// TODO: Implement import_term() method.

// 1. Insert Term via wp_insert_term()
// 2. set the new term_id(!) via $term->id( $new_term_id );
// 3. connect translations $this->translation_connector->link_term( $new_term, $term );

/**
* Todo: resolve ancestor relation
* Here we don't know and should not depend on whether the parent was already
* imported or not.
*
* $ansestor_resolver->resolve_term( $new_term, $term );
*/
}

/**
* @param Type\ImportPostInterface $post
* @return bool|\WP_Error
*/
public function import_post( Type\ImportPostInterface $post ) {

// 1. Insert Term via wp_insert_term()
// 2. set the new term_id(!) via $term->id( $new_term_id );
// 3. connect translations $this->translation_connector->link_term( $new_post, $post );

/**
* Todo: resolve ancestor relation
* Here we don't know and should not depend on whether the parent was already
* imported or not.
*
* $ansestor_resolver->resolve_term( $new_post, $post );
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace W2M\Import\Type;

/**
* Interface ImportPost
*/
interface ImportPost extends ImportElementInterface {
interface ImportPostInterface extends ImportElementInterface {

/**
* @return string
Expand Down
41 changes: 41 additions & 0 deletions inc/Import/Type/ImportTermInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Type;

/**
* Interface ImportTermInterface
*
* @package W2M\Import\Type
*/
interface ImportTermInterface extends ImportElementInterface {

/**
* @return string
*/
public function taxonomy();

/**
* @return string
*/
public function name();

/**
* @return string
*/
public function slug();

/**
* @return string
*/
public function description();

/**
* @return int
*/
public function origin_parent_term_id();

/**
* @return array
*/
public function locale_relations();
}
2 changes: 1 addition & 1 deletion inc/Import/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Wrapps around XMLReader to iterate over entity objects (terms, users, posts)

## Types

`ImportPost`, `ImportTerm`, etc.
`ImportPostInterface`, `ImportTerm`, etc.

To have a clear defined interface to the importing data. Types are almost immutable. The only value that can changed
once in the object live time is the id of the object, as this gets created when inserting it into DB. This change will
Expand Down

0 comments on commit 623cafc

Please sign in to comment.