Skip to content

Commit

Permalink
Admin/WeightPresets
Browse files Browse the repository at this point in the history
 * removed redundant code
 * fixed empty scales not being written to dataset as expected
  • Loading branch information
Sarjuuk committed May 13, 2018
1 parent 37652ce commit 45f325a
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions includes/ajaxHandler/admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,26 +349,6 @@ protected function wtSave()
if (!$this->_post['id'] || !$this->_post['__icon'])
return 3;

$writeFile = function($file, $content)
{
$success = false;
if ($handle = @fOpen($file, "w"))
{
if (fWrite($handle, $content))
$success = true;

fClose($handle);
}
else
die('me no file');

if ($success)
@chmod($file, Util::FILE_ACCESS);

return $success;
};


// save to db

DB::Aowow()->query('DELETE FROM ?_account_weightscale_data WHERE id = ?d', $this->_post['id']);
Expand All @@ -388,23 +368,10 @@ protected function wtSave()

// write dataset

$wtPresets = [];
$scales = DB::Aowow()->select('SELECT id, name, icon, class FROM ?_account_weightscales WHERE userId = 0 ORDER BY class, id ASC');

foreach ($scales as $s)
{
$weights = DB::Aowow()->selectCol('SELECT field AS ARRAY_KEY, val FROM ?_account_weightscale_data WHERE id = ?d', $s['id']);
if (!$weights)
continue;

$wtPresets[$s['class']]['pve'][$s['name']] = array_merge(['__icon' => $s['icon']], $weights);
}

$toFile = "var wt_presets = ".Util::toJSON($wtPresets).";";
$file = 'datasets/weight-presets';

if (!$writeFile($file, $toFile))
return 2;
exec('php aowow --build=weightPresets', $out);
foreach ($out as $o)
if (strstr($o, 'ERR'))
return 2;


// all done
Expand Down

0 comments on commit 45f325a

Please sign in to comment.