Helpful error if daemon isn't running
This commit is contained in:
parent
0ceb343be7
commit
983e59cd78
3 changed files with 45 additions and 9 deletions
|
@ -142,13 +142,13 @@ class LBRYPress
|
||||||
*/
|
*/
|
||||||
private function init()
|
private function init()
|
||||||
{
|
{
|
||||||
|
$this->notice = new LBRY_Admin_Notice();
|
||||||
$this->daemon = new LBRY_Daemon();
|
$this->daemon = new LBRY_Daemon();
|
||||||
$this->speech = new LBRY_Speech();
|
$this->speech = new LBRY_Speech();
|
||||||
|
|
||||||
// Admin request
|
// Admin request
|
||||||
if (is_admin()) {
|
if (is_admin()) {
|
||||||
$this->admin = new LBRY_Admin();
|
$this->admin = new LBRY_Admin();
|
||||||
$this->notice = new LBRY_Admin_Notice();
|
|
||||||
$this->network = new LBRY_Network();
|
$this->network = new LBRY_Network();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,9 @@ class LBRY_Admin_Notice
|
||||||
set_transient('lbry_notices', array($notice));
|
set_transient('lbry_notices', array($notice));
|
||||||
} else {
|
} else {
|
||||||
$notices = get_transient('lbry_notices');
|
$notices = get_transient('lbry_notices');
|
||||||
$notices[] = $notice;
|
if (!in_array($notice, $notices)) {
|
||||||
|
$notices[] = $notice;
|
||||||
|
}
|
||||||
set_transient('lbry_notices', $notices);
|
set_transient('lbry_notices', $notices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +58,15 @@ class LBRY_Admin_Notice
|
||||||
if ($notice['is_dismissible']) {
|
if ($notice['is_dismissible']) {
|
||||||
$class .= ' is-dismissible';
|
$class .= ' is-dismissible';
|
||||||
}
|
}
|
||||||
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($notice['message']));
|
ob_start();
|
||||||
|
?>
|
||||||
|
<div class="<?= $class ?>">
|
||||||
|
<p>
|
||||||
|
<span style="font-weight:bold">LBRYPress: </span>
|
||||||
|
<?= $notice['message'] ?>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
echo ob_get_clean();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,11 @@ class LBRY_Daemon
|
||||||
*/
|
*/
|
||||||
private $daemon_running = false;
|
private $daemon_running = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Daemon Notice Handler
|
||||||
|
*/
|
||||||
|
private $notice = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Daemon Logger
|
* The Daemon Logger
|
||||||
* @var LBRY_Daemon_Logger
|
* @var LBRY_Daemon_Logger
|
||||||
|
@ -30,7 +35,12 @@ class LBRY_Daemon
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->logger = new LBRY_Daemon_Logger();
|
$this->logger = new LBRY_Daemon_Logger();
|
||||||
|
$this->notice = new LBRY_Admin_Notice();
|
||||||
$this->daemon_running = $this->test_daemon();
|
$this->daemon_running = $this->test_daemon();
|
||||||
|
|
||||||
|
if (!$this->daemon_running && !$this->start_daemon()) {
|
||||||
|
$this->notice->set_notice('error', 'Cannot connect to the LBRY Daemon. Click <a href="' . admin_url('admin.php?page=lbrypress-help') . '">HERE</a> for help.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +49,22 @@ class LBRY_Daemon
|
||||||
*/
|
*/
|
||||||
private function test_daemon()
|
private function test_daemon()
|
||||||
{
|
{
|
||||||
return true;
|
try {
|
||||||
|
$result = $this->request('status')->result;
|
||||||
|
return $result->is_running;
|
||||||
|
} catch (LBRYDaemonException $e) {
|
||||||
|
$this->logger->log('daemon_status_error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to start the daemon
|
||||||
|
* @return bool True on success
|
||||||
|
*/
|
||||||
|
private function start_daemon()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +81,7 @@ class LBRY_Daemon
|
||||||
return $result->result;
|
return $result->result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('address_unused error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('address_unused error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
LBRY()->notice->set_notice('error', 'Issue getting unused address.');
|
$this->notice->set_notice('error', 'Issue getting unused address.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +106,7 @@ class LBRY_Daemon
|
||||||
return $result->result->items;
|
return $result->result->items;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
LBRY()->notice->set_notice('error', 'Issue getting address list.');
|
$this->notice->set_notice('error', 'Issue getting address list.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +126,7 @@ class LBRY_Daemon
|
||||||
return $result->result->available;
|
return $result->result->available;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('account_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('account_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
LBRY()->notice->set_notice('error', 'Issue getting account balance.');
|
$this->notice->set_notice('error', 'Issue getting account balance.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +151,7 @@ class LBRY_Daemon
|
||||||
return empty($result) ? null : $result;
|
return empty($result) ? null : $result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
LBRY()->notice->set_notice('error', 'Issue retrieving channel list.');
|
$this->notice->set_notice('error', 'Issue retrieving channel list.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +251,7 @@ class LBRY_Daemon
|
||||||
return $result->result;
|
return $result->result;
|
||||||
} catch (LBRYDaemonException $e) {
|
} catch (LBRYDaemonException $e) {
|
||||||
$this->logger->log('publish error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
$this->logger->log('publish error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||||
LBRY()->notice->set_notice('error', 'Issue publishing / updating post to LBRY Network.');
|
$this->notice->set_notice('error', 'Issue publishing / updating post to LBRY Network.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue