Skip to content

Commit

Permalink
Merge pull request #63 from JarvusInnovations/develop
Browse files Browse the repository at this point in the history
Release: emergence v1.0.7
  • Loading branch information
themightychris authored Apr 27, 2018
2 parents 4a4bd86 + 53ced06 commit 0a6b666
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 3 deletions.
50 changes: 50 additions & 0 deletions bin/fire-event
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node


require('yargs')
.command('$0 <site> <event> <context>', 'Fire event within site', yargs => {
yargs
.positional('site', {
describe: 'Handle of site to fire event within'
})
.positional('event', {
describe: 'Name of event to fire'
})
.positional('context', {
describe: 'Context path to fire event within'
})
}, argv => {
var path = require('path'),
documentRoot = path.resolve(__dirname, '../php-bootstrap'),
PHPFPM = require('node-phpfpm'),
phpClient = new PHPFPM({
sockFile: '/emergence/services/run/php-fpm/php-fpm.sock',
documentRoot: documentRoot + '/'
}),
payload = Object.assign({}, argv);

delete payload._;
delete payload.help;
delete payload.version;
delete payload.site;
delete payload.event;
delete payload.context;
delete payload['$0'];

// execute event via PHP-FPM interface
phpClient.run({
uri: 'event.php',
json: {
site: argv.site,
event: argv.event,
context: argv.context,
payload: payload
}
}, function (err, output, phpErrors) {
if (err == 99) console.error('PHPFPM server error');
console.log(output);
if (phpErrors) console.error(phpErrors);
});

})
.argv;
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "emergence",
"preferGlobal": true,
"version": "1.0.6",
"version": "1.0.7",
"license": "MIT",
"dependencies": {
"hostile": "^1.0.2",
Expand All @@ -14,15 +14,17 @@
"semver": "^5.1.0",
"shelljs": "^0.5.3",
"underscore": "1.3.x",
"underscore-cli": "^0.2.19"
"underscore-cli": "^0.2.19",
"yargs": "^11.0.0"
},
"bin": {
"emergence-kernel": "./bin/kernel",
"emergence-shell": "./bin/shell",
"emergence-git-shell": "./bin/git-shell",
"emergence-su": "./bin/su",
"emergence-create-site": "./bin/create-site.sh",
"emergence-mysql-shell": "./bin/mysql-shell"
"emergence-mysql-shell": "./bin/mysql-shell",
"emergence-fire-event": "./bin/fire-event"
},
"repository": {
"type": "git",
Expand Down
46 changes: 46 additions & 0 deletions php-bootstrap/event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

// bootstrap emergence
require('bootstrap.inc.php');


// only process POST requests
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
http_response_code(405);
echo "POST only";
exit(1);
}


// parse and validate input
$input = json_decode(file_get_contents('php://input'), true);

if (
empty($input)
|| empty($input['site'])
|| empty($input['event'])
|| empty($input['context'])
) {
http_response_code(400);
echo "site, event, and context required";
exit(1);
}


// identify site
$siteRoot = "/emergence/sites/{$input['site']}";

if (!is_dir($siteRoot)) {
http_response_code(404);
echo "site not found";
exit(1);
}


// initialize site
Site::$debug = true;
Site::initialize($siteRoot, 'localhost');


// fire event
Emergence\EventBus::fireEvent($input['event'], $input['context'], !empty($input['payload']) ? $input['payload'] : array());

0 comments on commit 0a6b666

Please sign in to comment.