Skip to content

Commit d7f0aa8

Browse files
committed
Merge branch 'release/v1.7.0'
2 parents c60904e + f928488 commit d7f0aa8

File tree

8 files changed

+65
-13
lines changed

8 files changed

+65
-13
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.7.0] - 2021-04-27
10+
### Added
11+
- New flag to add prefix to sales orders, invoices, credit memos and shipments.
12+
- Ability to change installed version when installing.
13+
14+
### Changed
15+
- Call to the site url changed and backup added.
16+
17+
918
## [1.6.0] - 2020-10-16
1019
### Added
1120
- Added ignore tables option for the main config which is passed to n98-magerun2.

MENU.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ Use the below to generate the menu.sh file from the site [https://argbash.io/gen
44

55
```
66
#!/bin/bash
7-
# version="1.5.1"
7+
# version="1.7.0"
88
#
99
# This is an optional arguments-only example of Argbash potential
1010
#
11-
# ARG_OPTIONAL_BOOLEAN([local-backup], [b], [perform a backup before importing remote], [off])
1211
# ARG_OPTIONAL_BOOLEAN([full], [f], [full database dump])
12+
# ARG_OPTIONAL_BOOLEAN([local-backup], [b], [perform a backup before importing remote], [off])
13+
# ARG_OPTIONAL_BOOLEAN([prefix], [p], [prefix invoices, orders, shipments etc], [off])
1314
# ARG_OPTIONAL_BOOLEAN([wordpress], [w], [include wordpress content], [off])
1415
# ARG_VERSION([echo test v$version])
1516
# ARG_HELP([The general script's help msg])

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Magento 2 Production DB Sync v1.5.1
1+
# Magento 2 Production DB Sync v1.7.0
22

33
## About
44
A script to copy over a production database to another server, also has the ability to copy across imagery.
@@ -11,6 +11,7 @@ Currently the script is configured to attempt Magento 2 and WordPress database m
1111
- MySQL (or equivalent) needs to be installed on both the local machine and the server (obviously).
1212
- Magento 2 needs to be installed and configured on both the local and the host machine.
1313
- rsync needs to be installed locally.
14+
- Magento URL's set in the env.php file `system.default.web.secure.base_url`.
1415

1516
## Installing and Updating
1617
To install or update the script run the following curl script

db-sync.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ while true; do
7171
esac
7272
done
7373

74+
# Add prefix to sequence table
75+
if [ $_arg_prefix == 'on' ]; then
76+
source "${dbsyncutil}prefix.sh";
77+
fi
78+
7479
# Import latest imagery
7580
while true; do
7681
echo -e "\n"

install.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88

99
dbsync_latest_version() {
10-
echo "v1.6.0"
10+
echo "v1.7.0"
1111
}
1212

1313
#
@@ -22,6 +22,15 @@
2222
echo "$DBSYNC_SOURCE_URL"
2323
}
2424

25+
dbsync_version() {
26+
local DBSYNC_VERSION="$(dbsync_latest_version)"
27+
if [ ! -z $1]; then
28+
DBSYNC_VERSION="$1"
29+
fi
30+
31+
echo "$DBSYNC_VERSION"
32+
}
33+
2534
do_install() {
2635
local INSTALL_DIR
2736
INSTALL_DIR="$(dbsync_install_dir)"
@@ -37,7 +46,7 @@
3746
if [ -d "$INSTALL_DIR/.git" ]; then
3847
echo "=> db-sync is already installed in $INSTALL_DIR, trying to update using git"
3948
command printf '\r=> '
40-
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$(dbsync_latest_version)" --depth=1 2>/dev/null || {
49+
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$(dbsync_version $1)" --depth=1 2>/dev/null || {
4150
echo >&2 "Failed to update db-sync, run 'git fetch' in $INSTALL_DIR yourself."
4251
exit 1
4352
}
@@ -56,18 +65,18 @@
5665
echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!'
5766
exit 2
5867
}
59-
command git --git-dir="${INSTALL_DIR}/.git" fetch origin tag "$(dbsync_latest_version)" --depth=1 || {
68+
command git --git-dir="${INSTALL_DIR}/.git" fetch origin tag "$(dbsync_version $1)" --depth=1 || {
6069
echo >&2 'Failed to fetch origin with tags. Please report this!'
6170
exit 2
6271
}
6372
else
64-
command git -c advice.detachedHead=false clone "$(dbsync_source)" -b "$(dbsync_latest_version)" --depth=1 "${INSTALL_DIR}" || {
73+
command git -c advice.detachedHead=false clone "$(dbsync_source)" -b "$(dbsync_version $1)" --depth=1 "${INSTALL_DIR}" || {
6574
echo >&2 'Failed to clone dbsync repo. Please report this!'
6675
exit 2
6776
}
6877
fi
6978
fi
70-
command git -c advice.detachedHead=false --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout -f --quiet "$(dbsync_latest_version)"
79+
command git -c advice.detachedHead=false --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout -f --quiet "$(dbsync_version $1)"
7180
if [ -n "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then
7281
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then
7382
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1
@@ -110,7 +119,7 @@
110119
# during the execution of the install script
111120
#
112121
dbsync_reset() {
113-
unset -f dbsync_install_dir dbsync_latest_version dbsync_source do_install
122+
unset -f dbsync_install_dir dbsync_latest_version dbsync_version dbsync_source do_install
114123
}
115124

116125
do_install

utils/menu.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
version="1.6.0"
2+
version="1.7.0"
33

44
die()
55
{
@@ -24,6 +24,7 @@ begins_with_short_option()
2424
# THE DEFAULTS INITIALIZATION - OPTIONALS
2525
_arg_full="off"
2626
_arg_local_backup="off"
27+
_arg_prefix="off"
2728
_arg_wordpress="off"
2829

2930
dbsync_print_help() {
@@ -35,10 +36,11 @@ dbsync_print_help() {
3536
3637
Make sure you are in a Magento 2 directory before trying to run any scripts.
3738
38-
Usage: db-sync.sh [-b|--local-backup] [-f|--full] [-w|--wordpress] [-v|--version] [-h|--help]
39+
Usage: db-sync.sh [-b|--local-backup] [-f|--full] [-p|--prefix] [-w|--wordpress] [-v|--version] [-h|--help]
3940
Options:
4041
-b, --local-backup: perform a backup before importing remote (off by default)
4142
-f, --full: full database dump (off by default)
43+
-p, --prefix: prefix invoices, orders, shipments etc (off by default)
4244
-w, --wordpress: include wordpress content (off by default)"
4345
-v, --version: Prints version
4446
-h, --help: Prints help
@@ -77,6 +79,18 @@ parse_commandline()
7779
{ begins_with_short_option "$_next" && shift && set -- "-f" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
7880
fi
7981
;;
82+
-p|--no-prefix|--prefix)
83+
_arg_prefix="on"
84+
test "${1:0:5}" = "--no-" && _arg_prefix="off"
85+
;;
86+
-p*)
87+
_arg_prefix="on"
88+
_next="${_key##-p}"
89+
if test -n "$_next" -a "$_next" != "$_key"
90+
then
91+
{ begins_with_short_option "$_next" && shift && set -- "-p" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
92+
fi
93+
;;
8094
-w|--no-wordpress|--wordpress)
8195
_arg_wordpress="on"
8296
test "${1:0:5}" = "--no-" && _arg_wordpress="off"

utils/prefix.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Run the prefix information to the sequence table
4+
echo
5+
echo -e "${txt_blue} Adding prefix to Magento Orders, Invoices, Credit Memo's and Shipping Notes.${txt_end}"
6+
echo
7+
8+
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS -D$DB_DBASE <<EOF
9+
UPDATE sales_sequence_profile SET prefix = IFNULL(CONCAT("TEST", prefix, "-"), "TEST-")
10+
EOF

utils/url_update.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ echo -e ""
55
echo -e "${txt_blue} Update the database urls to current environment.${txt_end}"
66
echo -e ""
77

8-
# TODO: need to catch if this fails
9-
CURRENT_URL=$(n98-magerun config:show web/secure/base_url)
8+
# Get the URL from n98, if the first option fails it'll try the next
9+
if ! CURRENT_URL=$(n98-magerun config:env:show system.default.web.secure.base_url); then
10+
CURRENT_URL=$(n98-magerun config:show web/secure/base_url)
11+
fi
12+
1013
new_domain=${CURRENT_URL,,}
1114
# remove http://
1215
new_domain=$(printf '%s' "${new_domain}" | sed 's/^http:\/\///g')

0 commit comments

Comments
 (0)