m7v
8/4/2015 - 5:43 AM

Robo tasks for drupal

Robo tasks for drupal

<?php

class RoboFile extends \Robo\Tasks
{
  private function DrupalExec($siteprefix, $command, $instance) {
    $sitenames = array(
      'ex1' => 'examle1.com',
      'ex2' => 'examle2.com',
      'ex3' => 'examle3.com',
      'all' => array(
        'examle1.com',
        'examle2.com',
        'examle3.com',
      )
    );

    $instance_prefix = '';
    if ($instance) {
      $instance_prefix = "@.{$instance}";
    }

    if (is_array($sitenames[$siteprefix])) {
      $task = $this->taskParallelExec();
      foreach ($sitenames[$siteprefix] as $sitename) {
        $task->printed(TRUE);
        $task->process("drush $instance_prefix $command -l {$sitename}");
      }
      $task->run();
    }
    else {
      $this->taskExecStack()
        ->stopOnFail()
        ->printed(TRUE)
        ->exec("drush $instance_prefix $command -l {$sitenames[$siteprefix]}")
        ->run();
    }
  }

  /**
   * Clear drupal cache
   */
  public function DCCA($siteprefix, $instance = NULL) {
    $this->DrupalExec($siteprefix, 'cc all', $instance);
  }

  /**
   * Clear drupal cache
   */
  public function DEval($siteprefix, $instance = NULL, $function = 'function()') {
    $this->DrupalExec($siteprefix, "eval '{$function}'", $instance);
  }

  /**
   * Revert all features
   */
  public function DFRA($siteprefix, $instance = NULL) {
    $this->DrupalExec($siteprefix, 'fra -y --force', $instance);
  }

  /**
   * Update database
   */
  public function DUDB($siteprefix, $instance = NULL) {
    $this->DrupalExec($siteprefix, 'updb -y', $instance);
  }

  /**
   * Login like admin
   */
  public function DULI($siteprefix, $instance = NULL) {
    $this->DrupalExec($siteprefix, 'uli --browser=0', $instance);
  }

  /**
   * Run cron
   */
  public function DRC($siteprefix, $instance = NULL) {
    $this->DrupalExec($siteprefix, 'elysia-cron', $instance);
  }

  /**
   * Enable
   */
  public function DME($siteprefix, $instance = NULL, $module = 'devel') {
    $this->DrupalExec($siteprefix, "en $module -y", $instance);
  }
  
  /**
   * Disa
   */
  public function DME($siteprefix, $instance = NULL, $module = 'devel') {
    $this->DrupalExec($siteprefix, "dis $module -y", $instance);
  }

  /**
   * Deploy instance
   * -run update database
   * -run clear cache
   * -run features revert;
   */
  public function DDeploy($siteprefix, $instance = NULL) {
    $this->DUDB($siteprefix, $instance);
    $this->DFRA($siteprefix, $instance);
    $this->DCCA($siteprefix, $instance);
  }
}