Switchboard
  • Namespace
  • Class
  • Tree

Namespaces

  • Fluxsauce
    • Switchboard

Classes

  • EnvDb
  • Environment
  • Persistent
  • Project
  • Provider
  • ProviderAcquia
  • ProviderPantheon
  • Site
  • Sqlite
  1 <?php
  2 /**
  3  * @file
  4  * Local Project.
  5  */
  6 
  7 namespace Fluxsauce\Switchboard;
  8 
  9 /**
 10  * Local Project.
 11  * @package Fluxsauce\Switchboard
 12  */
 13 class Project extends Persistent {
 14   /**
 15    * @var string The UUID of the Project.
 16    */
 17   protected $uuid;
 18 
 19   /**
 20    * @var int External key to an associated Site.
 21    */
 22   protected $siteId;
 23 
 24   /**
 25    * @var string The hostname for the local Project.
 26    */
 27   protected $hostname;
 28 
 29   /**
 30    * @var string The UNIX username for the local Project.
 31    */
 32   protected $username;
 33 
 34   /**
 35    * @var int The SSH port for the local Project.
 36    */
 37   protected $sshPort;
 38 
 39   /**
 40    * @var string The path on disk to the code root.
 41    */
 42   protected $codePath;
 43 
 44   /**
 45    * @var string The hostname for the Project database.
 46    */
 47   protected $databaseHost;
 48 
 49   /**
 50    * @var string The username for the Project database.
 51    */
 52   protected $databaseUsername;
 53 
 54   /**
 55    * @var string The password for the Project database.
 56    */
 57   protected $databasePassword;
 58 
 59   /**
 60    * @var string The database name for the Project database.
 61    */
 62   protected $databaseName;
 63 
 64   /**
 65    * @var int The port for the Project database.
 66    */
 67   protected $databasePort;
 68 
 69   /**
 70    * @var string The path on disk to the files root.
 71    */
 72   protected $filesPath;
 73 
 74   /**
 75    * @var string Metadata for ORM defining database structure.
 76    */
 77   protected $externalKeyName = 'name';
 78 
 79   /**
 80    * Get the minimal database specs.
 81    *
 82    * @return array
 83    *   Keys for database, host, user, password, port.
 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    * Get a database connection string.
 97    *
 98    * @return string
 99    *   The command for connecting to a database.
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    * Get a Drupal v6 database connection string.
112    *
113    * @return string
114    *   The db-url string.
115    */
116   public function getDatabaseUrl() {
117     return "mysql://{$this->databaseUsername}:{$this->databasePassword}@{$this->databaseHost}:{$this->databasePort}/{$this->databaseName}";
118   }
119 
120   /**
121    * Get a Drupal v7 database connection settings.
122    *
123    * @return string
124    *   The databases array.
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    * Generate command to commit all code changes.
141    *
142    * @param string $message
143    *   The git commit message.
144    *
145    * @return string
146    *   The git command.
147    */
148   public function vcsCommitCommand($message) {
149     return 'cd ' . $this->codePath . ' && git add --all . && git commit -m ' . drush_escapeshellarg($message);
150   }
151 
152   /**
153    * Generate command to pull code changes from remote.
154    *
155    * @return string
156    *   The git command.
157    */
158   public function vcsPullCommand() {
159     return 'git --git-dir=' . $this->codePath . '/.git pull origin master';
160   }
161 
162   /**
163    * Generate command to push code changes to remote.
164    *
165    * @return string
166    *   The git command.
167    */
168   public function vcsPushCommand() {
169     return 'git --git-dir=' . $this->codePath . '/.git push origin master';
170   }
171 
172   /**
173    * Generate command to reset all local code changes.
174    *
175    * @return string
176    *   The git command.
177    */
178   public function vcsResetCommand() {
179     return 'cd ' . $this->codePath . ' && git checkout .';
180   }
181 
182   /**
183    * Renders a project as a Drush alias.
184    *
185    * @return string
186    *   Drush alias.
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 
Switchboard API documentation generated by ApiGen 2.8.0