Skip to content

Commit 0f7c924

Browse files
Merge pull request #20 from dennisinteractive/27657_CDN
This is working correctly
2 parents 2672a6c + 521444e commit 0f7c924

File tree

4 files changed

+123
-5
lines changed

4 files changed

+123
-5
lines changed

chain/chain-site-rebuild.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ commands:
2121
- command: site:settings:db
2222
arguments:
2323
name: '%{{name}}'
24-
# Enable development settings
25-
- command: exec
24+
# Create settings.local.php
25+
- command: site:settings:local
2626
arguments:
27-
bin: 'cd /vagrant/repos/%{{name}}/web/sites; cp -n ./example.settings.local.php ./default/settings.local.php;'
27+
name: '%{{name}}'
2828
# Create phpunit.xml
2929
- command: site:phpunit:setup
3030
arguments:

console.config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ application:
1010
class: \DennisDigital\Drupal\Console\Command\SiteSettingsDbCommand
1111
'site:settings:memcache':
1212
class: \DennisDigital\Drupal\Console\Command\SiteSettingsMemcacheCommand
13+
'site:settings:local':
14+
class: \DennisDigital\Drupal\Console\Command\SiteSettingsLocalCommand
1315
'site:db:import':
1416
class: \DennisDigital\Drupal\Console\Command\SiteDbImportCommand
1517
'site:behat:setup':

src/Command/SiteCheckoutCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ protected function gitCheckout($branch, $destination) {
302302
/**
303303
* Pulls a list of branches from remote.
304304
*
305-
* @param $repo
306-
*
307305
* @return mixed
308306
* @throws SiteCommandException
309307
*/
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
$host= $this->config['host'];
90+
$cdn = $this->config['cdn'];
91+
92+
// Append configuration.
93+
$content .= <<<EOF
94+
95+
// Set Stage file proxy origin.
96+
\$config['stage_file_proxy.settings']['origin'] = '$cdn';
97+
98+
// Change CDN domain to local.
99+
\$config['cdn.settings']['mapping']['domain'] = '$host';
100+
101+
EOF;
102+
103+
$this->filePutContents($file, $content);
104+
105+
// Check file.
106+
if ($this->fileExists($file)) {
107+
$this->io->success(sprintf('Generated %s',
108+
$file)
109+
);
110+
}
111+
else {
112+
throw new SiteCommandException(sprintf('Error generating %s',
113+
$file
114+
)
115+
);
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)