From 2ca783b4d7cadd6394ebb53188d6cc99eaca1046 Mon Sep 17 00:00:00 2001 From: Jkoan Date: Sun, 22 Mar 2015 15:57:49 +0100 Subject: [PATCH] Implement "Rehash all" button #289 --- app/controllers/ModController.php | 26 +++++++++++++++++++++++++- app/views/mod/list.blade.php | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/controllers/ModController.php b/app/controllers/ModController.php index d828aa66..c969ee68 100644 --- a/app/controllers/ModController.php +++ b/app/controllers/ModController.php @@ -235,7 +235,31 @@ public function getDeleteVersion($ver_id = null) return App::abort(404); } - + + public function getRehashall() + { + if (Request::ajax()){ + $mods = Mod::all(); + foreach ($mods as $i => $mod_info) { + $mod = Mod::find($mod_info['id']); + $mod_versions = $mod->versions()->get(); + foreach ($mod_versions as $mod_version) { + $ver = Modversion::find($mod_version['id']); + if (empty($ver)){ + return; + } + if ($md5 = $this->mod_md5($ver->mod,$ver->version)) + { + $ver->md5 = $md5; + $ver->save(); + } + } + } + return Response::json(array('status' => 'success',)); + } + return App::abort(404); + } + private function mod_md5($mod, $version) { $location = Config::get('solder.repo_location').'mods/'.$mod->name.'/'.$mod->name.'-'.$version.'.zip'; diff --git a/app/views/mod/list.blade.php b/app/views/mod/list.blade.php index 771835c3..16c6b131 100644 --- a/app/views/mod/list.blade.php +++ b/app/views/mod/list.blade.php @@ -6,11 +6,14 @@
Mod List
+ + @if (Session::has('success'))
{{ Session::get('success') }} @@ -59,5 +62,21 @@ }); }); + +$('.rehash').click(function(e) { + e.preventDefault(); + $.ajax({ + type: "GET", + url: "{{ URL::to('mod/rehashall/') }}/", + success: function (data) { + if (data.status == "success") { + $("#success-ajax").stop(true, true).html('Rehashing complete.').fadeIn().delay(3000).fadeOut(); + } + }, + error: function (xhr, textStatus, errorThrown) { + $("#danger-ajax").stop(true, true).html(textStatus + ': ' + errorThrown).fadeIn().delay(3000).fadeOut(); + } + }); +}); @endsection \ No newline at end of file