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()) { if (loadClass('Helper')->isLoggedIn()) {
//
// ?database=
//
if (isset($_GET['database'])) { if (isset($_GET['database'])) {
// &type=mysql
if (isset($_GET['type']) && $_GET['type'] == 'mysql') { if (isset($_GET['type']) && $_GET['type'] == 'mysql') {
echo json_encode(array( echo json_encode(array(
'size' => (string)loadClass('Mysql')->getDBSize($_GET['database']), 'size' => (string)loadClass('Mysql')->getDBSize($_GET['database']),
'table' => (string)loadClass('Mysql')->getTableCount($_GET['database']) 'table' => (string)loadClass('Mysql')->getTableCount($_GET['database'])
)); ));
// &type=postgres
} else if (isset($_GET['type']) && $_GET['type'] == 'postgres') { } else if (isset($_GET['type']) && $_GET['type'] == 'postgres') {
$schema = isset($_GET['schema']) ? $_GET['schema'] : ''; $schema = isset($_GET['schema']) ? $_GET['schema'] : '';
echo json_encode(array( echo json_encode(array(
@ -16,12 +21,93 @@ if (loadClass('Helper')->isLoggedIn()) {
'table' => (string)loadClass('Pgsql')->getTableCount($_GET['database'], $schema) '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('/'); loadClass('Helper')->redirect('/');
} }

View File

@ -30,6 +30,7 @@ $connection = array();
$error = null; $error = null;
// ---- HTTPD (required) ---- // ---- HTTPD (required) ----
$host = $GLOBALS['HTTPD_HOST_NAME']; $host = $GLOBALS['HTTPD_HOST_NAME'];
$succ = loadClass('Httpd')->canConnect($error, $host); $succ = loadClass('Httpd')->canConnect($error, $host);
$connection['Httpd'][$host] = array( $connection['Httpd'][$host] = array(
@ -51,7 +52,6 @@ $connection['Httpd'][$host] = array(
'host' => $host, 'host' => $host,
'succ' => $succ 'succ' => $succ
); );
// ---- MYSQL ---- // ---- MYSQL ----
if ($avail_mysql) { if ($avail_mysql) {
$host = $GLOBALS['MYSQL_HOST_NAME']; $host = $GLOBALS['MYSQL_HOST_NAME'];
@ -127,6 +127,7 @@ if ($avail_redis) {
); );
} }
// ---- MEMCACHED ---- // ---- MEMCACHED ----
if ($avail_memcd) { if ($avail_memcd) {
$host = $GLOBALS['MEMCD_HOST_NAME']; $host = $GLOBALS['MEMCD_HOST_NAME'];
@ -417,47 +418,47 @@ $HEALTH_PERCENT = 100 - ceil(100 * $HEALTH_FAILS / $HEALTH_TOTAL);
<tbody> <tbody>
<tr> <tr>
<th>composer</th> <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>
<tr> <tr>
<th>drupal-console</th> <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>
<tr> <tr>
<th>drush</th> <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>
<tr> <tr>
<th>git</th> <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>
<tr> <tr>
<th>Laravell installer</th> <th>Laravel installer</th>
<td><?php if (($version = loadClass('Php')->getLaravelVersion()) === false) {echo '<span class="text-danger">not installed</span>';}else{echo $version;}; ?></td> <td id="app_laravel"></td>
</tr> </tr>
<tr> <tr>
<th>mysqldump-secure</th> <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>
<tr> <tr>
<th>node</th> <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>
<tr> <tr>
<th>npm</th> <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>
<tr> <tr>
<th>Phalcon devtools</th> <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>
<tr> <tr>
<th>Symfony installer</th> <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>
<tr> <tr>
<th>Wordpress cli</th> <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> </tr>
</tbody> </tbody>
</table> </table>
@ -910,6 +911,37 @@ $HEALTH_PERCENT = 100 - ceil(100 * $HEALTH_FAILS / $HEALTH_TOTAL);
(function() { (function() {
// your page initialization code here // your page initialization code here
// the DOM will be available 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> </script>
</body> </body>

View File

@ -50,7 +50,7 @@ class Php extends BaseClass implements BaseInterface
$output = loadClass('Helper')->exec('drush --version', $output); $output = loadClass('Helper')->exec('drush --version', $output);
return loadClass('Helper')->egrep('/[0-9.]+/', $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); $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); return loadClass('Helper')->egrep('/[0-9.]+[-rc0-9.]*/', $output);