forked from drupal-tome/tome_drush
-
Notifications
You must be signed in to change notification settings - Fork 1
/
InstallCommands.php
115 lines (99 loc) · 3.98 KB
/
InstallCommands.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
<?php
namespace Drush\Commands\tome_drush;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Extension\InfoParserDynamic;
use Drupal\Core\Site\Settings;
use Drush\Commands\DrushCommands;
use Drush\Drupal\ExtensionDiscovery;
use Drush\Drush;
use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
use Consolidation\SiteAlias\SiteAliasManagerAwareInterface;
/**
* Contains install and init commands for tome.
*/
class InstallCommands extends DrushCommands implements SiteAliasManagerAwareInterface {
use SiteAliasManagerAwareTrait;
/**
* Installs tome.
*
* @bootstrap configuration
* @command tome:install
*
* @return int|null
* The status code, if the command did not complete successfully.
*/
public function install() {
if (!$this->io()->confirm('You are about to DROP all tables in your local database and re-install Tome. Do you want to continue?', FALSE)) {
return 0;
}
FileCacheFactory::setConfiguration(['default' => ['class' => '\Drupal\Component\FileCache\NullFileCache']]);
$source_storage = new FileStorage(Settings::get('config_sync_directory'));
if (!$source_storage->exists('core.extension')) {
$this->io()->warning('Existing configuration to install from not found. If this is your first time using Tome try running "drush tome:init".');
return 1;
}
$config = $source_storage->read('core.extension');
$self = $this->siteAliasManager()->getSelf();
Drush::drush($self, 'site-install', [$config['profile']], ['yes' => TRUE, 'sites-subdir' => 'default'])->mustRun();
if (isset($config['module']['tome_sync'])) {
Drush::drush($self, 'pm:enable', ['tome_sync'], ['yes' => TRUE])->mustRun();
}
else {
Drush::drush($self, 'pm:enable', ['tome'], ['yes' => TRUE])->mustRun();
}
Drush::drush($self, 'tome:import', [], ['yes' => TRUE])->mustRun();
Drush::drush($self, 'cache:rebuild', [], ['yes' => TRUE])->mustRun();
$this->io()->success('Install complete!');
}
/**
* Initializes tome.
*
* @bootstrap configuration
* @command tome:init
*
* @return int|null
* The status code, if the command did not complete successfully.
*/
public function init() {
if (is_dir(Settings::get('config_sync_directory')) || is_dir(Settings::get('tome_content_directory', '../content'))) {
if (!$this->io()->confirm('Running this command will remove all exported content and configuration. Do you want to continue?', FALSE)) {
return 0;
}
}
$profiles = $this->getProfiles();
$profile = $this->io()->choice('Select an installation profile', $profiles);
$self = $this->siteAliasManager()->getSelf();
Drush::drush($self, 'site-install', [$profile], ['yes' => TRUE, 'sites-subdir' => 'default'])->mustRun();
Drush::drush($self, 'pm:enable', ['tome'], ['yes' => TRUE])->mustRun();
Drush::drush($self, 'tome:export', [], ['yes' => TRUE])->mustRun();
$this->io()->success('Initialization complete!');
}
/**
* Gets a list of profiles.
*
* @return string[]
* An array of profile descriptions keyed by the profile machine name.
*/
protected function getProfiles() {
// Build a list of all available profiles.
$listing = new ExtensionDiscovery(getcwd(), FALSE);
$listing->setProfileDirectories([]);
$profiles = [];
$info_parser = new InfoParserDynamic();
foreach ($listing->scan('profile') as $profile) {
$details = $info_parser->parse($profile->getPathname());
// Don't show hidden profiles.
if (!empty($details['hidden'])) {
continue;
}
// Determine the name of the profile; default to the internal name if none
// is specified.
$name = isset($details['name']) ? $details['name'] : $profile->getName();
$description = isset($details['description']) ? "$name - {$details['description']}" : $name;
$profiles[$profile->getName()] = $description;
}
natcasesort($profiles);
return $profiles;
}
}