Skip to content

Commit 24eec3e

Browse files
committed
working on #4, clean up, reverted to using shell for WP_COMMANDS
1 parent d2f1d1e commit 24eec3e

4 files changed

Lines changed: 36 additions & 70 deletions

File tree

php/Bitbucket_Command.php

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
class Bitbucket_Command extends SCM_Command {
66

77
static protected function tgz($args, $assoc_args) {
8-
list( $repo, $tag ) = $args;
8+
@list( $repo, $tag ) = $args;
99
$url = sprintf("https://bitbucket.org/%s/get/%s.tar.gz", $repo, $tag ?: 'master');
1010
if (array_intersect_key($assoc_args, array('key' => TRUE, 'secret' => TRUE))) {
11-
WP_CLI::log("Fetching $url via OAuth");
11+
WP_CLI::debug("Fetching $url via OAuth");
1212
$tgz = self::fetch_tarball_via_oauth($assoc_args['key'], $assoc_args['secret'], $url);
1313
} else {
14-
WP_CLI::log("Fetching $url via cURL");
14+
WP_CLI::debug("Fetching $url via cURL");
1515
$tgz = self::fetch_tarball($url);
1616
}
17-
WP_CLI::log("Fetched $tgz");
18-
WP_CLI::log("Converting $tgz to zip");
17+
WP_CLI::debug("Fetched $tgz");
18+
WP_CLI::debug("Converting $tgz to zip");
1919
$zip = self::tgz_to_zip($repo, $tgz);
20-
WP_CLI::log("Converted $tgz to $zip");
20+
WP_CLI::debug("Converted $tgz to $zip");
2121
return array($url, $tgz, $zip);
2222
}
2323

@@ -86,27 +86,3 @@ function theme( $args, $assoc_args ) {
8686
}
8787

8888
WP_CLI::add_command( 'bitbucket', 'Bitbucket_Command' );
89-
90-
if (!function_exists('http_parse_headers')) {
91-
function http_parse_headers($header) {
92-
$retVal = array();
93-
$fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header));
94-
foreach( $fields as $field ) {
95-
if( preg_match('/([^:]+): (.+)/m', $field, $match) ) {
96-
$match[1] = preg_replace_callback('/(?<=^|[\x09\x20\x2D])./', function ($x) { return strtoupper($x[0]); }, strtolower(trim($match[1])));
97-
if( isset($retVal[$match[1]]) ) {
98-
if ( is_array( $retVal[$match[1]] ) ) {
99-
$i = count($retVal[$match[1]]);
100-
$retVal[$match[1]][$i] = $match[2];
101-
}
102-
else {
103-
$retVal[$match[1]] = array($retVal[$match[1]], $match[2]);
104-
}
105-
} else {
106-
$retVal[$match[1]] = trim($match[2]);
107-
}
108-
}
109-
}
110-
return $retVal;
111-
}
112-
}

