Skip to content

Commit

Permalink
Implement "Rehash all" button TechnicPack#289
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoan committed Mar 22, 2015
1 parent 5bafd63 commit 2ca783b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/controllers/ModController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
19 changes: 19 additions & 0 deletions app/views/mod/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right">
<a href="#" class="btn btn-xs btn-success rehash">Rehash All</a>
<a href="{{ URL::to('mod/create') }}" class="btn btn-xs btn-success">Add Mod</a>
</div>
Mod List
</div>
<div class="panel-body">
<div class="alert alert-success" id="success-ajax" style="width: 100%;display: none"></div>
<div class="alert alert-danger" id="danger-ajax" style="width: 100%;display: none"></div>
@if (Session::has('success'))
<div class="alert alert-success">
{{ Session::get('success') }}
Expand Down Expand Up @@ -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();
}
});
});
</script>
@endsection

0 comments on commit 2ca783b

Please sign in to comment.