/**
  * Constructor.
  */
 public function __construct(Common_API $api, DAO_Factory $dao_factory)
 {
     $this->api = $api;
     $this->post_dao = $dao_factory->create('Post');
     // Register listeners.
     add_action('sme_post_imported', array($this, 'post_imported'), 10, 2);
     add_action('sme_imported', array($this, 'imported'));
 }
 /**
  * Constructor.
  */
 public function __construct(Client $client, DAO_Factory $dao_factory)
 {
     $this->client = $client;
     $this->dao_factory = $dao_factory;
     $this->batch_dao = $dao_factory->create('Batch');
     $this->message_dao = $dao_factory->create('Message');
     $this->post_dao = $dao_factory->create('Post');
     $this->postmeta_dao = $dao_factory->create('Postmeta');
     $this->batch_mgr = new Batch_Mgr($this, $dao_factory);
 }
 /**
  * Constructor.
  */
 public function __construct(Common_API $api, DAO_Factory $dao_factory)
 {
     $this->post_dao = $dao_factory->create('Post');
     $this->api = $api;
     // Register listeners.
     add_action('sme_prepare', array($this, 'prepare_preflight'));
     add_action('sme_store', array($this, 'prepare_preflight'));
     add_action('sme_verify_posts', array($this, 'verify_post'), 10, 2);
     add_action('sme_deploy', array($this, 'prepare_deploy'), 9);
     add_action('sme_import', array($this, 'prepare_deploy'), 9);
 }
 /**
  * Constructor.
  *
  * @param Template               $template
  * @param Batch_Importer_Factory $importer_factory
  * @param Client                 $xmlrpc_client
  * @param Common_API             $api
  * @param DAO_Factory            $dao_factory
  */
 public function __construct(Template $template, Batch_Importer_Factory $importer_factory, Client $xmlrpc_client, Common_API $api, DAO_Factory $dao_factory)
 {
     $this->template = $template;
     $this->importer_factory = $importer_factory;
     $this->xmlrpc_client = $xmlrpc_client;
     $this->api = $api;
     $this->batch_dao = $dao_factory->create('Batch');
     $this->post_dao = $dao_factory->create('Post');
     // Action hooks.
     add_action('admin_post_sme_delete_batches', array($this, 'delete_batches'));
     add_action('admin_notices', array($this, 'delete_batches_notice'));
 }
 /**
  * Constructor.
  *
  * @param Common_API  $api
  * @param DAO_Factory $dao_factory
  */
 public function __construct(Common_API $api, DAO_Factory $dao_factory)
 {
     $this->api = $api;
     $this->batch_dao = $dao_factory->create('Batch');
     $this->custom_dao = $dao_factory->create('Custom');
     $this->option_dao = $dao_factory->create('Option');
     $this->post_dao = $dao_factory->create('Post');
     $this->post_taxonomy_dao = $dao_factory->create('Post_Taxonomy');
     $this->postmeta_dao = $dao_factory->create('Postmeta');
     $this->user_dao = $dao_factory->create('User');
 }
 /**
  * Helper method to trigger a background import.
  */
 public function run_background_import()
 {
     // Make sure a background import has been requested.
     if (!isset($_GET['sme_background_import']) || !$_GET['sme_background_import']) {
         return;
     }
     // Make sure a batch ID has been provided.
     if (!isset($_GET['sme_batch_id']) || !$_GET['sme_batch_id']) {
         return;
     }
     // Make sure a background import key has been provided.
     if (!isset($_GET['sme_import_key']) || !$_GET['sme_import_key']) {
         return;
     }
     $batch_id = intval($_GET['sme_batch_id']);
     $import_key = $_GET['sme_import_key'];
     $batch_dao = $this->dao_factory->create('Batch');
     // Get batch from database.
     $batch = $batch_dao->find($batch_id);
     // No batch to import found, error.
     if (!$batch) {
         error_log(sprintf('Batch with ID %d could not be imported.', $batch_id));
         wp_die(__('Something went wrong', 'sme-content-staging'));
     }
     // Validate key.
     if ($import_key !== $this->api->get_import_key($batch->get_id())) {
         error_log('Unauthorized batch import attempt terminated.');
         $this->api->add_deploy_message($batch->get_id(), __('Something went wrong', 'sme-content-staging'), 'error');
         $this->api->set_deploy_status($batch->get_id(), 2);
         wp_die(__('Something went wrong', 'sme-content-staging'));
     }
     // Background import is running. Make the old import key useless.
     $this->api->generate_import_key($batch);
     // Create the importer.
     $importer = new Batch_Background_Importer($batch);
     // Trigger import.
     $importer->import();
 }