3

I'm migrating content from a Joomla SQL source. The images are stored inside of the text as inline images.

This is how my source data looks like:

+------------+--------------------------------------------------+
|    id      |  introtext                                       |
+------------+--------------------------------------------------+
| 1          | <h1>...</h1><img src="...                        |
| 2          | <h1>...</h1><p>...                               |
| 3          | <h1>...</h1><img src="..."/><img src="...        |
+------------+--------------------------------------------------+

Here is my Source:

/**
 * Source plugin for image content.
 *
 * @MigrateSource(
 *   id = "image"
 * )
 */
 class Image extends SqlBase {

   /**
    * {@inheritdoc}
    */
   public function query() {
     $query = $this->select('jos_content', 'content');
     $query->fields('content', array(
       'id',
       'introtext',
     ));

     $query->condition('content.state', 1);

     $query->condition('content.introtext', '%<img%', 'LIKE');

     return $query;
   }

   ...

But this query does not produce one Row per Match, it produces one row for each source row where are at least is one image. I don't know if it's possible to process this in my migration .yml file:

id: image
label: Images migration
migration_group: joomla
migration_tags:
  - Images
source:
  plugin: image
  constants:
    file_source_uri: 'public://import'
    file_dest_uri: 'public://imported'
    status: 1
destination:
  plugin: 'entity:file'
process:
  file_source:
-
  plugin: concat
  delimiter: /
  source:
    - constants/file_source_uri
    - path
  file_dest:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/file_dest_uri
        - filename
  filename: filename
  uri:
    plugin: file_copy
    source:
      - '@file_source'
      - '@file_dest'
  status: constants/status
migration_dependencies:
  required: {  }
  optional: {  }
dependencies:
  enforced:
    module:
      - migrate_content

This configuration works only if there is one image per Migration Row, but there are multiple items per row. I would appreciate any help, thank you!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.