Update image paths

This commit is contained in:
Mauricio Dinarte 2020-10-04 17:51:12 -06:00
parent 48ff8401e9
commit 90ec6af8f9
8 changed files with 21 additions and 21 deletions

2
04.txt
View file

@ -14,7 +14,7 @@ source:
unique_id: 1
name: 'Michele Metts'
profile: '<a href="https://www.drupal.org/u/freescholar" title="Michele on Drupal.org">freescholar</a> on Drupal.org'
photo_url: 'https://agaric.coop/sites/default/files/2018-12/micky-cropped.jpg'
photo_url: 'https://udrupal.com/photos/freescholar.jpg'
photo_description: 'Photo of Michele Metts'
photo_width: '587'
photo_height: '657'

6
05.txt
View file

@ -91,18 +91,18 @@ Lets see part of the _source_ definition:
```yaml
source:
constants:
BASE_URL: "https://agaric.coop"
BASE_URL: "https://udrupal.com"
PHOTO_DESCRIPTION_PREFIX: "Photo of"
plugin: embedded_data
data_rows:
- unique_id: 1
name: "Michele Metts"
photo_url: "sites/default/files/2018-12/micky-cropped.jpg"
photo_url: "photos/freescholar.jpg"
photo_width: "587"
photo_height: "657"
```
Only one record is presented to keep snippet short, but more exist. In addition to having a unique identifier, each record includes a name, a short profile, and details about the image. Note that this time, the `photo_url` does not provide an absolute URL. Instead, it is a relative path from the domain hosting the images. In this example, the domain is `https://agaric.coop` so that value is stored in the BASE_URL constant which is later used to assemble a valid absolute URL to the image. Also, there is no photo description, but one can be created by concatenating some strings. The PHOTO_DESCRIPTION_PREFIX constant stores the prefix to add to the name to create a photo description.
Only one record is presented to keep snippet short, but more exist. In addition to having a unique identifier, each record includes a name, a short profile, and details about the image. Note that this time, the `photo_url` does not provide an absolute URL. Instead, it is a relative path from the domain hosting the images. In this example, the domain is `https://udrupal.com` so that value is stored in the BASE_URL constant which is later used to assemble a valid absolute URL to the image. Also, there is no photo description, but one can be created by concatenating some strings. The PHOTO_DESCRIPTION_PREFIX constant stores the prefix to add to the name to create a photo description.
Now, lets see the _process_ definition:

10
07.txt
View file

@ -20,18 +20,18 @@ The _source_ of a migration is independent of its _destination_. The following c
```yaml
source:
constants:
SOURCE_DOMAIN: "https://agaric.coop"
SOURCE_DOMAIN: "https://udrupal.com"
DRUPAL_FILE_DIRECTORY: "public://portrait/"
plugin: embedded_data
data_rows:
- photo_id: "P01"
photo_url: "sites/default/files/2018-12/micky-cropped.jpg"
photo_url: "photos/freescholar.jpg"
- photo_id: "P02"
photo_url: ""
- photo_id: "P03"
photo_url: "sites/default/files/pictures/picture-94-1480090110.jpg"
photo_url: "photos/gnuget.jpg"
- photo_id: "P04"
photo_url: "sites/default/files/2019-01/clayton-profile-medium.jpeg"
photo_url: "photos/cedewey.jpg"
ids:
photo_id:
type: string
@ -103,7 +103,7 @@ psf_source_image_path:
- plugin: urlencode
```
The end result of this operation will be something like `https://agaric.coop/sites/default/files/2018-12/micky-cropped.jpg`. Note that the `concat` and `url_encode` plugins are used just like in the previous step. A subtle difference is that a `delimiter` is specifying in the concatenation step. This is because, contrary to the `DRUPAL_FILE_DIRECTORY` constant, the `SOURCE_DOMAIN` constant does not end with a _slash_ (**/**). This was done intentionally to highlight two things. First, it is important to understand your source data. Second, you can transform it as needed by using various process plugins.
The end result of this operation will be something like `https://udrupal.com/photos/freescholar.jpg`. Note that the `concat` and `url_encode` plugins are used just like in the previous step. A subtle difference is that a `delimiter` is specifying in the concatenation step. This is because, contrary to the `DRUPAL_FILE_DIRECTORY` constant, the `SOURCE_DOMAIN` constant does not end with a _slash_ (**/**). This was done intentionally to highlight two things. First, it is important to understand your source data. Second, you can transform it as needed by using various process plugins.
## Copying the image file to Drupal

6
15.txt
View file

@ -98,9 +98,9 @@ The final example will show a slight variation of the previous configuration. Th
| | |
|-|-|-|
| P01 | https://agaric.coop/sites/default/files/pictures/picture-15-1421176712.jpg |
| P02 | https://agaric.coop/sites/default/files/pictures/picture-3-1421176784.jpg |
| P03 | https://agaric.coop/sites/default/files/pictures/picture-2-1421176752.jpg |
| P01 | https://udrupal.com/photos/freescholar.jpg |
| P02 | https://udrupal.com/photos/mlncn.jpg |
| P03 | https://udrupal.com/photos/sfreudenberg.jpg |
```yaml

4
16.txt
View file

@ -41,7 +41,7 @@ This migration will reuse the same configuration from the [introduction to parag
"udm_photos": [
{
"photo_id": "P01",
"photo_url": "https://agaric.coop/sites/default/files/pictures/picture-15-1421176712.jpg",
"photo_url": "https://udrupal.com/photos/freescholar.jpg",
"photo_dimensions": [240, 351]
},
{...},
@ -207,7 +207,7 @@ Let's consider an example where the records to migrate have *more data than need
"udm_photos": [
{
"photo_id": "P01",
"photo_url": "https://agaric.coop/sites/default/files/pictures/picture-15-1421176712.jpg",
"photo_url": "https://udrupal.com/photos/freescholar.jpg",
"photo_dimensions": [240, 351]
},
{...},

4
17.txt
View file

@ -44,7 +44,7 @@ This migration will reuse the same configuration from the [introduction to parag
</udm_book_paragraph>
<udm_photos>
<photo_id>P01</photo_id>
<photo_url>https://agaric.coop/sites/default/files/pictures/picture-15-1421176712.jpg</photo_url>
<photo_url>https://udrupal.com/photos/freescholar.jpg</photo_url>
<photo_dimensions>
<width>240</width>
<height>351</height>
@ -229,7 +229,7 @@ Let's consider an example where the elements to migrate have *more data than nee
<data>
<udm_photos>
<photo_id>P01</photo_id>
<photo_url>https://agaric.coop/sites/default/files/pictures/picture-15-1421176712.jpg</photo_url>
<photo_url>https://udrupal.com/photos/freescholar.jpg</photo_url>
<photo_dimensions>
<width>240</width>
<height>351</height>

6
20.txt
View file

@ -78,9 +78,9 @@ destination:
Now let's consider an example of a spreadsheet file that does not have a header row. This example is for the *image* migration and uses a Microsoft Excel file. The following snippets shows the `UD Example Sheet` worksheet and the configuration of the *source* plugin:
```
P01, https://agaric.coop/sites/default/files/pictures/picture-15-1421176712.jpg
P02, https://agaric.coop/sites/default/files/pictures/picture-3-1421176784.jpg
P03, https://agaric.coop/sites/default/files/pictures/picture-2-1421176752.jpg
P01, https://udrupal.com/photos/freescholar.jpg
P02, https://udrupal.com/photos/mlncn.jpg
P03, https://udrupal.com/photos/sfreudenberg.jpg
```
```yaml

4
28.txt
View file

@ -42,7 +42,7 @@ $ drush migrate:import udm_csv_source_image --migrate-debug --limit=1
└──────────────────────────────────────────────────────────────────────────────┘
array (10) [
'photo_id' => string (3) "P01"
'photo_url' => string (74) "https://agaric.coop/sites/default/files/pictures/picture-15-1421176712.jpg"
'photo_url' => string (74) "https://udrupal.com/photos/freescholar.jpg"
'path' => string (76) "modules/custom/ud_migrations/ud_migrations_csv_source/sources/udm_photos.csv"
'ids' => array (1) [
string (8) "photo_id"
@ -69,7 +69,7 @@ array (10) [
array (4) [
'psf_destination_filename' => string (25) "picture-15-1421176712.jpg"
'psf_destination_full_path' => string (25) "picture-15-1421176712.jpg"
'psf_source_image_path' => string (74) "https://agaric.coop/sites/default/files/pictures/picture-15-1421176712.jpg"
'psf_source_image_path' => string (74) "https://udrupal.com/photos/freescholar.jpg"
'uri' => string (29) "./picture-15-1421176712_6.jpg"
]
┌──────────────────────────────────────────────────────────────────────────────┐