Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test For Wordpress Network #2468

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export PROJECT_PATH=$(realpath .)
export TERMINUS_SITE="terminus-test-site"
export TERMINUS_SITE_WP="terminus-test-site-wordpress"
export TERMINUS_SITE_WP="terminus-test-wp-site"
export TERMINUS_SITE_WP_NETWORK="terminus-test-site-wp-network"
export TERMINUS_ENV="dev"
export TERMINUS_ORG="Agency"
export TERMINUS_ORG="agency-org"
export TERMINUS_USER="[email protected]"
## To Autoload your token from your local machine, change the TERMINUS_TOKEN to the following command:
## export TERMINUS_TOKEN=$(cat $HOME/.terminus/cache/tokens/[email protected] | jq -r .token)
Expand Down
61 changes: 61 additions & 0 deletions scripts/make-wordpress-multisite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

set -e

TERMINUS_SITE_WP_NETWORK_UPSTREAM="word_press_multisite"
TERMINUS_SITE_WP_NETWORK_TITLE="TERMINUS-TEST-SITE"
TERMINUS_SITE_WP_NETWORK_ADMIN_USER="admin"
TERMINUS_SITE_WP_NETWORK_ADMIN_EMAIL="[email protected]"
LOCAL_CLONED_DIRECTORY="${HOME}/pantheon-local-copies/${TERMINUS_SITE_WP_NETWORK}"

if test -z "${TERMINUS_SITE_WP_NETWORK}"
then
echo "Please set the following environment variables:"
echo "TERMINUS_SITE_WP_NETWORK"
echo "TERMINUS_SITE_WP_NETWORK_LABEL"
echo "TERMINUS_ORG"
exit 1
fi

if terminus site:info ${TERMINUS_SITE_WP_NETWORK} --format=json | jq -r .id
then
echo "${TERMINUS_SITE_WP_NETWORK} exists... skipping creation..."
else
echo "${TERMINUS_SITE_WP_NETWORK} doesn't exist... creating..."
terminus site:create \
"${TERMINUS_SITE_WP_NETWORK}" \
"${TERMINUS_SITE_WP_NETWORK}" \
"${TERMINUS_SITE_WP_NETWORK_UPSTREAM}" \
--org="${TERMINUS_ORG}"
fi

if [ ! -d "${LOCAL_CLONED_DIRECTORY}" ]
then
echo "Cloning ${TERMINUS_SITE_WP_NETWORK}"
terminus local:clone \
"${TERMINUS_SITE_WP_NETWORK}"
fi

terminus wp ${TERMINUS_SITE_WP_NETWORK}.dev -- core install \
--title="${TERMINUS_SITE_WP_NETWORK_TITLE}" \
--admin_user="${TERMINUS_SITE_WP_NETWORK_ADMIN_USER}" \
--admin_email="${TERMINUS_SITE_WP_NETWORK_ADMIN_EMAIL}"

terminus wp ${TERMINUS_SITE_WP_NETWORK}.dev -- core multisite-install \
--title="${TERMINUS_SITE_WP_NETWORK_TITLE}" \
--admin_user="${TERMINUS_SITE_WP_NETWORK_ADMIN_USER}" \
--admin_email="${TERMINUS_SITE_WP_NETWORK_ADMIN_EMAIL}"

terminus wp ${TERMINUS_SITE_WP_NETWORK}.dev -- plugin install \
pantheon-advanced-page-cache \
--activate

terminus env:commit \
"${TERMINUS_SITE_WP_NETWORK}.dev" \
--message="Initial commit"

terminus connection:set \
"${TERMINUS_SITE_WP_NETWORK}.dev" \
git

cd "${LOCAL_CLONED_DIRECTORY}" && git pull
54 changes: 40 additions & 14 deletions src/Commands/Env/CloneContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@

