REL-0.12 Speed up frontpage by using Ajax requests

This commit is contained in:
cytopia 2017-10-02 12:42:29 +02:00
parent 20383fee48
commit 3990d2de71
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2
3 changed files with 137 additions and 19 deletions

View File

@ -3,12 +3,17 @@ require '../config.php';
if (loadClass('Helper')->isLoggedIn()) {
//
// ?database=
//
if (isset($_GET['database'])) {
// &type=mysql
if (isset($_GET['type']) && $_GET['type'] == 'mysql') {
echo json_encode(array(
'size' => (string)loadClass('Mysql')->getDBSize($_GET['database']),
'table' => (string)loadClass('Mysql')->getTableCount($_GET['database'])
));
// &type=postgres
} else if (isset($_GET['type']) && $_GET['type'] == 'postgres') {
$schema = isset($_GET['schema']) ? $_GET['schema'] : '';
echo json_encode(array(
@ -16,12 +21,93 @@ if (loadClass('Helper')->isLoggedIn()) {
'table' => (string)loadClass('Pgsql')->getTableCount($_GET['database'], $schema)
));
}
} else if (isset($_GET['vhost'])) {
echo loadClass('Httpd')->checkVirtualHost($_GET['vhost']);
} else {
loadClass('Helper')->redirect('/');
}
} else {
//
// ?vhost=
//
else if (isset($_GET['vhost'])) {
echo loadClass('Httpd')->checkVirtualHost($_GET['vhost']);
}
//
// ?software=
//
else if (isset($_GET['software'])) {
$no = '<span class="text-danger">not installed</span>';
$software = array();
if ($_GET['software'] == 'composer') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getComposerVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'drupalc') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getDrupalConsoleVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'drush') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getDrushVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'git') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getGitVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'laravel') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getLaravelVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'mds') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getMdsVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'node') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getNodeVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'npm') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getNpmVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'phalcon') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getPhalconVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'symfony') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getPhalconVersion()) !== false) ? $version : $no
));
}
else if ($_GET['software'] == 'wpcli') {
echo json_encode(array(
$_GET['software'] => (($version = loadClass('Php')->getSymfonyVersion()) !== false) ? $version : $no
));
} else {
echo json_encode(array($_GET['software'] => 'unknown software'));
}
}
//
// WRONG REQUEST
//
else {
loadClass('Helper')->redirect('/');
}
}
//
// Not logged in
//
else {
loadClass('Helper')->redirect('/');
}

View File

@ -30,6 +30,7 @@ $connection = array();
$error = null;
// ---- HTTPD (required) ----
$host = $GLOBALS['HTTPD_HOST_NAME'];
$succ = loadClass('Httpd')->canConnect($error, $host);
$connection['Httpd'][$host] = array(
@ -51,7 +52,6 @@ $connection['Httpd'][$host] = array(
'host' => $host,
'succ' => $succ
);
// ---- MYSQL ----
if ($avail_mysql) {
$host = $GLOBALS['MYSQL_HOST_NAME'];
@ -127,6 +127,7 @@ if ($avail_redis) {
);
}
// ---- MEMCACHED ----
if ($avail_memcd) {
$host = $GLOBALS['MEMCD_HOST_NAME'];
@ -417,47 +418,47 @@ $HEALTH_PERCENT = 100 - ceil(100 * $HEALTH_FAILS / $HEALTH_TOTAL);
<tbody>
<tr>
<th>composer</th>
<td><?php if (($version = loadClass('Php')->getComposerVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_composer"></td>
</tr>
<tr>
<th>drupal-console</th>
<td><?php if (($version = loadClass('Php')->getDrushConsoleVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_drupalc"></td>
</tr>
<tr>
<th>drush</th>
<td><?php if (($version = loadClass('Php')->getDrushVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_drush"></td>
</tr>
<tr>
<th>git</th>
<td><?php if (($version = loadClass('Php')->getGitVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_git"></td>
</tr>
<tr>
<th>Laravell installer</th>
<td><?php if (($version = loadClass('Php')->getLaravelVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<th>Laravel installer</th>
<td id="app_laravel"></td>
</tr>
<tr>
<th>mysqldump-secure</th>
<td><?php if (($version = loadClass('Php')->getMdsVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_mds"></td>
</tr>
<tr>
<th>node</th>
<td><?php if (($version = loadClass('Php')->getNodeVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_node"></td>
</tr>
<tr>
<th>npm</th>
<td><?php if (($version = loadClass('Php')->getNpmVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_npm"></td>
</tr>
<tr>
<th>Phalcon devtools</th>
<td><?php if (($version = loadClass('Php')->getPhalconVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_phalcon"></td>
</tr>
<tr>
<th>Symfony installer</th>
<td><?php if (($version = loadClass('Php')->getSymfonyVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_symfony"></td>
</tr>
<tr>
<th>Wordpress cli</th>
<td><?php if (($version = loadClass('Php')->getWpcliVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td>
<td id="app_wpcli"></td>
</tr>
</tbody>
</table>
@ -910,6 +911,37 @@ $HEALTH_PERCENT = 100 - ceil(100 * $HEALTH_FAILS / $HEALTH_TOTAL);
(function() {
// your page initialization code here
// the DOM will be available here
/**
* Update installed tool versions.
* Ajax method is faster for loading the front page
* @param string app Name of the tool
*/
function updateVersions(app) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
var elem = document.getElementById('app_'+app);
if (this.readyState == 4 && this.status == 200) {
json = JSON.parse(this.responseText);
elem.innerHTML = json[app];
}
};
xhttp.open('GET', '_ajax_callback.php?software='+app, true);
xhttp.send();
}
updateVersions('composer');
updateVersions('drupalc');
updateVersions('drush');
updateVersions('git');
updateVersions('laravel');
updateVersions('mds');
updateVersions('node');
updateVersions('npm');
updateVersions('phalcon');
updateVersions('symfony');
updateVersions('wpcli');
})();
</script>
</body>

View File

@ -50,7 +50,7 @@ class Php extends BaseClass implements BaseInterface
$output = loadClass('Helper')->exec('drush --version', $output);
return loadClass('Helper')->egrep('/[0-9.]+/', $output);
}
public function getDrushConsoleVersion()
public function getDrupalConsoleVersion()
{
$output = loadClass('Helper')->exec('drupal --version | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"', $output);
return loadClass('Helper')->egrep('/[0-9.]+[-rc0-9.]*/', $output);