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

fix/upgrade degradations #241

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{block content}
{if $changes}
<div class="alert alert-info" role="alert">
<strong>Updated degredations:</strong>
<strong>Updated degradations:</strong>
<ul>
{foreach item=value key=key from=$changes}
<li>{$key|escape}: {tif $value ? 'on' : 'off'}</li>
Expand All @@ -13,14 +13,14 @@
{/if}

<form method="POST" class="card">
<div class="card-header">Configured degredations</div>
<div class="card-header">Configured degradations</div>

<div class="card-body">
{foreach item=value key=key from=$degredations}
<input type="hidden" name="degredations[{$key|escape}]" value="off">
{foreach item=value key=key from=$degradations}
<input type="hidden" name="degradations[{$key|escape}]" value="off">
<div class="checkbox">
<label>
<input type="checkbox" name="degredations[{$key|escape}]" value="on" {tif $value ? checked}>
<input type="checkbox" name="degradations[{$key|escape}]" value="on" {tif $value ? checked}>
{$key|escape}
</label>
</div>
Expand All @@ -30,7 +30,7 @@
<input type="text" placeholder="new-key" name="enable[]">
</div>

<button type="submit" class="btn btn-primary">Apply Degredations</button>
<button type="submit" class="btn btn-primary">Apply Degradations</button>
</div>
</form>
{/block}
2 changes: 1 addition & 1 deletion php-classes/Emergence/Dwoo/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected function initRuntimeVars(\Dwoo_ITemplate $tpl)
// set site information
$this->globals['Site'] = array(
'title' => Site::$title
,'degredations' => Site::getConfig('degredations')
,'degradations' => Site::getConfig('degradations')
);

// add magic globals
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

return [
'title' => 'Manage Degredations',
'title' => 'Manage Degradations',
'description' => 'Enable or disable degredation flags that can be used to reduce the functionality of sites live while under failure or high load',
'icon' => 'power-off',
'handler' => function () {
$config = Site::getConfig();
$degredations = !empty($config['degredations']) ? $config['degredations'] : [];
$degradations = !empty($config['degradations']) ? $config['degradations'] : [];
$changes = [];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

// parse degredation changes from request input
if (!empty($_POST['degredations']) && is_array($_POST['degredations'])) {
foreach ($_POST['degredations'] AS $key => $value) {
if (!empty($_POST['degradations']) && is_array($_POST['degradations'])) {
foreach ($_POST['degradations'] AS $key => $value) {
if ($key && is_string($key)) {
$changes[$key] = $value == 'on';
}
Expand All @@ -37,26 +37,26 @@
}


// apply degredations
// apply degradations
if (count($changes)) {
foreach ($changes AS $key => $value) {
if (isset($degredations[$key]) && $degredations[$key] == $value) {
if (isset($degradations[$key]) && $degradations[$key] == $value) {
unset($changes[$key]);
continue;
}

$degredations[$key] = $value;
$degradations[$key] = $value;
}

$config['degredations'] = $degredations;
$config['degradations'] = $degradations;

// update cached site config
Cache::rawStore(Site::$rootPath, $config);
}
}
return static::respond('degredations', [
'degredations' => $degredations,

return static::respond('degradations', [
'degradations' => $degradations,
'changes' => $changes
]);
}
Expand Down