/**
* Class CloneContentCommand
*
* @package Pantheon\Terminus\Commands\Env
*/
class CloneContentCommand extends TerminusCommand implements SiteAwareInterface
{

stovak marked this conversation as resolved.
Show resolved Hide resolved
use SiteAwareTrait;
use WorkflowProcessingTrait;

/**
* @var Environment
*/
private $source_env;

/**
* @var Environment
*/
Expand All @@ -43,9 +46,11 @@ class CloneContentCommand extends TerminusCommand implements SiteAwareInterface
*
* @command env:clone-content
*
* @param string $site_env Origin site & environment in the format `site-name.env`
* @param string $site_env Origin site & environment in the format
* `site-name.env`
* @param string $target_env Target environment
* @param array $options
*
* @option bool $cc Whether or not to clear caches
* @option bool $db-only Only clone database
* @option bool $files-only Only clone files
Expand All @@ -55,12 +60,21 @@ class CloneContentCommand extends TerminusCommand implements SiteAwareInterface
*
* @throws \Pantheon\Terminus\Exceptions\TerminusException
*
* @usage <site>.<env> <target_env> Clones database and files from <site>'s <env> environment to <target_env> environment.
* @usage <site>.<env> <target_env> --cc Clones from <site>'s <env> environment to <target_env> environment and clears the cache.
* @usage <site>.<env> <target_env> --db-only Clones only the database from <site>'s <env> environment to <target_env> environment.
* @usage <site>.<env> <target_env> --files-only Clones only files from <site>'s <env> environment to <target_env> environment.
* @usage <site>.<env> <target_env> --updatedb Clones from <site>'s <env> environment to <target_env> environment and updates the Drupal database (if applicable).
* @usage <site>.<env> <target_env> --from-url=www.example.com --to-url=mulitidevenv.example.com (WordPress only) Clones from <site>'s <env> environment to <target_env> environment and replaces www.example.com with mulitidevenv.example.com in the database.
* @usage <site>.<env> <target_env> Clones database and files from <site>'s
* <env> environment to <target_env> environment.
* @usage <site>.<env> <target_env> --cc Clones from <site>'s <env>
* environment to <target_env> environment and clears the cache.
* @usage <site>.<env> <target_env> --db-only Clones only the database from
* <site>'s <env> environment to <target_env> environment.
* @usage <site>.<env> <target_env> --files-only Clones only files from
* <site>'s <env> environment to <target_env> environment.
* @usage <site>.<env> <target_env> --updatedb Clones from <site>'s <env>
* environment to <target_env> environment and updates the Drupal
* database (if applicable).
* @usage <site>.<env> <target_env> --from-url=www.example.com
* --to-url=mulitidevenv.example.com (WordPress only) Clones from
* <site>'s <env> environment to <target_env> environment and replaces
* www.example.com with mulitidevenv.example.com in the database.
*/
public function cloneContent(
$site_env,
Expand All @@ -75,7 +89,9 @@ public function cloneContent(
]
) {
if (!empty($options['db-only']) && !empty($options['files-only'])) {
throw new TerminusException('You cannot specify both --db-only and --files-only');
throw new TerminusException(
'You cannot specify both --db-only and --files-only'
);
}

$this->requireSiteIsNotFrozen($site_env);
Expand All @@ -84,7 +100,9 @@ public function cloneContent(
$this->target_env = $site->getEnvironments()->get($target_env);

if ($this->source_env->id === $target_env) {
$this->log()->notice('The clone has been skipped because the source and target environments are the same.');
$this->log()->notice(
'The clone has been skipped because the source and target environments are the same.'
);
return;
}

Expand Down Expand Up @@ -113,20 +131,25 @@ public function cloneContent(
// environment.
if ($site->getFramework()->isWordpressFramework()) {
$options['search-replace'] = [
'from_url' => $options['from-url'] ?? $this->source_env->domain(),
'to_url' => $options['to-url'] ?? $this->target_env->domain(),
'from_url' => $options['from-url'] ?? $this->source_env->domain(
),
'to_url' => $options['to-url'] ?? $this->target_env->domain(
),
];
}
$this->cloneDatabase($options);
}
}

/**
* Checks to see whether the indicated environment is initialized and stops the process if it isn't
* Checks to see whether the indicated environment is initialized and stops
* the process if it isn't
*
* @param Environment $env
* @param string $direction "into" or "from" are recommended.
* @throws TerminusException Thrown if the passed-in environment is not initialized
*
* @throws TerminusException Thrown if the passed-in environment is not
* initialized
*/
private function checkForInitialization(Environment $env, $direction = '')
{
Expand Down Expand Up @@ -175,7 +198,10 @@ private function emitNotice($element)
{
$this->log()->notice(
"Cloning {$element} from {source} environment to {target} environment",
['source' => $this->source_env->getName(), 'target' => $this->target_env->getName(),]
[
'source' => $this->source_env->getName(),
'target' => $this->target_env->getName(),
]
);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ class Site extends TerminusModel implements
*/
public $tags;

/**
* @var string
*/
public $framework;

/**
* Add a payment method to the given site
*
Expand Down
Loading