php/GitHub_Command.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
class GitHub_Command extends SCM_Command {
66

77
static protected function tgz($args, $assoc_args) {
8-
list( $repo, $tag ) = $args;
8+
@list( $repo, $tag ) = $args;
99
// Get the tarball URL for the latest (or specified release)
1010
$url = sprintf("https://api.github.com/repos/%s/releases/%s", $repo, $tag ? "tags/${tag}" : 'latest');
11-
WP_CLI::log("Querying for releases: $url");
11+
WP_CLI::debug("Querying for releases: $url");
1212
$url = self::tarball_url($url, @$assoc_args['token']);
1313

1414
// If no releases are available fail-back to a commitish
@@ -17,13 +17,13 @@ static protected function tgz($args, $assoc_args) {
1717
else
1818
$url = sprintf("https://api.github.com/repos/%s/tarball/%s", $repo, $tag ?: 'master');
1919

20-
WP_CLI::log("Fetching $url");
20+
WP_CLI::debug("Fetching $url");
2121
$tgz = self::fetch_tarball($url, @$assoc_args['token']);
22-
WP_CLI::log("Fetched $tgz");
22+
WP_CLI::debug("Fetched $tgz");
2323

24-
WP_CLI::log("Converting $tgz to zip");
24+
WP_CLI::debug("Converting $tgz to zip");
2525
$zip = self::tgz_to_zip($repo, $tgz);
26-
WP_CLI::log("Converted $tgz to $zip");
26+
WP_CLI::debug("Converted $tgz to $zip");
2727

2828
return array($url, $tgz, $zip);
2929
}

php/SCM_Command.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ static protected function tarball_url($url, $auth = NULL) {
7373
if ($auth)
7474
$auth = "-u ${auth}";
7575
// TODO pure PHP
76-
return trim(shell_exec("curl -sSfL ${auth} ${url} | jq -r '.tarball_url'"));
76+
return trim(shell_exec("curl -sfL ${auth} ${url} | jq -r '.tarball_url'"));
7777
}
7878

7979
static protected function fetch_tarball($url, $auth = NULL) {
8080
if ($auth)
8181
$auth = "-u ${auth}";
8282
// TODO pure PHP
83-
return shell_exec("echo -n $(readlink -n -f .)/; curl -sSfLJO -w '%{filename_effective}' ${auth} ${url}");
83+
return shell_exec("echo -n $(readlink -n -f .)/; curl -sfLJO -w '%{filename_effective}' ${auth} ${url}");
8484
}
8585

8686
static protected function fetch_tarball_via_oauth($key, $secret, $uri) {
@@ -134,34 +134,34 @@ static protected abstract function tgz($args, $assoc_args);
134134
static protected function apply($cmd, $args, $assoc_args) {
135135
$op = array_shift($args);
136136
list($url, $tgz, $zip) = static::tgz($args, $assoc_args);
137-
WP_CLI::log("Installing from $zip");
137+
WP_CLI::debug("Installing from $zip");
138138
WP_CLI::run_command(array($cmd, $op, $zip), array('force' => 1));
139-
WP_CLI::log("Removing $tgz, $zip");
139+
WP_CLI::debug("Removing $tgz, $zip");
140140
unlink($tgz);
141141
unlink($zip);
142142
}
143143
}
144144

145145
if (!function_exists('http_parse_headers')) {
146-
function http_parse_headers($header) {
147-
$retVal = array();
148-
$fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header));
146+
function http_parse_headers($headers_raw) {
147+
$headers = array();
148+
$fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $headers_raw));
149149
foreach( $fields as $field ) {
150150
if( preg_match('/([^:]+): (.+)/m', $field, $match) ) {
151151
$match[1] = preg_replace_callback('/(?<=^|[\x09\x20\x2D])./', function ($x) { return strtoupper($x[0]); }, strtolower(trim($match[1])));
152-
if( isset($retVal[$match[1]]) ) {
153-
if ( is_array( $retVal[$match[1]] ) ) {
154-
$i = count($retVal[$match[1]]);
155-
$retVal[$match[1]][$i] = $match[2];
152+
if( isset($headers[$match[1]]) ) {
153+
if ( is_array( $headers[$match[1]] ) ) {
154+
$i = count($headers[$match[1]]);
155+
$headers[$match[1]][$i] = $match[2];
156156
}
157157
else {
158-
$retVal[$match[1]] = array($retVal[$match[1]], $match[2]);
158+
$headers[$match[1]] = array($headers[$match[1]], $match[2]);
159159
}
160160
} else {
161-
$retVal[$match[1]] = trim($match[2]);
161+
$headers[$match[1]] = trim($match[2]);
162162
}
163163
}
164164
}
165-
return $retVal;
165+
return $headers;
166166
}
167167
}

setup.sh

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#!/bin/bash
22

3-
X=$(shopt -qo xtrace && echo "-x")
4-
53
# Juggle ENV VARS
6-
echo MYSQL_ROOT_PASSWORD = ${MYSQL_ROOT_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
7-
echo WP_DB_NAME = ${WP_DB_NAME:=$MYSQL_ENV_MYSQL_DATABASE}
8-
echo WP_DB_USER = ${WP_DB_USER:=$MYSQL_ENV_MYSQL_USER}
9-
echo WP_DB_PASSWORD = ${WP_DB_PASSWORD:=$MYSQL_ENV_MYSQL_PASSWORD}
10-
echo WP_DB_HOST = ${WP_DB_HOST:=$MYSQL_PORT_3306_TCP_ADDR}
11-
echo WP_DB_PORT = ${WP_DB_PORT:=${MYSQL_PORT_3306_TCP_PORT:-3306}}
12-
echo WP_NETWORK = ${WP_NETWORK:-no}
13-
echo WP_SUBDOMAINS = ${WP_SUBDOMAINS:-no}
14-
echo WP_URL = ${WP_URL:?WP_URL is required}
4+
: ${MYSQL_ROOT_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
5+
: ${WP_DB_NAME:=$MYSQL_ENV_MYSQL_DATABASE}
6+
: ${WP_DB_USER:=$MYSQL_ENV_MYSQL_USER}
7+
: ${WP_DB_PASSWORD:=$MYSQL_ENV_MYSQL_PASSWORD}
8+
: ${WP_DB_HOST:=$MYSQL_PORT_3306_TCP_ADDR}
9+
: ${WP_DB_PORT:=${MYSQL_PORT_3306_TCP_PORT:-3306}}
10+
: ${WP_NETWORK:-no}
11+
: ${WP_SUBDOMAINS:-no}
12+
: ${WP_URL:?WP_URL is required}
1513

1614
function install_core {
1715
# Download the lastest WP, preferebly with the selected locale, but fall back to the default locale.
@@ -59,18 +57,10 @@ function install_core {
5957
function wp_commands {
6058
for V in ${!WP_COMMANDS*}
6159
do
62-
xargs -r -L 1 wp <<< "${!V}"
60+
sh <<< "${!V}"
6361
done
6462
}
6563

66-
function import {
67-
wp plugin is-installed wordpress-importer || install_a plugin wordpress-importer
68-
# wp option update siteurl "$WP_URL"
69-
# wp option update home "$WP_URL"
70-
echo 'Importing, this may take a *very* long time.'
71-
wp import $WP_IMPORT --authors=create --skip=image_resize --quiet "$@"
72-
}
73-
7464
# All rolled up into one function.
7565
function setup {
7666
install_core

0 commit comments

Comments
 (0)