FeedsNodeExportParser.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * @file
  4. * Class definition of FeedsNodeExportParser.
  5. */
  6. /**
  7. * Parses a given file as a node export file.
  8. */
  9. class FeedsNodeExportParser extends FeedsParser {
  10. public $format = NULL;
  11. /**
  12. * Implements FeedsParser::parse().
  13. */
  14. public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
  15. if (!($source->importer->processor instanceOf FeedsNodeExportProcessor)) {
  16. drupal_set_message(
  17. t('Node export parser must be used with Node export processor. No nodes imported.'),
  18. 'error'
  19. );
  20. return new FeedsParserResult(array());
  21. }
  22. // Get the node export code.
  23. $code_string = $fetcher_result->getRaw();
  24. // @todo: Do we need this stuff?
  25. //$source_config = $source->getConfigFor($this);
  26. //$state = $source->state(FEEDS_PARSE);
  27. // Execute node_export_import() but don't have it save the nodes.
  28. $result = node_export_import($code_string, 't', FALSE);
  29. // Handle failure.
  30. if (!$result['success']) {
  31. foreach ($result['output'] as $error) {
  32. // @todo: Is this what we should do with output messages?
  33. drupal_set_message($error, 'error');
  34. }
  35. // @todo: Is this the right thing to return for a failure?
  36. return new FeedsParserResult(array());
  37. }
  38. foreach ($result['output'] as $status) {
  39. // @todo: Is this what we should do with output messages?
  40. drupal_set_message($status);
  41. }
  42. // Feeds needs the nodes to be arrays.
  43. // @todo: Should we try to get node_export_import() to return arrays in the
  44. // first place? Or perhaps have the processor accept objects?
  45. foreach ($result['nodes'] as $node) {
  46. $items[] = (array)$node;
  47. }
  48. // Store the format that was used.
  49. $this->format = $result['format'];
  50. /*
  51. // Node export doesn't support batchy stuffs atm.
  52. // Determine section to parse, parse.
  53. $start = $state->pointer ? $state->pointer : $parser->lastLinePos();
  54. $limit = $source->importer->getLimit();
  55. $rows = $this->parseItems($parser, $iterator, $start, $limit);
  56. // Report progress.
  57. $state->total = filesize($fetcher_result->getFilePath());
  58. $state->pointer = $parser->lastLinePos();
  59. $progress = $parser->lastLinePos() ? $parser->lastLinePos() : $state->total;
  60. $state->progress($state->total, $progress);
  61. */
  62. // Create a result object and return it.
  63. return new FeedsParserResult($items);
  64. }
  65. /**
  66. * Override parent::getMappingSources().
  67. */
  68. public function getMappingSources() {
  69. return FALSE;
  70. }
  71. /**
  72. * Override parent::getSourceElement() to use only lower keys.
  73. */
  74. public function getSourceElement(FeedsSource $source, FeedsParserResult $result, $element_key) {
  75. return parent::getSourceElement($source, $result, drupal_strtolower($element_key));
  76. }
  77. /**
  78. * Define defaults.
  79. */
  80. public function sourceDefaults() {
  81. return array();
  82. }
  83. /**
  84. * Source form.
  85. *
  86. * Show mapping configuration as a guidance for import form users.
  87. */
  88. public function sourceForm($source_config) {
  89. $form = array();
  90. return $form;
  91. }
  92. /**
  93. * Define default configuration.
  94. */
  95. public function configDefaults() {
  96. return array();
  97. }
  98. /**
  99. * Build configuration form.
  100. */
  101. public function configForm(&$form_state) {
  102. $form = array();
  103. $form['info'] = array(
  104. '#prefix' => '<p>',
  105. '#markup' => t(
  106. 'This parser uses settings from <a href="!config">node export</a>.',
  107. array('!config' => url('admin/config/content/node_export'))
  108. ),
  109. '#suffix' => '</p>',
  110. );
  111. return $form;
  112. }
  113. /**
  114. *
  115. */
  116. public function getTemplate() {
  117. return;
  118. }
  119. }