wordmove 1.3.0.pre2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/README.mdown +5 -0
- data/Rakefile +2 -4
- data/assets/images/wordmove.png +0 -0
- data/bin/console +10 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/setup +7 -0
- data/exe/wordmove +6 -0
- data/lib/wordmove.rb +25 -0
- data/lib/wordmove/assets/dump.php.erb +202 -165
- data/lib/wordmove/assets/import.php.erb +1179 -1080
- data/lib/wordmove/cli.rb +18 -18
- data/lib/wordmove/deployer/base.rb +30 -32
- data/lib/wordmove/deployer/ftp.rb +3 -7
- data/lib/wordmove/deployer/ssh.rb +3 -5
- data/lib/wordmove/exceptions.rb +6 -0
- data/lib/wordmove/generators/movefile.rb +0 -3
- data/lib/wordmove/generators/movefile_adapter.rb +3 -4
- data/lib/wordmove/logger.rb +0 -5
- data/lib/wordmove/version.rb +1 -1
- data/wordmove.gemspec +34 -38
- metadata +91 -75
- data/bin/wordmove +0 -6
- data/lib/wordmove/core_ext.rb +0 -11
- data/spec/deployer/base_spec.rb +0 -85
- data/spec/features/movefile_spec.rb +0 -59
- data/spec/fixtures/Movefile +0 -23
- data/spec/fixtures/wp-config.php +0 -90
- data/spec/spec_helper.rb +0 -22
- data/spec/sql_adapter_spec.rb +0 -163
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef259f42e99168010fa346b266b25ae9e116f633
|
4
|
+
data.tar.gz: 11fe30b4ff34778cb26a26d74c23e04da4a9e3bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37f218ec6741be9fb5fe47737f7b740b011ce709b5d40047e43986944219161443ddcc67c6534f38ab20c1be83f35ad6d7368fb658ea5711247996022b72436b
|
7
|
+
data.tar.gz: 6e685dad79f7679c1d7b926e698c85dc8cf70c1d267065ff5f8fa96d58daf8cb252e9f5ff65b071bdc9b6623353939868dda3d8ca1ba8d66c7dceb0f6a233926
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/README.mdown
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Wordmove
|
2
2
|
|
3
|
+
![logo](https://raw.githubusercontent.com/welaika/wordmove/master/assets/images/wordmove.png)
|
4
|
+
|
3
5
|
Wordmove is a nice little gem that lets you automatically mirror local Wordpress
|
4
6
|
installations and DB data back and forth from your local development machine to
|
5
7
|
the remote staging server. SSH and FTP connections are both supported.
|
@@ -148,6 +150,9 @@ too much about security though: the script is deleted just after the usage,
|
|
148
150
|
and can only be executed by `wordmove`, as each time it requires a pre-shared
|
149
151
|
one-time-password to be run.
|
150
152
|
|
153
|
+
## Need more tools?
|
154
|
+
Visit [Wordpress Tools](http://wptools.it).
|
155
|
+
|
151
156
|
## Credits
|
152
157
|
|
153
158
|
* The dump script is the [`MYSQL-dump` PHP package](https://github.com/dg/MySQL-dump) by David Grudl;
|
data/Rakefile
CHANGED
Binary file
|
data/bin/console
ADDED
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/bin/setup
ADDED
data/exe/wordmove
ADDED
data/lib/wordmove.rb
CHANGED
@@ -1,4 +1,29 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/group'
|
3
|
+
require 'colorize'
|
4
|
+
require 'logger'
|
5
|
+
require 'yaml'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'erb'
|
8
|
+
require 'open-uri'
|
9
|
+
require 'active_support'
|
10
|
+
require 'active_support/core_ext'
|
11
|
+
|
12
|
+
require 'photocopier'
|
13
|
+
|
14
|
+
require 'wordmove/exceptions'
|
15
|
+
require 'wordmove/cli'
|
16
|
+
require 'wordmove/logger'
|
17
|
+
require 'wordmove/sql_adapter'
|
1
18
|
require "wordmove/version"
|
19
|
+
require 'wordmove/wordpress_directory'
|
20
|
+
|
21
|
+
require 'wordmove/generators/movefile_adapter'
|
22
|
+
require 'wordmove/generators/movefile'
|
23
|
+
|
24
|
+
require 'wordmove/deployer/base'
|
25
|
+
require 'wordmove/deployer/ftp'
|
26
|
+
require 'wordmove/deployer/ssh'
|
2
27
|
|
3
28
|
module Wordmove
|
4
29
|
end
|
@@ -1,186 +1,223 @@
|
|
1
1
|
<?php
|
2
2
|
|
3
|
+
$shared_key = '<%= password %>';
|
4
|
+
if ($_GET['shared_key'] != $shared_key) {
|
5
|
+
die();
|
6
|
+
}
|
7
|
+
|
3
8
|
/**
|
4
9
|
* MySQL database dump.
|
5
10
|
*
|
6
|
-
* @author David Grudl
|
11
|
+
* @author David Grudl (http://davidgrudl.com)
|
7
12
|
* @copyright Copyright (c) 2008 David Grudl
|
8
13
|
* @license New BSD License
|
9
|
-
* @
|
10
|
-
* @version 0.9
|
14
|
+
* @version 1.0
|
11
15
|
*/
|
12
|
-
|
13
16
|
class MySQLDump
|
14
17
|
{
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
}
|
18
|
+
const MAX_SQL_SIZE = 1e6;
|
19
|
+
|
20
|
+
const NONE = 0;
|
21
|
+
const DROP = 1;
|
22
|
+
const CREATE = 2;
|
23
|
+
const DATA = 4;
|
24
|
+
const TRIGGERS = 8;
|
25
|
+
const ALL = 15; // DROP | CREATE | DATA | TRIGGERS
|
26
|
+
|
27
|
+
/** @var array */
|
28
|
+
public $tables = array(
|
29
|
+
'*' => self::ALL,
|
30
|
+
);
|
31
|
+
|
32
|
+
/** @var mysqli */
|
33
|
+
private $connection;
|
34
|
+
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Connects to database.
|
38
|
+
* @param mysqli connection
|
39
|
+
*/
|
40
|
+
public function __construct(mysqli $connection, $charset = 'utf8'
|
41
|
+
{
|
42
|
+
$this->connection = $connection;
|
43
|
+
|
44
|
+
if ($connection->connect_errno) {
|
45
|
+
throw new Exception($connection->connect_error);
|
46
|
+
|
47
|
+
} elseif (!$connection->set_charset($charset)) { // was added in MySQL 5.0.7 and PHP 5.0.5, fixed in PHP 5.1.5)
|
48
|
+
throw new Exception($connection->error);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Saves dump to the file.
|
55
|
+
* @param string filename
|
56
|
+
* @return void
|
57
|
+
*/
|
58
|
+
public function save($file)
|
59
|
+
{
|
60
|
+
$handle = strcasecmp(substr($file, -3), '.gz') ? fopen($file, 'wb') : gzopen($file, 'wb');
|
61
|
+
if (!$handle) {
|
62
|
+
throw new Exception("ERROR: Cannot write file '$file'.");
|
63
|
+
}
|
64
|
+
$this->write($handle);
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Writes dump to logical file.
|
70
|
+
* @param resource
|
71
|
+
* @return void
|
72
|
+
*/
|
73
|
+
public function write($handle = NULL)
|
74
|
+
{
|
75
|
+
if ($handle === NULL) {
|
76
|
+
$handle = fopen('php://output', 'wb');
|
77
|
+
} elseif (!is_resource($handle) || get_resource_type($handle) !== 'stream') {
|
78
|
+
throw new Exception('Argument must be stream resource.');
|
79
|
+
}
|
80
|
+
|
81
|
+
$tables = array();
|
82
|
+
|
83
|
+
$res = $this->connection->query('SHOW TABLES');
|
84
|
+
while ($row = $res->fetch_row()) {
|
85
|
+
$tables[] = $row[0];
|
86
|
+
}
|
87
|
+
$res->close();
|
88
|
+
|
89
|
+
$this->connection->query('LOCK TABLES `' . implode('` READ, `', $tables) . '` READ');
|
90
|
+
|
91
|
+
$db = $this->connection->query('SELECT DATABASE()')->fetch_row();
|
92
|
+
fwrite($handle, "-- Created at " . date('j.n.Y G:i') . " using David Grudl MySQL Dump Utility\n"
|
93
|
+
. (isset($_SERVER['HTTP_HOST']) ? "-- Host: $_SERVER[HTTP_HOST]\n" : '')
|
94
|
+
. "-- MySQL Server: " . $this->connection->server_info . "\n"
|
95
|
+
. "-- Database: " . $db[0] . "\n"
|
96
|
+
. "\n"
|
97
|
+
. "SET NAMES utf8;\n"
|
98
|
+
. "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\n"
|
99
|
+
. "SET FOREIGN_KEY_CHECKS=0;\n"
|
100
|
+
);
|
101
|
+
|
102
|
+
foreach ($tables as $table) {
|
103
|
+
$this->dumpTable($handle, $table);
|
104
|
+
}
|
105
|
+
|
106
|
+
fwrite($handle, "-- THE END\n");
|
107
|
+
|
108
|
+
$this->connection->query('UNLOCK TABLES');
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Dumps table to logical file.
|
114
|
+
* @param resource
|
115
|
+
* @return void
|
116
|
+
*/
|
117
|
+
public function dumpTable($handle, $table)
|
118
|
+
{
|
119
|
+
$delTable = $this->delimite($table);
|
120
|
+
$res = $this->connection->query("SHOW CREATE TABLE $delTable");
|
121
|
+
$row = $res->fetch_assoc();
|
122
|
+
$res->close();
|
123
|
+
|
124
|
+
fwrite($handle, "-- --------------------------------------------------------\n\n");
|
125
|
+
|
126
|
+
$mode = isset($this->tables[$table]) ? $this->tables[$table] : $this->tables['*'];
|
127
|
+
$view = isset($row['Create View']);
|
128
|
+
|
129
|
+
if ($mode & self::DROP) {
|
130
|
+
fwrite($handle, 'DROP ' . ($view ? 'VIEW' : 'TABLE') . " IF EXISTS $delTable;\n\n");
|
131
|
+
}
|
132
|
+
|
133
|
+
if ($mode & self::CREATE) {
|
134
|
+
fwrite($handle, $row[$view ? 'Create View' : 'Create Table'] . ";\n\n");
|
135
|
+
}
|
136
|
+
|
137
|
+
if (!$view && ($mode & self::DATA)) {
|
138
|
+
$numeric = array();
|
139
|
+
$res = $this->connection->query("SHOW COLUMNS FROM $delTable");
|
140
|
+
$cols = array();
|
141
|
+
while ($row = $res->fetch_assoc()) {
|
142
|
+
$col = $row['Field'];
|
143
|
+
$cols[] = $this->delimite($col);
|
144
|
+
$numeric[$col] = (bool) preg_match('#^[^(]*(BYTE|COUNTER|SERIAL|INT|LONG$|CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER)#i', $row['Type']);
|
145
|
+
}
|
146
|
+
$cols = '(' . implode(', ', $cols) . ')';
|
147
|
+
$res->close();
|
148
|
+
|
149
|
+
|
150
|
+
$size = 0;
|
151
|
+
$res = $this->connection->query("SELECT * FROM $delTable", MYSQLI_USE_RESULT);
|
152
|
+
while ($row = $res->fetch_assoc()) {
|
153
|
+
$s = '(';
|
154
|
+
foreach ($row as $key => $value) {
|
155
|
+
if ($value === NULL) {
|
156
|
+
$s .= "NULL,\t";
|
157
|
+
} elseif ($numeric[$key]) {
|
158
|
+
$s .= $value . ",\t";
|
159
|
+
} else {
|
160
|
+
$s .= "'" . $this->connection->real_escape_string($value) . "',\t";
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
if ($size == 0) {
|
165
|
+
$s = "INSERT INTO $delTable $cols VALUES\n$s";
|
166
|
+
} else {
|
167
|
+
$s = ",\n$s";
|
168
|
+
}
|
169
|
+
|
170
|
+
$len = strlen($s) - 1;
|
171
|
+
$s[$len - 1] = ')';
|
172
|
+
fwrite($handle, $s, $len);
|
173
|
+
|
174
|
+
$size += $len;
|
175
|
+
if ($size > self::MAX_SQL_SIZE) {
|
176
|
+
fwrite($handle, ";\n");
|
177
|
+
$size = 0;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
$res->close();
|
182
|
+
if ($size) {
|
183
|
+
fwrite($handle, ";\n");
|
184
|
+
}
|
185
|
+
fwrite($handle, "\n");
|
186
|
+
}
|
187
|
+
|
188
|
+
if ($mode & self::TRIGGERS) {
|
189
|
+
$res = $this->connection->query("SHOW TRIGGERS LIKE '" . $this->connection->real_escape_string($table) . "'");
|
190
|
+
if ($res->num_rows) {
|
191
|
+
fwrite($handle, "DELIMITER ;;\n\n");
|
192
|
+
while ($row = $res->fetch_assoc()) {
|
193
|
+
fwrite($handle, "CREATE TRIGGER {$this->delimite($row['Trigger'])} $row[Timing] $row[Event] ON $delTable FOR EACH ROW\n$row[Statement];;\n\n");
|
194
|
+
}
|
195
|
+
fwrite($handle, "DELIMITER ;\n\n");
|
196
|
+
}
|
197
|
+
$res->close();
|
198
|
+
}
|
199
|
+
|
200
|
+
fwrite($handle, "\n");
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
private function delimite($s)
|
205
|
+
{
|
206
|
+
return '`' . str_replace('`', '``', $s) . '`';
|
207
|
+
}
|
155
208
|
|
156
|
-
function get_connection($db_host, $db_user, $db_password, $db_name, $db_port, &$error = NULL) {
|
157
|
-
$db_connection = new mysqli($db_host, $db_user, $db_password, $db_name, $db_port);
|
158
|
-
if (!$db_connection || !$db_connection->select_db($db_name)) {
|
159
|
-
if ($db_connection) {
|
160
|
-
$error = mysqli_connect_error();
|
161
|
-
} else {
|
162
|
-
$error = "Unable to connect to mysql database";
|
163
|
-
}
|
164
|
-
return NULL;
|
165
|
-
}
|
166
|
-
return $db_connection;
|
167
209
|
}
|
168
210
|
|
169
211
|
$db_host = '<%= escape_php db[:host] %>';
|
170
|
-
$db_port = '<%=
|
212
|
+
$db_port = '<%= db[:port] %>';
|
171
213
|
if (!$db_port) {
|
172
214
|
$db_port = ini_get("mysqli.default_port");
|
173
215
|
}
|
174
216
|
$db_user = '<%= escape_php db[:user] %>';
|
175
217
|
$db_password = '<%= escape_php db[:password] %>';
|
176
218
|
$db_name = '<%= escape_php db[:name] %>';
|
177
|
-
$
|
178
|
-
|
179
|
-
$mysql_error = '';
|
180
|
-
|
181
|
-
if ($_GET['shared_key'] == $shared_key) {
|
182
|
-
$connection = get_connection($db_host, $db_user, $db_password, $db_name, $db_port, $mysql_error);
|
183
|
-
$dump = new MySQLDump($connection);
|
184
|
-
$dump->send('dump.mysql');
|
185
|
-
}
|
219
|
+
$db_charset = '<%= escape_php db[:charset] %>';
|
186
220
|
|
221
|
+
$connection = new mysqli($db_host, $db_user, $db_password, $db_name, $db_port);
|
222
|
+
$dump = new MySQLDump($connection, $db_charset);
|
223
|
+
$dump->save('dump.mysql');
|