Skip to content

Commit 7f9f66b

Browse files
committed
Case 27657; New command
1 parent 87efa49 commit 7f9f66b

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \DennisDigital\Drupal\Console\Command\SiteSettingsLocalCommand.
6+
*
7+
* Creates Local configurations.
8+
*/
9+
10+
namespace DennisDigital\Drupal\Console\Command;
11+
12+
use Symfony\Component\Console\Input\InputOption;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
use DennisDigital\Drupal\Console\Exception\SiteCommandException;
16+
17+
/**
18+
* Class SiteSettingsLocalCommand
19+
*
20+
* @package DennisDigital\Drupal\Console\Command
21+
*/
22+
class SiteSettingsLocalCommand extends SiteBaseCommand {
23+
24+
/**
25+
* The file name to generate.
26+
*
27+
* @var
28+
*/
29+
protected $filename = 'settings.local.php';
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
protected function configure() {
35+
parent::configure();
36+
37+
$this->setName('site:settings:local')
38+
// @todo use: ->setDescription($this->trans('commands.site.settings.local.description'))
39+
->setDescription('Generates settings.local.php for a given site.');
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
protected function interact(InputInterface $input, OutputInterface $output) {
46+
parent::interact($input, $output);
47+
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
protected function execute(InputInterface $input, OutputInterface $output) {
54+
parent::execute($input, $output);
55+
56+
$this->destination = $this->settingsPhpDirectory();
57+
58+
// Validation.
59+
if (!$this->fileExists($this->destination . '../example.' . $this->filename)) {
60+
$message = sprintf('The file example.settings.local.php is missing.',
61+
$this->destination
62+
);
63+
throw new SiteCommandException($message);
64+
}
65+
66+
// Remove existing file.
67+
$file = $this->destination . $this->filename;
68+
if ($this->fileExists($file)) {
69+
$this->fileUnlink($file);
70+
}
71+
72+
// Copy example.
73+
$command = sprintf('cd %s && cp -n ../example.%s %s',
74+
$this->shellPath($this->destination),
75+
$this->filename,
76+
$this->filename
77+
);
78+
$shellProcess = $this->getShellProcess();
79+
if (!$shellProcess->exec($command, TRUE)) {
80+
throw new SiteCommandException(sprintf('Error generating %s',
81+
$this->filename
82+
)
83+
);
84+
}
85+
86+
// Load the file.
87+
$content = $this->fileGetContents($file);
88+
89+
// Append configuration.
90+
$content .= <<<EOF
91+
92+
// Set Stage file proxy origin.
93+
\$config['stage_file_proxy.settings']['origin'] = 'cdn.subscriptions.dennis.co.uk';
94+
95+
// Change CDN domain to local.
96+
\$config['cdn.settings']['mapping']['domain'] = 'subscriptions.vm8.didev.co.uk';
97+
98+
EOF;
99+
100+
$this->filePutContents($file, $content);
101+
102+
// Check file.
103+
if ($this->fileExists($file)) {
104+
$this->io->success(sprintf('Generated %s',
105+
$file)
106+
);
107+
}
108+
else {
109+
throw new SiteCommandException(sprintf('Error generating %s',
110+
$file
111+
)
112+
);
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)