0

I'm trying to migrate a csv file that I build from a drupal 6 site.

I have create a view to export those fields: "fid","filemime","filename","image_path","changed","estado" , "estado" is "status" field.

I have check the /web/core/file/migratrions/, also I have read: https://understanddrupal.com/lessons/migrating-files-and-images-drupal/, and some other blog post.

My file.yml is:

# Every migration that references a file by Drupal 6 fid should specify this
# migration as an optional dependency.
id: project_files
label: Public files
audit: true
migration_group: files
audit: true
migration_tags:
  - Drupal 7
  - Files
source:
  plugin: 'csv'
  path: public://csv/files/files.csv
  delimiter: ','
  enclosure: '"'
  header_offset: 0
  constants:
    # The tool configuring this migration must set source_base_path. It
    # represents the fully qualified path relative to which URIs in the files
    # table are specified, and must end with a /. See source_full_path
    # configuration in this migration's process pipeline as an example.
    source_base_path: 'https://domain.es/sites/domain.prod1.domain.es/files/'
    file_directory_path: 'public://old_yaq'
    temp_directory_path: '/tmp'
    is_public: true
  ids:
    - fid
process:
  # If you are using this file to build a custom migration consider removing
  # the fid field to allow incremental migrations.
  fid: fid
  filename: filename
  source_full_path:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/source_base_path
        - image_path
    -
      plugin: urlencode
  destination_full_path:
    plugin: file_uri
    source:
      - image_path
      - constant/file_directory_path
      - constant/temp_directory_path
      - constant/is_public
  uri:
    plugin: file_copy
    source:
      - '@source_full_path'
      - '@destination_full_path'
  filemime: filemime
  # No need to migrate filesize, it is computed when file entities are saved.
  # filesize: filesize
  status: estado
  # Drupal 7 didn't keep track of the file's creation or update time -- all it
  # had was the vague "timestamp" column. So we'll use it for both.
  created:
    plugin: date_2_timestamp
    source:
      - changed
  changed:
    plugin: date_2_timestamp
    source:
      - changed
  uid: uid
destination:
  plugin: entity:file

And this is my plugin

<?php

namespace Drupal\yaq_migration\Plugin\migrate\process;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * Perform custom value transformations.
 *
 * @MigrateProcessPlugin(
 *   id = "date_2_timestamp"
 * )
 *
 * To do custom value transformations use the following:
 */
class DateToTimestamp extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {

    if (empty($value[0])) {
      return time();
    }
    return strtotime($value[0]);
  }

}

I get this output:

[email protected]:/var/www/html $ drush migrate:import project_files
 [notice] Processed 2546 items (0 created, 0 updated, 2546 failed, 0 ignored) - done with 'project_files'

In MigrateToolsCommands.php line 971:
                                      
  project_files Migration - 2546 failed. 

I don't find what it's wrong.

Oskar.

5
  • Did you run drush migrate:messages, just try to show message
    – Jonh
    Aug 25, 2022 at 1:33
  • Seems timestamp is causing the issue. What format is it exported in csv ? Aug 25, 2022 at 2:45
  • Try to migrate first without timestamp field and check if its migrating correctly Aug 25, 2022 at 2:45
  • @Jonh I get this message: "Destination property uri not provided", also I have commented the date fields. Aug 25, 2022 at 16:22
  • that mean, your uri field config not correctly.
    – Jonh
    Aug 29, 2022 at 1:29

1 Answer 1

0

My error was here:

    source:
      - image_path
      - constant/file_directory_path
      - constant/temp_directory_path
      - constant/is_public

It should be constants this s at the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.