Skip to content

Commit

Permalink
Fixes #36, #56: Making DrushTask conform to Phing verbosity. Converti…
Browse files Browse the repository at this point in the history
…ng <exec> instances to <drush>.
  • Loading branch information
grasmash committed Sep 9, 2016
1 parent 1722aed commit 5df54cd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 25 deletions.
4 changes: 4 additions & 0 deletions phing/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ drush:
cmd: ${drush.bin} @${drush.alias} -r ${docroot} -l ${multisite.name}
dir: ${repo.root}
root: ${docroot}
uri: ${multisite.name}
assume: yes
passthru: yes
verbose: yes

multisite:
# The docroot/sites/default directory is used by default.
Expand Down
45 changes: 38 additions & 7 deletions phing/phingcludes/DrushTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class DrushTask extends Task {
private $return_property = NULL;
private $verbose = FALSE;
private $haltonerror = TRUE;
private $passthru = FALSE;

/**
* The Drush command to run.
Expand Down Expand Up @@ -119,8 +120,11 @@ public function setUri($str) {
* Assume 'yes' or 'no' to all prompts.
*/
public function setAssume($var) {
if (is_string($var)) {
$this->assume = ($var === 'yes');
if ($var === "") {
unset($this->assume);
}
elseif (is_string($var)) {
$this->assume = ($var === 'yes' || $var === 'true');
} else {
$this->assume = !!$var;
}
Expand Down Expand Up @@ -199,7 +203,18 @@ public function createOption() {
*/
public function setVerbose($var) {
if (is_string($var)) {
$this->verbose = ($var === 'yes');
$this->verbose = ($var === 'yes' || $var === 'true');
} else {
$this->verbose = !!$var;
}
}

/**
* Use passthru() rather than exec() for command execution.
*/
public function setPassthru($var) {
if (is_string($var)) {
$this->verbose = ($var === 'yes' || $var === 'true');
} else {
$this->verbose = !!$var;
}
Expand All @@ -214,6 +229,14 @@ public function init() {
$this->uri = $this->getProject()->getProperty('drush.uri');
$this->bin = $this->getProject()->getProperty('drush.bin');
$this->dir = $this->getProject()->getProperty('drush.dir');
$this->alias = $this->getProject()->getProperty('drush.alias');
$this->setVerbose($this->getProject()->getProperty('drush.verbose'));
$this->setAssume($this->getProject()->getProperty('drush.assume'));
$this->setPassthru($this->getProject()->getProperty('drush.passthru'));

if (Phing::getMsgOutputLevel() >= Project::MSG_VERBOSE) {
$this->setVerbose('yes');
}
}

/**
Expand Down Expand Up @@ -290,11 +313,19 @@ public function main() {
// Execute Drush.
$this->log("Executing: $command");
$output = array();
exec($command, $output, $return);
// Collect Drush output for display through Phing's log.
foreach ($output as $line) {
$this->log($line);
$return = NULL;

if ($this->passthru) {
passthru($command, $return);
}
else {
exec($command, $output, $return);
// Collect Drush output for display through Phing's log.
foreach ($output as $line) {
$this->log($line);
}
}

// Set value of the 'pipe' property.
if (!empty($this->return_property)) {
$this->getProject()->setProperty($this->return_property, implode($this->return_glue, $output));
Expand Down
5 changes: 4 additions & 1 deletion phing/tasks/acsf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<echo>Modifying project.yml.</echo>
<exec dir="${repo.root}" command="drupal yaml:update:value project.yml hosting acsf" logoutput="true" checkreturn="true" passthru="true" level="info"/>
<echo>Executing initialization command for acsf module.</echo>
<exec dir="${docroot}" command="${drush.cmd} --include=${docroot}/modules/contrib/acsf/acsf_init acsf-init --skip-default-settings -y" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<drush command="acsf-init">
<option name="include">"${docroot}/modules/contrib/acsf/acsf_init"</option>
<option name="skip-default-settings"></option>
</drush>
<echo>Please add acsf_init as a dependency for your installation profile to ensure that it remains enabled.</echo>
<echo>An example alias file for ACSF is located in /drush/site-aliases/example.acsf.aliases.drushrc.php.</echo>
</target>
Expand Down
2 changes: 1 addition & 1 deletion phing/tasks/blt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<target name="blt:update-yml" description="Updates project BLT .yml files with new key value pairs from upstream. This WILL NOT overwrite existing values.">
<!--@todo Output different message if project.yml does not exist-->
<echo>Merging BLT's project.yml template with your project's project.yml</echo>
<echo>Merging BLT's project.yml template with your project's project.yml.</echo>
<echo>This WILL NOT overwrite existing values.</echo>
<!--Values in the project's existing project.yml file will be preserved and not overridden.-->
<exec dir="${repo.root}" command="${repo.root}/vendor/bin/blt-console yaml:munge ${blt.root}/template/project.yml ${repo.root}/project.yml > ${repo.root}/project.yml.tmp" logoutput="true" checkreturn="true" level="info"/>
Expand Down
16 changes: 11 additions & 5 deletions phing/tasks/local-sync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

<target name="local:sync" description="Synchronize local environment from remote (remote --> local)."
depends="setup:drupal:settings">
<exec dir="${docroot}" command="${drush.cmd} sql-drop -y" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<!--We cannot use drush.cmd here because it incorrectly assigns an alias to the command. -->
<exec dir="${docroot}" command="${drush.bin} -r ${docroot} -l ${multisite.name} sql-sync @${drush.aliases.remote} @${drush.aliases.local} --create-db --structure-tables-key=lightweight -y" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${docroot}" command="${drush.cmd} cc drush" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${docroot}" command="${drush.cmd} cr" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<drush command="sql-drop"/>
<drush command="sql-sync" alias="">
<option name="structure-tables-key">lightweight</option>
<option name="create-db"/>
<param>@${drush.aliases.remote}</param>
<param>@${drush.aliases.local}</param>
</drush>
<drush command="cache-clear">
<param>drush</param>
</drush>
<drush command="cache-rebuild"/>
</target>

<target name="local:update" description="Update current database to reflect the state of the Drupal file system; uses local drush alias.">
Expand Down
5 changes: 5 additions & 0 deletions phing/tasks/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</if>

<target name="echo-property" description="Echoes the value of a Phing property.">
<fail unless="property.name" message="property.name must be set!"/>
<echo>${property.name}</echo>
<if>
<isset property="${property.name}"/>
Expand All @@ -46,4 +47,8 @@
</if>
</target>

<target name="echo-properties" description="Echoes the value of all Phing properties.">
<echoproperties/>
</target>

</project>
21 changes: 10 additions & 11 deletions phing/tasks/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<not><available file="${docroot}/sites/default/settings.php"/></not>
<then>
<echo>Generating settings.php from default.settings.php.</echo>
<copy file="${docroot}/sites/default/default.settings.php" tofile="${docroot}/sites/default/settings.php"/>
<copy file="${docroot}/sites/default/default.settings.php" tofile="${docroot}/sites/default/settings.php" verbose="true"/>
</then>
</if>
<echo>Making ${docroot}/sites/default/settings.php writable.</echo>
Expand All @@ -70,7 +70,7 @@
<if>
<not><available file="${repo.root}/project.local.yml" type="file" /></not>
<then>
<copy file="${repo.root}/example.project.local.yml" tofile="${repo.root}/project.local.yml" />
<copy file="${repo.root}/example.project.local.yml" tofile="${repo.root}/project.local.yml" verbose="true" />
</then>
</if>

Expand All @@ -80,11 +80,11 @@
<if>
<available file="${docroot}/sites/${multisite.name}/settings/default.local.settings.php" type="file" />
<then>
<copy file="${docroot}/sites/${multisite.name}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/local.settings.php" />
<copy file="${docroot}/sites/${multisite.name}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/local.settings.php" verbose="true"/>
</then>
<else>
<copy file="${blt.root}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/default.local.settings.php" />
<copy file="${blt.root}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/local.settings.php" />
<copy file="${blt.root}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/default.local.settings.php" verbose="true"/>
<copy file="${blt.root}/settings/default.local.settings.php" tofile="${docroot}/sites/${multisite.name}/settings/local.settings.php" verbose="true" />
</else>
</if>
</then>
Expand All @@ -96,11 +96,11 @@
<if>
<available file="${docroot}/sites/${multisite.name}/default.local.drushrc.php" type="file" />
<then>
<copy file="${docroot}/sites/${multisite.name}/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/local.drushrc.php" />
<copy file="${docroot}/sites/${multisite.name}/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/local.drushrc.php" verbose="true" />
</then>
<else>
<copy file="${blt.root}/settings/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/default.local.drushrc.php" />
<copy file="${blt.root}/settings/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/local.drushrc.php" />
<copy file="${blt.root}/settings/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/default.local.drushrc.php" verbose="true"/>
<copy file="${blt.root}/settings/default.local.drushrc.php" tofile="${docroot}/sites/${multisite.name}/local.drushrc.php" verbose="true"/>
</else>
</if>
</then>
Expand All @@ -124,16 +124,15 @@
depends="setup:drupal:settings, setup:hash-salt, configure">

<echo>Printing drush status.</echo>
<drush command="status" alias="${drush.alias}"/>
<drush command="status"/>

<echo>Installing Drupal.</echo>
<drush command="site-install" assume="yes" verbose="TRUE" alias="${drush.alias}">
<drush command="site-install">
<option name="site-name">"${project.human_name}"</option>
<option name="site-mail">"${drupal.account.mail}"</option>
<option name="account-name">"${drupal.account.name}"</option>
<option name="account-pass">"${drupal.account.password}"</option>
<option name="account-mail">"${drupal.account.mail}"</option>
<option name="l">"${multisite.name}"</option>
<param>"${project.profile.name}"</param>
<param>"install_configure_form.update_status_module='array(FALSE,FALSE)'"</param>
</drush>
Expand Down

0 comments on commit 5df54cd

Please sign in to comment.