Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature soap logs view #119

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
AnnotationRegistry::registerLoader([$loader, 'loadClass']);

require ACORE_PATH_PLG . "/src/boot.php";

register_activation_hook( __FILE__, 'activate_acore_wp_plugin' );
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ function acore_tools_page()
$SettingsCtrl->loadTools();
}

// mt_settings_page() displays the page content for the Test settings submenu
function acore_soap_logs_page()
{
$SettingsCtrl = new SettingsController();
$SettingsCtrl->loadSoapLogs();
}

// action function for above hook
function acore_add_pages()
{
Expand Down Expand Up @@ -101,6 +108,16 @@ function acore_add_pages()
ACORE_SLUG . '-tools',
array($this, 'acore_tools_page')
);

// Add a new submenu under Settings:
add_submenu_page(
'acore',
__('ACore Settings Panel', Opts::I()->org_alias),
__('Soap Logs', Opts::I()->org_alias),
'manage_options',
ACORE_SLUG . '-soap-logs',
array($this, 'acore_soap_logs_page')
);
}

// action function for above hook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,7 @@
</div>
</form>
</div>

<script>
jQuery('#check-soap').on('click', function(e) {
jQuery.ajax({
url: "<?php echo get_rest_url(null, 'wp-acore/v1/server-info'); ?>",
success: function(response) {
jQuery('#ajax-message').html('<div class="notice notice-info"><p>SOAP Response: <strong>' + response.message + '</strong></p></div>');
},
error: function(response) {
jQuery('#ajax-message').html('<div class="notice notice-error"><p>An unknown error happens requesting SOAP status.</div>');
},
})
});
jQuery('#eluna_recruit_a_friend').on('change', function() {
jQuery('.eluna_raf_config').toggle();
})
Helias marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@
<script>
jQuery('#check-soap').on('click', function(e) {
jQuery.ajax({
url: "<?php echo get_rest_url(null, ACORE_SLUG . '/v1/server-info'); ?>",
url: "<?= get_rest_url(null, ACORE_SLUG . '/v1/server-info'); ?>",
data: {
_wpnonce: "<?= wp_create_nonce( 'wp_rest' ); ?>"
},
success: function(response) {
jQuery('#ajax-message').html('<div class="notice notice-info"><p>SOAP Response: <strong>' + response.message + '</strong></p></div>');
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
use ACore\Manager\Opts;
// Now display the settings editing screen
$myCredConfs = get_option('mycred_pref_core');
?>

<div class="wrap">
<h2> <?= __('Soap Logs', Opts::I()->page_alias)?> </h2>
<p>A list of the logged commands.</p>
<div class="row">
<div class="col">
<div class="card p-0">
<div class="card-body">
<h5>Soap Logs</h5>
<hr>
<form class="row row-cols-lg-auto g-2" url="<?= menu_page_url(ACORE_SLUG . '-soap-logs'); ?>">
<input type="hidden" value="<?= ACORE_SLUG . '-soap-logs'; ?>" name="page">
<div class="col">
<label class="visually-hidden" for="username">Username</label>
<input type="text" class="form-control form-control-sm" id="username" name="username" placeholder="Username" value="<?= $data['username']; ?>">
</div>
<div class="col">
<label class="visually-hidden" for="order_id">Order ID</label>
<input type="text" class="form-control form-control-sm" id="order_id" name="order_id" placeholder="Order ID" value="<?= $data['order_id']; ?>">
</div>

<div class="col">
<label class="visually-hidden" for="items">Items</label>
<select class="form-select" name="items" id="items">
<option value="10">10</option>
<option value="25" <?= $data['items'] == '25' ? 'selected' : ''; ?>>25</option>
<option value="50" <?= $data['items'] == '50' ? 'selected' : ''; ?>>50</option>
<option value="100" <?= $data['items'] == '100' ? 'selected' : ''; ?>>100</option>
</select>
</div>

<div class="col">
<button type="submit" class="btn btn-primary btn-sm">Search</button>
</div>

<div class="col ms-auto">
<nav aria-label="Table pagination">
<ul class="pagination pagination-sm">
<?php
$maxPagination = 3;
$diff = $data["max_page"] - $data["pos"];
$start = ($data["pos"] - $maxPagination > 0 && $diff >= 0) ? $data["pos"] - $maxPagination : 1;
$end = ($data["pos"] + $maxPagination < $data["max_page"] && $diff > 0) ? $data["pos"] + $maxPagination : $data["max_page"];

$link = menu_page_url(ACORE_SLUG . '-soap-logs', false);
if ($data["username"]) {
$link .= "&username=" . $data["username"];
}
if ($data["order_id"]) {
$link .= "&order_id=" . $data["order_id"];
}
?>

<li class="page-item disabled">
<?php if ($data["count"] > 0): ?>
<a class="page-link">Results <?= ($data["pos"] - 1) * $data["items"] + 1; ?> to <?= $data["pos"] != $data["max_page"] ? $data["pos"] * $data["items"] : $data["count"]; ?> from <?= $data["count"]; ?> </a>
<?php else: ?>
<a class="page-link">No results </a>
<?php endif; ?>
Helias marked this conversation as resolved.
Show resolved Hide resolved
</li>

<?php
$link .= "&items=" . $data["items"];
if ($start > 1) {
echo '<li class="page-item"><a class="page-link" href="' . $link . '&pos=1">1</a></li>';
if ($maxPagination <= $start) {
echo '<li class="page-item disabled"><a class="page-link">...</a></li>';
}
}
for ($i = $start; $i <= $end; $i++) {
$href = "$link&pos=$i";
$class = "";
if ($i == $data["pos"]) {
$href = "#";
$class = " active";
}
echo '<li class="page-item' . $class . '"><a class="page-link" href="' . $href . '">' . $i . '</a></li>';
}
if ($end < $data["max_page"]) {
if ($data["max_page"] - 1 != $end) {
echo '<li class="page-item disabled"><a class="page-link">...</a></li>';
}
echo '<li class="page-item"><a class="page-link" href="' . $link . '&pos=' . $data["max_page"] . '">' . $data["max_page"] . '</a></li>';
}
?>
</ul>
</nav>
</div>

</form>
<table class="table table-bordered table-hover align-middle">
<thead>
<tr>
<th>#</th>
<th>Result</th>
<th>Details</th>
<th>Command</th>
<th>User</th>
<th>Order</th>
<th>Executed DateTime</th>
</tr>
</thead>
<tbody>
<?php
foreach ($result as $item) {
echo "<tr><td>{$item->id}</td>";
if ($item->success) {
echo '<td><span class="dashicons dashicons-yes text-success"></span></td>';
} else {
echo '<td><span class="dashicons dashicons-no text-danger"></span></td>';
}
echo "<td>{$item->result}</td>";
echo "<td>{$item->command}</td>";
$user_info = get_userdata($item->user_id);
echo '<td><a href="' . get_edit_user_link($item->user_id) . '">' . $user_info->user_login . '</a></td>';
echo "<td>{$item->order_id}</td>";
echo "<td>{$item->executed_at}</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function loadTools() {
$result = ACoreServices::I()->getServerSoap()->executeCommand("item restore list");
if (strpos($result, '.item restore list'))
$this->storeConf($key, $_POST[$key]);
else
else
print "<div class='error'><p><strong>Item restore service error: $result</strong></p></div>";
}
else {
Expand All @@ -366,14 +366,84 @@ public function loadTools() {
}

// Reload configs
$this->data = $this->loadData();
$this->data = $this->loadData();
?>
<div class="updated"><p><strong>Tools have been saved</strong></p></div>
<?php
}
echo $this->getView()->getToolsRender();
}

public function loadSoapLogs() {
# defaults
$items = 10;
$pos = 1;
$userName = null;
$orderId = null;
$from = null;
$to = null;

if (!is_admin()) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
global $wpdb;
$soapLogsTableName = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME;
$query = "SELECT
sl.*
FROM $soapLogsTableName sl";
if (isset($_GET["username"]) && !empty($_GET["username"])) {
$userName = $_GET['username'];
$query .= " INNER JOIN {$wpdb->users} u ON sl.user_id = u.ID";
$query .= " AND u.user_login LIKE '%{$wpdb->_real_escape($userName)}%'";
}
$query .= "
WHERE
1=1
";
if (isset($_GET["order_id"]) && filter_var($_GET["order_id"], FILTER_VALIDATE_INT)) {
$orderId = (int) $_GET['order_id'];
$query .= " AND sl.order_id = $orderId";
}
if (isset($_GET["from"]) && isset($_GET["to"])) {
$from = $wpdb->_real_escape($_GET['from']);
$to = $wpdb->_real_escape($_GET['to']);
$query .= " AND sl.executed_at BETWEEN '{$from}::00:00:00' AND '{$to}::23:59:59'";
}
if (isset($_GET["items"]) && in_array($_GET["items"], ["10", "25", "50", "100"])) {
$items = (int) $_GET['items'];
}
if (isset($_GET["pos"])) {
$pos = (int) $_GET['pos'];
if ($pos <= 0) {
$pos = 1;
}
}

$count = $wpdb->get_col("SELECT count(0) FROM ($query) total");

$offset = ($pos - 1) * $items;
$query .= " ORDER BY id DESC LIMIT $items OFFSET $offset";

$result = $wpdb->get_results($query);
$maxPage = ceil((int) $count[0] / $items);

$data = [
'username' => $userName,
'order_id' => $orderId,
'from' => $from,
'to' => $to,
'items' => $items,
'pos' => $pos,
'count' => (int) $count[0],
'max_page' => $maxPage,
];

echo $this->getView()->getSoapLogsRender(
$data,
$result
);
}


public function storeConf($conf, $value) {
update_option($conf, $value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function getToolsRender() {
return $this->loadPageLayout('Tools');
}

public function getSoapLogsRender($data, $result) {
return $this->loadPageLayout('SoapLogs', ['data' => $data, 'result' => $result]);
}

private function loadPageLayout($pageName, $varExtract=null) {
wp_enqueue_style('bootstrap-css', '//cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css', array(), '5.1.3');
wp_enqueue_style('acore-css', ACORE_URL_PLG . 'web/assets/css/main.css', array(), '0.1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function ItemRestoreList($request) {
public static function ItemRestore($data) {
$item = $data['item'];
$cname = $data['cname'];
return ACoreServices::I()->getServerSoap()->executeCommand("item restore $item $cname");
return ACoreServices::I()->getServerSoap()->executeCommand("item restore $item $cname", true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function showRafProgress() {
if ($res instanceof \Exception) {
$errorMessages[] = "The server seems to be offline, try again later!";
} else {
$res = $soap->executeCommand("bindraf $newRecruitId $recruiterCode");
$res = $soap->executeCommand("bindraf $newRecruitId $recruiterCode", true);
if ($res instanceof \Exception) {
$errorMessages[] = "An error ocurred while binding accounts. Please try again later.";
}
Expand Down Expand Up @@ -129,7 +129,6 @@ public function showRafProgress() {

public function showItemRestorationPage() {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->saveCharacterOrder();
?>
<div class="updated"><p><strong>Character settings succesfully saved.</strong></p></div>
<?php
Expand Down
Loading