Skip to content

Commit ffc754f

Browse files
committed
Merge branch '27689_console_commands' of github.com:dennisinteractive/drupal_console_commands into 27689_console_commands
2 parents 29a8fc4 + ec8c157 commit ffc754f

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

src/Command/SiteBaseCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ protected function _validateUrl(InputInterface $input) {
311311

312312
if ($url && filter_var($url, FILTER_VALIDATE_URL) !== FALSE) {
313313
$this->url = $url;
314-
$input->setOption('site-url', $this->url);
315-
316314
};
317315

318316
return $this->url;
@@ -334,7 +332,7 @@ public function settingsPhpDirectory() {
334332
$this->shellPath($webSitesPath)
335333
);
336334

337-
$this->io->comment('Searching for settings.php in the sites folder');
335+
$this->io->writeln('Searching for settings.php in the sites folder');
338336
$shellProcess = $this->getShellProcess();
339337
if ($shellProcess->exec($command, TRUE)) {
340338
if (!empty($shellProcess->getOutput())) {

src/Command/SiteDbImportCommand.php

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SiteDbImportCommand extends SiteBaseCommand {
2929
*
3030
* @var
3131
*/
32-
protected $file = NULL;
32+
protected $filename = NULL;
3333

3434
/**
3535
* The temporary path to this db.
@@ -96,24 +96,24 @@ protected function execute(InputInterface $input, OutputInterface $output) {
9696

9797
// Check if a dump file has been specified.
9898
if ($input->hasOption('file') && !is_null($input->getOption('file'))) {
99-
$this->file = $input->getOption('file');
99+
$this->filename = $input->getOption('file');
100100
}
101101
// Check if a dump file is set in the yaml config
102102
elseif (isset($this->config['db']['dump'])) {
103103
// Use config from sites.yml.
104-
$this->file = $this->config['db']['dump'];
104+
$this->filename = $this->config['db']['dump'];
105105
}
106106
else {
107107
throw new SiteCommandException('Please specify a file to import the dump from');
108108
}
109109

110110
// If we're installing from a dump that's not already in
111111
// our local destination, copy it to our local destination.
112-
if (!empty($this->file)) {
113-
$this->file = $this->copy($this->file);
112+
if (!empty($this->filename)) {
113+
$this->filename = $this->copy($this->filename);
114114

115115
// If the file is gzipped we need to unzip it.
116-
$this->file = $this->unzip($this->file);
116+
$this->filename = $this->unzip($this->filename);
117117
}
118118

119119
$this->destination = $this->settingsPhpDirectory();
@@ -149,7 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
149149
}
150150

151151
// If a dump file wasn't found or not specified, do a fresh site install
152-
if (empty($this->file) || !$this->fileExists($this->file)) {
152+
if (empty($this->filename) || !$this->fileExists($this->filename)) {
153153
//@todo Use drupal site:install instead of Drush.
154154
$command = sprintf(
155155
'cd %s && ' .
@@ -173,7 +173,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
173173
'drush sql-cli < %s; ',
174174
$this->destination,
175175
$input->getOption('db-name'),
176-
$this->file
176+
$this->filename
177177
);
178178
$this->io->comment('Importing dump');
179179
}
@@ -202,38 +202,38 @@ protected function execute(InputInterface $input, OutputInterface $output) {
202202
*
203203
* Can be copied from a remote or local desintaiton.
204204
*
205-
* @param $file
205+
* @param $filename
206206
* The file to be copied.
207207
*
208208
* @return string
209209
* The absolute path for the dump.
210210
*
211211
* @throws SiteCommandException
212212
*/
213-
protected function copy($file) {
213+
protected function copy($filename) {
214214
// Sanitise the input file path.
215-
$file = $this->cleanFileName($file);
216-
$filename = basename($file);
215+
$filename = $this->cleanFileName($filename);
216+
$basename = basename($filename);
217217

218218
// Return canonicalized absolute pathname for local files.
219-
if (stream_is_local($file)) {
220-
$file = realpath($file);
219+
if (stream_is_local($filename)) {
220+
$filename = realpath($filename);
221221
}
222222

223223
// Check we're not explicitly using a file in the local destination.
224-
if (substr($file, 0, strlen($this->tmpFolder)) === $this->tmpFolder) {
225-
return $file;
224+
if (substr($filename, 0, strlen($this->tmpFolder)) === $this->tmpFolder) {
225+
return $filename;
226226
}
227227

228228
// Save the db dump from S3 to the local destination.
229229
// We use S3cmd because the stream_wrapper isn't authenticated
230230
// and because it validates the checksum for us.
231-
if ('s3' === parse_url($file, PHP_URL_SCHEME)) {
231+
if ('s3' === parse_url($filename, PHP_URL_SCHEME)) {
232232
$command = sprintf(
233233
'cd %s && ' .
234234
's3cmd --force --check-md5 get %s',
235235
$this->tmpFolder,
236-
$file
236+
$filename
237237
);
238238

239239
$shellProcess = $this->getShellProcess();
@@ -248,58 +248,60 @@ protected function copy($file) {
248248
// we copy chunk by chunk to the local destination.
249249
else {
250250
// Check the file isn't already downloaded.
251-
$this->io->write(sprintf('Checking if db dump needs updating: '));
252-
if ($this->fileExists($this->tmpFolder . $filename) && md5_file($this->tmpFolder . $filename) === md5_file($file)) {
253-
$this->io->writeln('No');
254-
return $this->tmpFolder . $filename;
251+
$this->io->write(sprintf('Checking if db dump needs updating:'));
252+
if ($this->fileExists($this->tmpFolder . $basename) && md5_file($this->tmpFolder . $basename) === md5_file($filename)) {
253+
$this->io->comment('No');
255254
}
256-
$this->io->writeln('Yes');
257-
258-
// Open a stream in read-only mode
259-
if ($stream = fopen($file, 'r')) {
260-
// Open the destination file to save the output to.
261-
$output_file = fopen($this->tmpFolder . $filename, "a");
262-
if ($output_file) {
263-
while (!feof($stream)) {
264-
fwrite($output_file, fread($stream, 1024), 1024);
255+
else {
256+
$this->io->comment('Yes');
257+
// Open a stream in read-only mode
258+
if ($this->fileExists($filename) && $stream = fopen($filename, 'r')) {
259+
// Open the destination file to save the output to.
260+
$output_file = fopen($this->tmpFolder . $basename, "a");
261+
if ($output_file) {
262+
while (!feof($stream)) {
263+
fwrite($output_file, fread($stream, 1024), 1024);
264+
}
265+
}
266+
fclose($stream);
267+
if ($output_file) {
268+
fclose($output_file);
265269
}
266270
}
267-
fclose($stream);
268-
if ($output_file) {
269-
fclose($output_file);
270-
}
271-
}
272-
else {
273-
throw new SiteCommandException("The DB dump does not exist or is not readable.");
274271
}
275272
}
276273

277-
// Check that the db dump has been saved.
278-
if (!$this->fileExists($this->tmpFolder . $filename)) {
279-
throw new SiteCommandException("The DB dump could not be saved to the local destination.");
274+
// Final check to see if copy was successful.
275+
if (!$this->fileExists($this->tmpFolder . $basename)) {
276+
$this->io->error(sprintf('Could not copy the dump to %s', $this->tmpFolder . $basename));
277+
278+
return FALSE;
280279
}
281-
$this->io->success(sprintf('The DB dump was copied to %s.', $this->tmpFolder . $filename));
282280

283-
return $this->tmpFolder . $filename;
281+
return $this->tmpFolder . $basename;
284282
}
285283

286284
/**
287-
* @param $file
285+
* @param $filename
288286
* The zipped file to be extracted.
289287
*
290288
* @return string
291289
* The unzipped file.
292290
*
293291
* @throws SiteCommandException
294292
*/
295-
public function unzip($file) {
293+
public function unzip($filename) {
294+
if (!$this->fileExists($filename)) {
295+
return FALSE;
296+
}
297+
296298
// The basename without any path.
297-
$baseNameGz = basename($file);
299+
$baseNameGz = basename($filename);
298300
// The basename with sql extension.
299301
$baseNameSql = rtrim($baseNameGz, '.gz');
300302

301303
// Unzip sql file and keep zipped in the folder.
302-
if (mime_content_type($this->file) === 'application/x-gzip') {
304+
if (mime_content_type($this->filename) === 'application/x-gzip') {
303305
$command = sprintf(
304306
'cd %s; ' .
305307
'gunzip -c %s > %s; ',
@@ -310,7 +312,7 @@ public function unzip($file) {
310312
}
311313
// Return the file without modification.
312314
else {
313-
return $file;
315+
return $filename;
314316
}
315317

316318
// Run unzip command.

0 commit comments

Comments
 (0)