FeedsNodeExportProcessor.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @file
  4. * Class definition of FeedsNodeExportProcessor.
  5. */
  6. /**
  7. * Creates nodes from feed items.
  8. */
  9. class FeedsNodeExportProcessor extends FeedsNodeProcessor {
  10. public $new_nodes = array();
  11. /**
  12. * Process the result of the parsing stage.
  13. *
  14. * @param FeedsSource $source
  15. * Source information about this import.
  16. * @param FeedsParserResult $parser_result
  17. * The result of the parsing stage.
  18. */
  19. public function process(FeedsSource $source, FeedsParserResult $parser_result) {
  20. if (!($source->importer->parser instanceOf FeedsNodeExportParser)) {
  21. drupal_set_message(
  22. t('Node export processor must be used with Node export parser. No nodes imported.'),
  23. 'error',
  24. FALSE
  25. );
  26. return new FeedsParserResult(array());
  27. }
  28. parent::process($source, $parser_result);
  29. }
  30. /**
  31. * Creates a new node in memory and returns it.
  32. */
  33. /*
  34. @todo: Should we override this function?
  35. protected function newEntity(FeedsSource $source) {
  36. $node = new stdClass();
  37. $node->type = $this->config['content_type'];
  38. $node->changed = REQUEST_TIME;
  39. $node->created = REQUEST_TIME;
  40. $node->language = LANGUAGE_NONE;
  41. node_object_prepare($node);
  42. // Populate properties that are set by node_object_prepare().
  43. $node->log = 'Created by FeedsNodeProcessor';
  44. $node->uid = $this->config['author'];
  45. return $node;
  46. }
  47. */
  48. /**
  49. * Loads an existing node.
  50. *
  51. * If the update existing method is not FEEDS_UPDATE_EXISTING, only the node
  52. * table will be loaded, foregoing the node_load API for better performance.
  53. */
  54. /*
  55. @todo: Should we override this function?
  56. protected function entityLoad(FeedsSource $source, $nid) {
  57. if ($this->config['update_existing'] == FEEDS_UPDATE_EXISTING) {
  58. $node = node_load($nid, NULL, TRUE);
  59. }
  60. else {
  61. // We're replacing the existing node. Only save the absolutely necessary.
  62. $node = db_query("SELECT created, nid, vid, type FROM {node} WHERE nid = :nid", array(':nid' => $nid))->fetchObject();
  63. $node->uid = $this->config['author'];
  64. }
  65. node_object_prepare($node);
  66. // Populate properties that are set by node_object_prepare().
  67. if ($this->config['update_existing'] == FEEDS_UPDATE_EXISTING) {
  68. $node->log = 'Updated by FeedsNodeProcessor';
  69. }
  70. else {
  71. $node->log = 'Replaced by FeedsNodeProcessor';
  72. }
  73. return $node;
  74. }
  75. */
  76. /**
  77. * Save a node.
  78. *
  79. * This code is similar to some code in node_export_import()
  80. * which gets executed for each node when the $save param is TRUE.
  81. *
  82. * @todo: should we check to make sure FeedsNodeExportParser was used?
  83. */
  84. public function entitySave($entity) {
  85. $node = &$entity;
  86. node_export_save($node);
  87. $this->new_nodes[$node->nid] = $node;
  88. // @todo: Is this what we should do with output messages?
  89. drupal_set_message(t("Imported node !nid: !node", array(
  90. '!nid' => $node->nid,
  91. '!node' => l($node->title, 'node/' . $node->nid)
  92. )));
  93. }
  94. }