|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Full import commands: |
| 4 | +# |
| 5 | +# local - `bash ./jwplayer-full-import.sh local-dev.consumer-cms 200 338 true` |
| 6 | +# - This doesn't currently work for me on macOS BigSur |
| 7 | +# - Error Message: |
| 8 | +# - "OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: chdir to cwd ("/app/public_html/wp-content") set in config.json failed: no such file or directory: unknown" |
| 9 | +# "Error: OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: chdir to cwd ("/app/public_html/wp-content") set in config.json failed: no such file or directory: unknown" |
| 10 | +# |
| 11 | +# dev - `bash ./jwplayer-full-import.sh cms-accuweather.develop 200 338 false` |
| 12 | +# |
| 13 | +if [ $# -lt 3 ]; then |
| 14 | + echo "usage: $0 <env-name> <posts-per-page> <pages> [is-local-env]" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +ENV_NAME=$1 |
| 19 | +POSTS_PER_PAGE=$2 |
| 20 | +PAGES=${3} |
| 21 | +OFFSET=${4-0} |
| 22 | +IS_LOCAL=${5-false} |
| 23 | + |
| 24 | +run_vip_accuweather_jwplayer_video_import() { |
| 25 | + |
| 26 | + if [[ 0 -eq "$POSTS_PER_PAGE" ]]; then |
| 27 | + POSTS_PER_PAGE=1; |
| 28 | + elif [[ 1000 -lt "$POSTS_PER_PAGE" ]]; then |
| 29 | + POSTS_PER_PAGE=1000; |
| 30 | + fi |
| 31 | + |
| 32 | + if [[ -z "$IS_LOCAL" || "$IS_LOCAL" = false ]]; then |
| 33 | + IS_LOCAL=false |
| 34 | + local LOCAL_ENV="@$ENV_NAME" |
| 35 | + else |
| 36 | + local LOCAL_ENV="--slug=$ENV_NAME dev-env exec" |
| 37 | + fi |
| 38 | + |
| 39 | + # Create log file name. |
| 40 | + # local LOG_FILE_NAME="import_jwplayer_videos_page_${CURRENT_PAGE}_videos_${POSTS_PER_PAGE}_import.log" |
| 41 | + local LOG_FILE_NAME="${ENV_NAME}_import_jwplayer_videos_page_${PAGES}_videos_${POSTS_PER_PAGE}_import.log" |
| 42 | + |
| 43 | + # Run the single import command. |
| 44 | + # Removing verbose as it caused issues: --verbose |
| 45 | + vip "${LOCAL_ENV}" -- wp accuweather import_jwplayer_videos --per-page="$POSTS_PER_PAGE" --pages=1 --offset="$VIDEO_OFFSET" --update-existing --format=table | tee -a "$IMPORT_LOG_DIR/$LOG_FILE_NAME" |
| 46 | + |
| 47 | + # sleep for 5 seconds |
| 48 | + sleep 5 |
| 49 | +} |
| 50 | + |
| 51 | +run_vip_full_jwplayer_video_import() { |
| 52 | + |
| 53 | + if [ -z "$ENV_NAME" ]; then |
| 54 | + return; |
| 55 | + fi |
| 56 | + |
| 57 | + local VIDEO_OFFSET=0 |
| 58 | + local CURRENT_PAGE=1 |
| 59 | + local IMPORT_LOG_DIR="${HOME}/Desktop/jwplayer-full-import-logs" |
| 60 | + |
| 61 | + if [[ 0 -eq "$PAGE" ]]; then |
| 62 | + PAGE=$CURRENT_PAGE |
| 63 | + fi |
| 64 | + |
| 65 | + if [ ! -d "$IMPORT_LOG_DIR" ]; then |
| 66 | + mkdir -p $IMPORT_LOG_DIR |
| 67 | + fi |
| 68 | + |
| 69 | + for (( i=1; i <= PAGES; i++ )); do |
| 70 | + CURRENT_PAGE=$i |
| 71 | + run_vip_accuweather_jwplayer_video_import |
| 72 | + VIDEO_OFFSET=$(( CURRENT_PAGE*POSTS_PER_PAGE )) |
| 73 | + done |
| 74 | +} |
| 75 | + |
| 76 | +run_vip_full_jwplayer_video_import |
0 commit comments