Skip to content

Commit

Permalink
Merge pull request #99 from grueneschweiz/dev
Browse files Browse the repository at this point in the history
0.17.0
  • Loading branch information
cyrillbolliger authored Nov 6, 2020
2 parents 6590baf + 8373638 commit 0a26609
Show file tree
Hide file tree
Showing 36 changed files with 6,601 additions and 5,409 deletions.
22 changes: 22 additions & 0 deletions scripts/export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

mkdir export

urls=( $(wp site list --field=url) )
domains=( $( wp site list --field=domain ) )
paths=( $( wp site list --field=path | sed 's/\///g' ) )
post_types="post page attachment"

for i in "${!domains[@]}"
do
site="${domains[$i]}_${paths[$i]}"
url="${urls[i]}"
for type in ${post_types[*]}
do
wp --url="$url" export --post_type="$type" --dir="./export" --filename_format="${site}.${type}.xml"
done
done

echo "SUCCESS: exported all ${post_types[*]} into ./export"
110 changes: 110 additions & 0 deletions scripts/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

set -e

usage()
{
echo "This command will import posts, pages and attachments of the given sites (site_slugs)."
echo ""
echo "Usage: import [ -h ] network_url site_slugs..."
echo " -h This screen"
echo " network_url The base url of the WPMU network. With trailing slash!"
echo " site_slugs The slugs of the site where the content should be imported"
echo ""
echo "The files with the content to import must be placed in ./import and stick to the"
echo 'following naming convention: ${site_slug}.${post_type}.xml'
echo "Example: ./import/lausanne.attachment.xml"
echo ""
echo "The command must be executed from the WordPress' base directory."
exit 2
}

import_attachments() {
local file="$1" # wxr import file
local url="$2" # site url (multisite)

for i in {1..10}
do
echo "importing attachments. attempt $i"
if wp --url="$url" import --authors=skip "$file"; then
echo "SUCCESS: imported all attachments"
i=0
break
fi
done

if [ $i -ge 10 ]; then
echo "ERROR importing attachments"
exit 1
fi
}

import_post_type() {
local post_type="$1"
local file="$2" # wxr import file
local url="$3" # site url (multisite)

if [ ! -f "$file" ]; then
echo "ERROR: Import file could not be found. Looking for: $file"
echo "Call $0 -h for more information"
exit 1
fi

if [[ $post_type == "attachment" ]]; then
import_attachments "$file" "$url"
else
wp --url="$url" import --authors=skip "$file"
fi
}


migrate_post_content() {
local url="$1"
if wp --url="$url" eval-file "wp-content/themes/les-verts/lib/admin/import-handler.php"; then
echo "Migration completed"
else
echo "ERROR migrating content."
exit 1
fi
}


while getopts 'h' opt
do
case "$opt" in
"h") usage; exit 1 ;;
*) usage; exit 1 ;;
esac
done

if [ -z "$1" ] || [ -z "$2" ]; then
usage
exit 1
fi

base_url="$1"
shift 1
sites=( "$@" )

post_types=(post page attachment)

for site in ${sites[*]}
do
echo
echo "Start importing $site..."

url="${base_url}${site}"

for post_type in ${post_types[*]}
do
file="./import/${site}.${post_type}.xml"
echo "Importing $post_type for $site from $file..."
import_post_type "$post_type" "$file" "$url"
done

echo "Migrating post content..."
migrate_post_content "$url"
done

echo "SUCCESS. All done. Don't forget to remove the import files!"

22 changes: 6 additions & 16 deletions scripts/wp-configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,16 @@
# README:
# * this script should not break things on
# existing website in production
#
# PARAMETERS:
# -n treat this installation as multi site
# (network)
#===========================================

set -e

# detect if it's a multisite installation
NETWORK=
while getopts "n" opt; do
case $opt in
n)
NETWORK=1
echo "WP multi site support enabled."
;;
?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
if wp site list; then
NETWORK=1
echo "WP multisite detected."
fi

# set time zone
$WPCLI option update timezone_string "Europe/Zurich"
Expand Down Expand Up @@ -80,6 +69,7 @@ $WPCLI option patch insert --json tribe_events_calendar_options tribeDisableTrib
$WPCLI option patch insert --json tribe_events_calendar_options donate-link false
$WPCLI option patch insert tribe_events_calendar_options viewOption list
$WPCLI option patch insert tribe_events_calendar_options datepickerFormat "11"
$WPCLI option patch insert --json tribe_events_calendar_options views_v2_enabled false

# configure searchwp
$WPCLI option set --json searchwp_engines '{"default":{"label":"Default","settings":{"stemming":true,"adminengine":false},"sources":{"post.post":{"attributes":{"title":80,"content":5,"slug":60,"excerpt":40,"meta":{"*":1},"taxonomy":{"category":50,"post_tag":50}},"rules":[],"options":[]},"post.page":{"attributes":{"title":80,"content":5,"slug":60,"meta":{"*":1}},"rules":[],"options":[]},"post.tribe_events":{"attributes":{"title":80,"content":5,"slug":60,"excerpt":40,"comments":1,"meta":{"*":1}},"rules":[],"options":[]}}}}'
18 changes: 9 additions & 9 deletions scripts/wp-install-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# existing website in production
#
# PARAMETERS:
# -n treat this installation as multi site
# (network)
# -l this is a multilingual setup
#===========================================

Expand All @@ -23,14 +21,16 @@ INSTALL_ACTIVATE="--activate"
NETWORK=
MULTILANG=

# detect if it's a multisite installation
if wp site list; then
NETWORK=1
ACTIVATE_NETWORK="--network"
INSTALL_ACTIVATE="--activate-network"
echo "WP multisite detected."
fi

while getopts "nl" opt; do
case $opt in
n)
NETWORK=1
ACTIVATE_NETWORK="--network"
INSTALL_ACTIVATE="--activate-network"
echo "WP multi site support enabled."
;;
case $opt in
l)
MULTILANG=1
echo "Multi language support enabled."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,17 @@
"the_content",
"excerpt",
"discussion",
"comments",
"slug",
"author",
"format",
"page_attributes",
"featured_image",
"categories",
"tags",
"send-trackbacks"
"comments",
"slug",
"author",
"format",
"page_attributes",
"featured_image",
"categories",
"tags",
"send-trackbacks"
],
"active": 1,
"description": "",
"modified": 1543421501
"active": true,
"description": "",
"modified": 1604686054
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"key": "group_5fa587aac61ec",
"title": "(Category) Author",
"fields": [
{
"key": "field_5fa587ab352a8",
"label": "Show author",
"name": "has_author",
"type": "true_false",
"instructions": "Show the author for all posts of this category?",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "",
"default_value": 0,
"ui": 1,
"ui_on_text": "",
"ui_off_text": ""
}
],
"location": [
[
{
"param": "taxonomy",
"operator": "==",
"value": "category"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": true,
"description": "",
"modified": 1604683888
}
Loading

0 comments on commit 0a26609

Please sign in to comment.