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

Prevent double Imports (Implement Import Filters) #49

Open
derpixler opened this issue Jan 26, 2016 · 1 comment
Open

Prevent double Imports (Implement Import Filters) #49

derpixler opened this issue Jan 26, 2016 · 1 comment
Labels
Milestone

Comments

@derpixler
Copy link
Contributor

When we run the Import more then one time, then we get doublicated data.

981d2d08-c43c-11e5-8a1e-7a4513efe6f0

@derpixler derpixler added the bug label Jan 26, 2016
@dnaber-de
Copy link
Member

Sure thing, thats a missing feature. Some thoughts about this…

  • The implementation should be independent and outside of the existing PostImporterInterface structure. So it wont go into WpPostImporter
  • This could better go into a new ImportFilterInterface which checks each Type\ImportPostInterface whether it should be imported or not:
namespace W2M\Import\Filter;

use
    W2M\Import\Type;

interface PostImportFilterInterface {

    /**
     * Checks if a post should be imported or not
     * 
     * @param Type\ImportPostInterface $import_post
     *
     * @return bool
     */
    public function post_to_import( Type\ImportPostInterface $import_post );
}
  • To connect the Filter with the import logic, the Import\Service\PostProcessor depends additionaly on the Filter, and asks for each post before passing it to the importer.
  • A basic implementor of PostFilterInterface has two tasks: Of course it implements post_to_import() method. Furthermore it listens to the w2m_post_imported action with a second method. The strategy to identify already imported posts could be to save post_guids/origin_ids as post-meta for the imported posts.
namespace W2M\Import\Filter;

use
    W2M\Import\Type,
    WP_Post;

class DuplicatePostFilter implements PostFilterInterface {

    /**
     * Checks if a post should be imported or not
     * 
     * @param Type\ImportPostInterface $import_post
     *
     * @return bool
     */
    public function post_to_import( Type\ImportPostInterface $import_post ) {
        // check for existing post here
    }

    /**
     * Records new imported post
     * 
     * @wp-hook w2m_post_imported
     *
     * @param WP_Post $wp_post
     * @param Type\ImportPostInterface $import_post
     */
    public function mark_imported_post( WP_Post $wp_post, Type\ImportPostInterface $import_post ) {
        // save post meta to identify the post here
    }
}

Update
It's important to have a separate Interface for the w2m_{TYPE}_imported action listeners ( #54 )

@dnaber-de dnaber-de changed the title Prevent double Imports Prevent double Imports (Implement Import Filters) Feb 2, 2016
@derpixler derpixler mentioned this issue Feb 7, 2016
43 tasks
dnaber-de added a commit that referenced this issue Feb 7, 2016
dnaber-de added a commit that referenced this issue Feb 7, 2016
dnaber-de added a commit that referenced this issue Feb 7, 2016
dnaber-de added a commit that referenced this issue Feb 7, 2016
dnaber-de added a commit that referenced this issue Feb 7, 2016
@dnaber-de dnaber-de added this to the 2.0.0-alpha milestone Feb 10, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants