wp-cli / media-command

Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
MIT License
44 stars 41 forks source link

WP-CLI Running In Docker Container Unable to Bulk Import Media #151

Closed imjoep closed 3 years ago

imjoep commented 3 years ago

I am attempting to import media via WP-CLI that I uploaded to the uploads directory via ftp. I have changed the owner of the files to www-data.

When I run import of a single file, it works successfully but when I add an “*” it fails, like it thinks that is part of the filename.

root@home-ubuntu:/home/MyStuff/wp/docker-wordpress# docker-compose run --rm wordpress-cli media import /var/www/html/wp-content/uploads/joe_photos/IMG_3112.JPG
Creating new-site_wordpress-cli_run ... done
Imported file '/var/www/html/wp-content/uploads/joe_photos/IMG_3112.JPG' as attachment ID 5427.
Success: Imported 1 of 1 items.
root@home-ubuntu:/home/MyStuff/wp/docker-wordpress# docker-compose run --rm wordpress-cli media import /var/www/html/wp-content/uploads/joe_photos/*
Creating new-site_wordpress-cli_run ... done
Warning: Unable to import file '/var/www/html/wp-content/uploads/joe_photos/*'. Reason: File doesn't exist.
Error: No items imported.

Here is my docker-compose file

version: '3'

services:
  wp-jp-db:
    container_name: ${CONTAINER_DB_NAME}
    image: ${DB_IMAGE:-mariadb}:${DB_VERSION:-latest}
    restart: unless-stopped
    volumes:
      - ${DB_FILES}:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}

  wordpress-jp:
    depends_on:
      - wp-jp-db
    container_name: ${CONTAINER_SITE_NAME}
    image: ${SITE_IMAGE:-wordpress}:${SITE_VERSION:-latest}
    restart: unless-stopped
    volumes:
      - ${SITE_FILES}:/var/www/html
      - ./conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini
      - /home/jpattavina/MyStuff/sync2/data/joe_photos/103APPLE:/var/www/html/photos
    environment:
      WORDPRESS_DB_HOST: ${CONTAINER_DB_NAME}:3306
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
      WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX}
      VIRTUAL_HOST: ${DOMAINS}
      LETSENCRYPT_HOST: ${DOMAINS}
      LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
    logging:
      options:
        max-size: ${LOGGING_OPTIONS_MAX_SIZE:-200k}

  wordpress-cli:
    depends_on:
      - wp-jp-db
    image: wordpress:cli
    user: xfs
    volumes:
      - ${SITE_FILES}:/var/www/html
      - /home/jpattavina/MyStuff/sync2/data/joe_photos/103APPLE:/documents

networks:
   default:
     external:
       name: ${NETWORK}
schlessera commented 3 years ago

@imjoep That is not an issue with WP-CLI, but with your shell. When you use *, your shell will expand this to include all the matching files within the filesystem that you're executing this command - which is your host system, not your docker container.

WP-CLI has no knowledge about the globbing (the use of wildcards like *), this is handled by the shell. Using that within the docker container will require shell code to run within the container, like a short bash script.

imjoep commented 3 years ago

YES!!!! 2 days of troubleshooting resolved in about 10 minutes.

For future reference:
docker-compose run --rm wordpress-cli bash wp media import /path/to/files/*

@schlessera I noticed it takes all files and imports them, whether they have been previously imported or not. Is there a way to skip previously imported files?