Skip to content

Commit bc9db03

Browse files
authored
Replace drush_escapeshellarg() uses in Sqlbase (#3819)
1 parent eed106a commit bc9db03

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

includes/environment.inc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ function _drush_convert_path($path) {
3131
/**
3232
* Build a drush command suitable for use for Drush to call itself.
3333
* Used in backend_invoke.
34+
*
35+
* @deprecated.
3436
*/
3537
function drush_build_drush_command($drush_path = NULL, $php = NULL, $os = NULL, $remote_command = FALSE, $environment_variables = []) {
3638
$os = _drush_get_os($os);
@@ -136,6 +138,8 @@ function drush_bit_bucket() {
136138
* WIN* (e.g. WINNT)
137139
* CYGWIN
138140
* MINGW* (e.g. MINGW32)
141+
*
142+
* @deprecated. Use \Consolidation\SiteProcess\Util\Escape.
139143
*/
140144
function _drush_get_os($os = NULL) {
141145
// In most cases, $os will be NULL and PHP_OS will be returned. However, if an
@@ -170,11 +174,16 @@ function drush_is_local_host($host) {
170174

171175
/**
172176
* Determine whether current OS is a Windows variant.
177+
*
178+
* @deprecated. Use \Consolidation\SiteProcess\Util\Escape.
173179
*/
174180
function drush_is_windows($os = NULL) {
175181
return strtoupper(substr(_drush_get_os($os), 0, 3)) === 'WIN';
176182
}
177183

184+
/**
185+
* @deprecated. Use \Consolidation\SiteProcess\Util\Escape.
186+
*/
178187
function drush_escapeshellarg($arg, $os = NULL, $raw = FALSE) {
179188
// Short-circuit escaping for simple params (keep stuff readable)
180189
if (preg_match('|^[a-zA-Z0-9.:/_-]*$|', $arg)) {
@@ -194,7 +203,9 @@ function drush_escapeshellarg($arg, $os = NULL, $raw = FALSE) {
194203
* This is intended to work the same way that escapeshellarg() does on
195204
* Linux. If we need to escape a string that will be used remotely on
196205
* a Linux system, then we need our own implementation of escapeshellarg,
197-
* because the Windows version behaves differently.
206+
* because the Windows version behaves differently
207+
*
208+
* @deprecated. Use \Consolidation\SiteProcess\Util\Escape.
198209
*/
199210
function _drush_escapeshellarg_linux($arg, $raw = FALSE) {
200211
// For single quotes existing in the string, we will "exit"
@@ -222,6 +233,8 @@ function _drush_escapeshellarg_linux($arg, $raw = FALSE) {
222233

223234
/**
224235
* Windows version of escapeshellarg().
236+
*
237+
* @deprecated. Use \Consolidation\SiteProcess\Util\Escape.
225238
*/
226239
function _drush_escapeshellarg_windows($arg, $raw = FALSE) {
227240
// Double up existing backslashes

src/Sql/SqlBase.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Drush\Sql;
44

5+
use Consolidation\SiteProcess\Util\Escape;
6+
use Consolidation\SiteProcess\Util\Shell;
57
use Drupal\Core\Database\Database;
68
use Drush\Drush;
7-
use Drush\Log\LogLevel;
89
use Drush\Utils\FsUtils;
910
use Robo\Common\ConfigAwareTrait;
1011
use Robo\Contract\ConfigAwareInterface;
12+
use Symfony\Component\Filesystem\Filesystem;
1113
use Symfony\Component\Process\Process;
1214
use Webmozart\PathUtil\Path;
1315

@@ -29,7 +31,10 @@ class SqlBase implements ConfigAwareInterface
2931
// An options array.
3032
public $options;
3133

32-
public $process;
34+
/**
35+
* @var Process
36+
*/
37+
protected $process;
3338

3439
/**
3540
* Typically, SqlBase instances are constructed via SqlBase::create($options).
@@ -169,7 +174,7 @@ public function dump()
169174
}
170175
if ($file) {
171176
$file .= $file_suffix;
172-
$cmd .= ' > ' . drush_escapeshellarg($file);
177+
$cmd .= ' > ' . Escape::shellArg($file);
173178
}
174179

175180
$process = Drush::process($cmd);
@@ -247,7 +252,7 @@ public function query($query, $input_file = null, $result_file = '')
247252
/**
248253
* Execute a SQL query. Always execute regardless of simulate mode.
249254
*
250-
* If you don't want query results to print during --debug then
255+
* If you don't want query to print during --debug then
251256
* provide a $result_file whose value can be drush_bit_bucket().
252257
*
253258
* @param string $query
@@ -276,7 +281,7 @@ public function alwaysQuery($query, $input_file = null, $result_file = '')
276281
}
277282
}
278283

279-
// Save $query to a tmp file if needed. We will redirect it in.
284+
// Save $query to a tmp file if needed. We redirect it in.
280285
if (!$input_file) {
281286
$query = $this->queryPrefix($query);
282287
$query = $this->queryFormat($query);
@@ -289,12 +294,12 @@ public function alwaysQuery($query, $input_file = null, $result_file = '')
289294
$this->silent(), // This removes column header and various helpful things in mysql.
290295
$this->getOption('extra', $this->queryExtra),
291296
$this->queryFile,
292-
drush_escapeshellarg($input_file),
297+
Escape::shellArg($input_file),
293298
];
294299
$exec = implode(' ', $parts);
295300

296301
if ($result_file) {
297-
$exec .= ' > '. drush_escapeshellarg($result_file);
302+
$exec .= ' > '. Escape::shellArg($result_file);
298303
}
299304

300305
// In --verbose mode, drush_shell_exec() will show the call to mysql/psql/sqlite,
@@ -309,7 +314,8 @@ public function alwaysQuery($query, $input_file = null, $result_file = '')
309314
$this->setProcess($process);
310315

311316
if ($success && $this->getOption('file-delete')) {
312-
drush_delete_dir($input_file);
317+
$fs = new Filesystem();
318+
$fs->remove($input_file);
313319
}
314320

315321
return $success;

0 commit comments

Comments
 (0)