From 45f325a0fa6b6078a0301ee559eb88af7e2fa0e0 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sun, 13 May 2018 12:39:10 +0200 Subject: [PATCH] Admin/WeightPresets * removed redundant code * fixed empty scales not being written to dataset as expected --- includes/ajaxHandler/admin.class.php | 41 +++------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/includes/ajaxHandler/admin.class.php b/includes/ajaxHandler/admin.class.php index 93982ccd..0e12877e 100644 --- a/includes/ajaxHandler/admin.class.php +++ b/includes/ajaxHandler/admin.class.php @@ -349,26 +349,6 @@ class AjaxAdmin extends AjaxHandler 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']); @@ -388,23 +368,10 @@ class AjaxAdmin extends AjaxHandler // 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