Extends
lithium\console\Command
Send a plugin archive to the server. The plugin must have a formula.
Parameters
- string $name the library name or full path to the archive to send
Returns
voidSource
public function push($name = null) {
if (!$name) {
$name = $this->in("please supply a name");
}
$path = $this->_toPath($name);
$name = basename($name);
$file = "{$path}.phar.gz";
if (!file_exists("phar://{$file}/config/{$name}.json")) {
$this->error(array(
"The forumla for {$name} is missing.", "Run li3 library formulate {$name}"
));
return false;
}
$formula = json_decode(file_get_contents("phar://{$file}/config/{$name}.json"));
$isValid = (
!empty($formula->name) && !empty($formula->version)
&& !empty($formula->summary) && !empty($formula->sources)
);
if (!$isValid) {
$this->error(array(
"The forumla for {$name} is not valid.", "Run li3 library formulate {$name}"
));
return false;
}
if (file_exists($file)) {
$service = $this->_instance('service', array(
'host' => $this->server, 'port' => $this->port,
'auth' => 'Basic', 'username' => $this->username, 'password' => $this->password
));
$boundary = md5(date('r', time()));
$headers = array("Content-Type: multipart/form-data; boundary={$boundary}");
$name = basename($file);
$data = join("\r\n", array(
"--{$boundary}",
"Content-Disposition: form-data; name=\"phar\"; filename=\"{$name}\"",
"Content-Type: application/phar", "",
base64_encode(file_get_contents($file)),
"--{$boundary}--"
));
$result = json_decode($service->post(
'/lab/server/receive', $data, compact('headers')
));
if ($service->last->response->status['code'] == 201) {
$this->out(array(
"{$result->name} added to {$this->server}.",
"See http://{$this->server}/lab/plugins/view/{$result->id}"
));
return $result;
}
if (!empty($result->error)) {
$this->error($result->error);
return false;
}
$this->error((array) $result);
return false;
}
$this->error(array("{$file} does not exist.", "Run li3 library archive {$name}"));
return false;
}