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

Added the ability to clone modpacks entirely. #470

Open
wants to merge 2 commits into
base: dev
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
59 changes: 59 additions & 0 deletions app/controllers/ModpackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,65 @@ public function postAddBuild($modpack_id)
return Redirect::to('modpack/build/'.$build->id);
}

public function getClone()
{
$modpacks = Modpack::all();
return View::make('modpack.clone')->with('modpacks', $modpacks);
}

public function postClone()
{
$rules = array(
'source' => 'required|exists:modpacks,slug',
'destination' => 'required|different:source'
);

$messages = array(
'source.required' => 'You must enter a modpack slug',
'source.exists' => 'The :attribute modpack must exist',
'destination.required' => 'You must enter a modpack slug',
'destination.different' => 'The :attribute must not be the same as the :other'
);

$validation = Validator::make(Input::all(), $rules, $messages);
if ($validation->fails())
return Redirect::to('modpack/clone')->withErrors($validation->messages());

$source = Modpack::where('slug', '=', Input::get('source'))->first();
$source->load('builds', 'builds.modversions');
$destination = Modpack::where('slug', '=', Input::get('destination'))->first();

if(empty($destination)){
$destination = $source->replicate();
$destination->name = Input::get('destination');
$destination->slug = Str::slug(Input::get('destination'));
$destination->push();
} else {
// Destroy any existing builds for the destination modpack.
foreach($destination->builds() as $build){
foreach($build->modversions() as $modversion){
$modversion->delete();
}
$build->delete();
}
}

foreach ($source->builds as $build) {
$newBuild = $build->replicate();
$newBuild->modpack_id = $destination->id;
$newBuild->push();
foreach ($build->modversions() as $modversion){
$newModversion = $modversion->replicate();
$newModversion->build_id = $newBuild->id;
$newModversion->save();
}
$newBuild->save();
}
$destination->save();

return Redirect::to('modpack/view/'.$destination->id);
}

public function getCreate()
{
return View::make('modpack.create');
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
@endforeach
<li><a href="{{ URL::to('modpack/list') }}">Modpack List</a></li>
<li><a href="{{ URL::to('modpack/create') }}">Add Modpack</a></li>
<li><a href="{{ URL::to('modpack/clone') }}">Clone Modpack</a></li>
</ul>
<!-- /.nav-second-level -->
</li>
Expand Down
84 changes: 84 additions & 0 deletions app/views/modpack/clone.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
@extends('layouts/master')
@section('title')
<title>Clone Modpack - TechnicSolder</title>
@stop
@section('top')
<script src="{{{ asset('js/selectize.min.js') }}}"></script>
<link href="{{{ asset('css/selectize.css') }}}" rel="stylesheet">
@endsection
@section('content')
<div class="page-header">
<h1>Modpack Management</h1>
</div>
<div class="panel panel-default">
<div class="panel-heading">
Clone Modpack
</div>
<div class="panel-body">
@if ($errors->all())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{{ $error }}<br />
@endforeach
</div>
@endif
{{ Form::open() }}
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="source">Source Modpack</label>
<select class="form-control" name="source" id="source" placeholder="Select a modpack...">
<option value="">Select a modpack...</option>
@foreach($modpacks as $modpack)
<option value="{{ $modpack->slug }}">
{{ $modpack->name }}
</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="destination">Destination Modpack</label>
<select class="form-control" name="destination" id="destination" placeholder="Select a modpack...">
<option value="">Select a modpack...</option>
@foreach($modpacks as $modpack)
<option value="{{ $modpack->slug }}">
{{ $modpack->name }}
</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-6">
<p>Cloning a modpack will duplicate all of a modpack's builds and history into another modpack.</p>
<p class="alert alert-danger">If the destination modpack already exists all of its builds will be destroyed and replaced with copies of the source modpack's builds, only do this if you're certain you know what you're doing. Otherwise, create a new modpack by typing its name.</p>
<p>If you wish to link this modpack with an existing Technic Platform modpack, the slug must be identical to your slug on the Platform!</p>
</div>
</div>
{{ Form::submit('Clone Modpack', array('class' => 'btn btn-success')) }}
{{ HTML::link('modpack/list/', 'Go Back', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</div>
</div>
<script type="text/javascript">
var $select = $("#source").selectize({
persist: false,
maxItems: 1,
sortField: {
field: 'text',
direction: 'asc'
}
});
var source = $select[0].selectize;

var $select = $("#destination").selectize({
persist: false,
maxItems: 1,
create: true,
sortField: {
field: 'text',
direction: 'asc'
}
});
var destination = $select[0].selectize;
</script>
@endsection