Created
December 12, 2013 17:15
-
-
Save kreitje/7931609 to your computer and use it in GitHub Desktop.
Laravel 4 commands that can work remotely while be called on a local system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class RefreshCommand extends RemoteSupportCommand { | |
protected $name = 'mysite:refresh'; | |
protected $description = 'My description'; | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function fire() | |
{ | |
/** | |
* If parent::fire() returns 1, it was executed on the connection server and not local. | |
*/ | |
if (parent::fire() == 1) | |
return true; | |
// run my task such as sending daily email etc etc. | |
} | |
protected function getArguments() | |
{ | |
return parent::getArguments(); | |
} | |
protected function getOptions() | |
{ | |
return array(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Illuminate\Support\Facades\SSH; | |
/** | |
* TODO: Pass in the arguments to the fire method | |
*/ | |
class RemoteSupportCommand extends Command { | |
protected $name = ''; | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function fire() | |
{ | |
if ( is_null( $this->argument('connection') ) ) return 0; | |
SSH::into( $this->argument('connection') )->run(array( | |
'cd ' . $this->getRoot( $this->argument('connection') ), | |
'php artisan ' . $this->name, | |
)); | |
return 1; | |
} | |
protected function getRemote($connection) { | |
return $this->laravel['remote']->connection( $connection ); | |
} | |
protected function getRoot($connection) { | |
return $this->laravel['config']['remote.connections.' . $connection . '.root']; | |
} | |
protected function getArguments() | |
{ | |
return array( | |
array('connection', InputArgument::OPTIONAL, 'The remote commention name') | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment