Skip to content

Scan Servers

Hostnames: - scan1.shopfactory.io

Access

You can use the following command in the dev-cli to SSH into the server:

dev-cli ssh scan

Access is restricted to developers who need access to run scans. If you need access, please contact the DevOps responsible.

Running Artisan Commands

You can use the following command on the scan server to run artisan commands:

artisan [command]

Directory Structure

The following directories are relevant on the scan server: - ~/scans/{Jira Issue ID}: Used for scan results. - ~/scripts/{Jira Issue ID}: Used for scripts to make it easier for you to run existing Artisan commands (See the example below).

Scripts Example

~/scripts/HS-6942/save-product-translations.sh:

#!/usr/bin/env bash

#set -o nounset
set -o errexit
set -o pipefail
#set -o noclobber

# Set ARTISAN_PATH to the ARTISAN_BIN variable if it is set, otherwise set it to the default value.
ARTISAN_PATH="${ARTISAN_BIN:-/code/core/latest/artisan}"

declare -A textTypeLengths

textTypeLengths["tinytext"]=255
textTypeLengths["text"]=65535
textTypeLengths["mediumtext"]=16777215
textTypeLengths["longtext"]=4294967295

function assertArtisanExists() {
  if [[ ! -f $ARTISAN_PATH ]]; then
    echo "Artisan executable not found: $ARTISAN_PATH"
    exit 1
  fi
}

function saveProductTranslations() {
  local jiraIssueNumber="$1"
  local contentType="$2"
  local textType="$3"

  if [[ -z $jiraIssueNumber ]]; then
    echo "Missing required argument (1): JIRA issue number"
    exit 1
  fi

  if [[ -z $contentType ]]; then
    echo "Missing required argument (2): contentType"
    exit 1
  fi

  if [[ -z $textType ]]; then
    echo "Missing required argument (3): textType"
    exit 1
  fi

  local minLength="${textTypeLengths[$textType]}"

  if [[ -z $minLength ]]; then
    echo "Unable to resolve length for text type: '$textType'"
    exit 1
  fi

  local outputFile="scans/${jiraIssueNumber}/translations/${contentType}.csv"

  # If directory of output file doesn't exist, ask the user if it should be created
  if [[ ! -d $(dirname "$outputFile") ]]; then
    echo "Directory for output file does not exist: '$(dirname "$outputFile")'"
    read -p "Create directory? (y/n) " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
      mkdir -p "$(dirname "$outputFile")"
    else
      echo "Directory not created. Exiting."
      exit 1
    fi
  fi

  php "$ARTISAN_PATH" scan:product-translations --min-length="$minLength" --content-type="$contentType" > "$outputFile"
}

function printHelp() {
  local scriptFileName
  scriptFileName="$(basename "$0")"

  echo "
Description:
  Save product translations to a CSV file.

Usage:
  ${scriptFileName} [options] [--] <jira-issue-number> <content-type> <text-type>

Arguments:
  jira-issue-number                       JIRA issue number; used to determine directory to which results are saved. Example: 'HS-1234'.
  content-type                            Type of content that a translation is for. Example: 'description'.
  text-type                               MySQL text type to scan for. Possible values are: 'tinytext', 'text', 'mediumtext', 'longtext'.

Options:
  -h, --help                                   Display this help message
  "
  exit 1
}

function printHelpIfNeeded() {
  # Print help statement if given no arguments or if any argument is -h or --help
  if [[ $# -eq 0 ]]; then
    printHelp
  fi

  for arg in "$@"; do
    if [[ $arg == "-h" || $arg == "--help" ]]; then
      printHelp
    fi
  done
}

assertArtisanExists
printHelpIfNeeded "$@"
saveProductTranslations "$@"