1 <?php
2 3 4 5
6
7 namespace Fluxsauce\Switchboard;
8
9 10 11 12
13 class Project extends Persistent {
14 15 16
17 protected $uuid;
18
19 20 21
22 protected $siteId;
23
24 25 26
27 protected $hostname;
28
29 30 31
32 protected $username;
33
34 35 36
37 protected $sshPort;
38
39 40 41
42 protected $codePath;
43
44 45 46
47 protected $databaseHost;
48
49 50 51
52 protected $databaseUsername;
53
54 55 56
57 protected $databasePassword;
58
59 60 61
62 protected $databaseName;
63
64 65 66
67 protected $databasePort;
68
69 70 71
72 protected $filesPath;
73
74 75 76
77 protected $externalKeyName = 'name';
78
79 80 81 82 83 84
85 public function getDatabaseSpecs() {
86 return array(
87 'database' => $this->databaseName,
88 'host' => $this->databaseHost,
89 'user' => $this->databaseUsername,
90 'password' => $this->databasePassword,
91 'port' => $this->databasePort,
92 );
93 }
94
95 96 97 98 99 100
101 public function getDatabaseConnection() {
102 $parameter_strings = array();
103 foreach ($this->getDatabaseSpecs() as $key => $value) {
104 $value = drush_escapeshellarg($value);
105 $parameter_strings[] = "--$key=$value";
106 }
107 return 'mysql ' . implode(' ', $parameter_strings);
108 }
109
110 111 112 113 114 115
116 public function getDatabaseUrl() {
117 return "mysql://{$this->databaseUsername}:{$this->databasePassword}@{$this->databaseHost}:{$this->databasePort}/{$this->databaseName}";
118 }
119
120 121 122 123 124 125
126 public function getDatabaseSettings() {
127 return <<<CONF
128 \$databases['default']['default'] = array(
129 'driver' => 'mysql',
130 'username' => '{$this->databaseUsername}',
131 'password' => '{$this->databasePassword}',
132 'host' => '{$this->databaseHost}',
133 'port' => '{$this->databasePort}',
134 'database' => '{$this->databaseName}',
135 );
136 CONF;
137 }
138
139 140 141 142 143 144 145 146 147
148 public function vcsCommitCommand($message) {
149 return 'cd ' . $this->codePath . ' && git add --all . && git commit -m ' . drush_escapeshellarg($message);
150 }
151
152 153 154 155 156 157
158 public function vcsPullCommand() {
159 return 'git --git-dir=' . $this->codePath . '/.git pull origin master';
160 }
161
162 163 164 165 166 167
168 public function vcsPushCommand() {
169 return 'git --git-dir=' . $this->codePath . '/.git push origin master';
170 }
171
172 173 174 175 176 177
178 public function vcsResetCommand() {
179 return 'cd ' . $this->codePath . ' && git checkout .';
180 }
181
182 183 184 185 186 187
188 public function toDrushAlias() {
189 return <<<ALIAS
190 \$aliases['{$this->name}'] = array(
191 'root' => '{$this->codePath}',
192 'uri' => '{$this->hostname}',
193 'db-url' => '{$this->getDatabaseUrl()}',
194 'remote-host' => '{$this->hostname}',
195 'remote-user' => '{$this->username}',
196 'ssh-options' => '-p {$this->sshPort}',
197 'path-aliases' => array(
198 '%files' => '{$this->filesPath}',
199 ),
200 );
201 ALIAS;
202 }
203 }
204