Commit 5df2a0cb authored by Brian Dukes's avatar Brian Dukes
Browse files

updated composer command output to go to textarea to simulate terminal

parent f8319120
......@@ -85,42 +85,74 @@ class project_setup {
}
}
private function run_composer() {
private function run_composer($set_status = true) {
if (is_dir($this->project->type['path'] . '/' . $this->project->folder)) {
if (file_exists($this->project->type['path'] . '/' . $this->project->folder . '/composer.json')) {
$this->setStatus("Composer found running composer commands");
switch (strtolower($this->project->type['name'])) {
case 'magento':
$command = 'composer update && composer run-script post-install-cmd -vvv -- --redeploy';
break;
default:
$command = 'composer update';
break;
if ($set_status) {
$this->setStatus("Composer found running composer commands");
}
$command = 'composer update';
$user = exec('whoami');
putenv("COMPOSER_HOME=/home/$user/.composer");
$this->run_terminal_command("cd {$this->project->type['path']}/{$this->project->folder} && $command");
$this->setStatus("Composer ran Successfully");
if ($set_status) {
$this->setStatus("Composer ran Successfully");
}
} else {
$this->setStatus("Composer not found for this project, coninuing with setup");
if ($set_status) {
$this->setStatus("Composer not found for this project, coninuing with setup");
}
}
}
}
private function run_composer_modules($set_status = true) {
if (is_dir($this->project->type['path'] . '/' . $this->project->folder)) {
if (file_exists($this->project->type['path'] . '/' . $this->project->folder . '/composer.json')) {
if ($set_status) {
$this->setStatus("Composer found running composer commands");
}
$command = 'composer run-script post-install-cmd -vvv -- --redeploy';
$user = exec('whoami');
putenv("COMPOSER_HOME=/home/$user/.composer");
$this->run_terminal_command("cd {$this->project->type['path']}/{$this->project->folder} && $command");
if ($set_status) {
$this->setStatus("Composer ran Successfully");
}
} else {
if ($set_status) {
$this->setStatus("Composer not found for this project, coninuing with setup");
}
}
}
}
private function run_terminal_command($cmd) {
header('Content-type: text/html; charset=utf-8');
while (@ ob_end_flush()); // end all output buffers if any
$proc = popen($cmd, 'r');
echo '<pre>';
$proc = popen("$cmd 2>&1 ; echo Command Ran Successfully;", 'r');
$live_output = "";
$complete_output = "";
while (!feof($proc)) {
echo fread($proc, 4096);
$live_output = fread($proc, 4096);
$complete_output = $complete_output . $live_output;
echo "$live_output </br>";
@ flush();
}
echo '</pre>';
pclose($proc);
return true;
}
public function updateComposer() {
$this->run_composer();
$this->run_composer(false);
}
public function updateComposerModules() {
$this->run_composer_modules(false);
}
public function resyncDb() {
......@@ -134,23 +166,18 @@ class project_setup {
$dbuser = 'root';
$pass = 'root';
$tp = $this->project->remote_db_prefix;
//first check/create table
// Connect to MySQL
$link = mysql_connect('localhost', $dbuser, $pass);
// Make project the current database
$db_selected = mysql_select_db($dbname, $link);
if (!$db_selected) {
// If we couldn't, then it either doesn't exist, or we can't see it.
$sql = 'CREATE DATABASE ' . $dbname;
if (mysql_query($sql, $link)) {
}
//first check/create/connect to db
try {
$db = new PDO("mysql:host=localhost;", $dbuser, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "CREATE DATABASE IF NOT EXISTS $dbname";
$db->exec($sql);
$sql = "use $dbname";
$db->exec($sql);
} catch (Exception $ex) {
//print_r($ex);
}
mysql_close($link);
$dumpSettings = array(
'add-drop-table' => true,
'add-drop-database' => true,
......@@ -198,18 +225,18 @@ class project_setup {
exec("mysql -u $dbuser -p{$pass} $dbname < $dumpfile"); //yep it's super sketch
$db = new PDO("mysql:host=localhost;dbname=$dbname", $dbuser, $pass);
switch (strtolower($this->project->type['name'])) {
case 'magento':
$siteurl = 'http://' . $this->project->domain . '/';
$tableprefix = $this->project->remote_db_prefix;
$sql = "UPDATE {$tableprefix}core_config_data SET value = '$siteurl' WHERE path IN ('web/unsecure/base_url','web/secure/base_url');
SET FOREIGN_KEY_CHECKS=0;
UPDATE {$tableprefix}core_store SET store_id = 0 WHERE code='admin';
UPDATE {$tableprefix}core_store_group SET group_id = 0 WHERE name='Default';
UPDATE {$tableprefix}core_website SET website_id = 0 WHERE code='admin';
UPDATE {$tableprefix}customer_group SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;";
SET FOREIGN_KEY_CHECKS=0;
UPDATE {$tableprefix}core_store SET store_id = 0 WHERE code='admin';
UPDATE {$tableprefix}core_store_group SET group_id = 0 WHERE name='Default';
UPDATE {$tableprefix}core_website SET website_id = 0 WHERE code='admin';
UPDATE {$tableprefix}customer_group SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;";
// there is no point in guarding against sql injection here
// since the whole point is that you can run any sql commands you want on local db
$db->prepare($sql)->execute();
......@@ -230,7 +257,7 @@ class project_setup {
break;
case 'basesite':
$sql = "UPDATE site_settings SET has_certificate = 0 WHERE id=1;
UPDATE site_pages SET enable_ssl = 0";
UPDATE site_pages SET enable_ssl = 0";
// there is no point in guarding against sql injection here
// since the whole point is that you can run any sql commands you want on local db
$db->prepare($sql)->execute();
......
......@@ -43,6 +43,9 @@ class projects extends module {
case 'updateComposer':
die(json_encode($this->updateComposer($_GET['id'])));
break;
case 'updateComposerModules':
die(json_encode($this->updateComposerModules($_GET['id'])));
break;
case 'buildModman':
die(json_encode($this->buildModman($_GET['id'])));
break;
......@@ -89,6 +92,17 @@ class projects extends module {
}
return array('success' => 1, 'msg' => 'Composer Updated Successfully.');
}
protected function updateComposerModules($id) {
$project = new project();
$project->load(array('id' => $id));
if ($project->exists()) {
$project_setup = new project_setup();
$project_setup->setProject($project);
$project_setup->updateComposerModules();
}
return array('success' => 1, 'msg' => 'Composer Updated Successfully.');
}
protected function resyncDb($id) {
$project = new project();
......
......@@ -18,15 +18,18 @@
</section>
<section id="actions" class="col-xs-6">
<h3><i class="fa fa-cog"></i> Ops</h3>
<ul class="ops-actions">
<li><a class="btn btn-info projectAction" data-action="resyncDb" href="#">Resync DB</a></li>
<div class="list-group">
<a class="list-group-item list-group-item-info text-center projectAction" data-action="resyncDb" href="#">Resync Database</a>
<?php if (file_exists($project->type['path'] . '/' . $project->folder . '/composer.json')) { ?>
<li><a class="btn btn-info projectAction" data-action="updateComposer" href="#">Update Composer</a></li>
<a class="list-group-item list-group-item-info text-center updateComposer" data-action="updateComposer" href="#">Update Composer</a>
<?php if (strtolower($project->type['name']) == 'magento') { ?>
<a class="list-group-item list-group-item-info text-center updateComposer" data-action="updateComposerModules" href="#">Redeploy Modules</a>
<?php } ?>
<?php } ?>
<?php if (is_dir($project->type['path'] . '/' . $project->folder . '/src') && file_exists($project->type['path'] . '/' . $project->folder . '/src/buildModman.php')): ?>
<li><a class="btn btn-info projectAction" data-action="buildModman" href="#">Run Build Modman</a></li>
<a class="list-group-item list-group-item-info text-center projectAction" data-action="buildModman" href="#">Run Build Modman</a>
<?php endif; ?>
</ul>
</div>
</section>
</div>
<!-- Update DB Info Modal -->
......@@ -73,6 +76,29 @@
</div>
</div>
</div>
<!-- Terminal Output Modal -->
<div class="modal fade" id="terminalOutputModal" tabindex="-1" role="dialog" aria-labelledby="Terminal Output" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Terminal Output</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="margin-top: -31px; font-size: 46px;">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div id="terminal-output">
</div>
</div>
<div class="clearfix"></div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(function () {
$('.projectAction').click(function () {
......@@ -85,6 +111,13 @@
});
});
$('.updateComposer').click(function () {
var project_action = $(this).data('action');
$('#terminalOutputModal .modal-title').text('Terminal Output (' + project_action + ')');
$('#terminal-output').html('<iframe style="width:100%;" src="' + document.URL.replace('#', '') + '?action=' + project_action + '&id=<?php echo $project->id; ?>"></iframe>');
$('#terminalOutputModal').modal('show');
});
$('.updateDbInfo').click(function () {
$('#updateDbInfoFrm').parent('.modal-body').bload({'overlay': {'show': true}}, function (bload) {
$.get(document.URL, $('#updateDbInfoFrm').serialize(), function (response) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment