/** * Run the database seeds. * * @return void */ public function run() { DB::table('modpacks')->delete(); $testmodpack = Modpack::create(array('name' => 'TestModpack', 'slug' => 'testmodpack', 'icon' => false, 'icon_md5' => 'fb6582e4d9c9bc208181907ecc108eb1', 'icon_url' => env('SOLDER_MIRROR_URL') . 'resources/default/icon.png', 'logo' => false, 'logo_md5' => 'fb6582e4d9c9bc208181907ecc108eb1', 'logo_url' => env('SOLDER_MIRROR_URL') . 'resources/default/logo.png', 'background' => false, 'background_md5' => 'fb6582e4d9c9bc208181907ecc108eb1', 'background_url' => env('SOLDER_MIRROR_URL') . 'resources/default/background.jpg')); DB::table('builds')->delete(); $testbuild = Build::create(array('modpack_id' => $testmodpack->id, 'version' => '1.0.0', 'minecraft' => '1.7.10', 'minecraft_md5' => 'e6b7a531b95d0c172acb704d1f54d1b3', 'min_java' => '1.7', 'min_memory' => '1024', 'is_published' => true)); $testbuild->modversions()->attach(1); }
/** * Make changes to the database. * * @return void */ public function up() { Schema::table('modpacks', function ($table) { $table->boolean('hidden')->default(1); }); foreach (Modpack::all() as $modpack) { $modpack->hidden = false; $modpack->save(); } }
public function testModpackBuild() { $modpack = Modpack::find(1); $build = $modpack->builds->first(); $response = $this->call('GET', '/modpack/' . $modpack->slug . '/' . $build->version); $this->assertResponseOk(); $this->assertTrue(is_a($response, 'Illuminate\\Http\\JsonResponse')); $json = $response->getData(true); $this->assertTrue(array_key_exists('minecraft', $json)); $this->assertTrue(array_key_exists('minecraft_md5', $json)); $this->assertTrue(array_key_exists('forge', $json)); $this->assertTrue(array_key_exists('java', $json)); $this->assertTrue(array_key_exists('memory', $json)); $this->assertTrue(array_key_exists('mods', $json)); }
private function fetchBuild(Request $request, $slug, $build) { $response = array(); if (Cache::has('modpack.' . $slug) && empty($this->client) && empty($this->key)) { $modpack = Cache::Get('modpack.' . $slug); } else { $modpack = Modpack::where("slug", "=", $slug)->first(); if (empty($this->client) && empty($this->key)) { Cache::put('modpack.' . $slug, $modpack, 5); } } if (empty($modpack)) { return array("error" => "Modpack does not exist"); } $buildpass = $build; if (Cache::has('modpack.' . $slug . '.build.' . $build) && empty($this->client) && empty($this->key)) { $build = Cache::get('modpack.' . $slug . '.build.' . $build); } else { $build = Build::with('Modversions')->where("modpack_id", "=", $modpack->id)->where("version", "=", $build)->first(); if (empty($this->client) && empty($this->key)) { Cache::put('modpack.' . $slug . '.build.' . $buildpass, $build, 5); } } if (empty($build)) { return array("error" => "Build does not exist"); } $response['minecraft'] = $build->minecraft; $response['minecraft_md5'] = $build->minecraft_md5; $response['java'] = $build->min_java; $response['memory'] = $build->min_memory; $response['forge'] = $build->forge; $response['mods'] = array(); if (!$request->has('include')) { if (Cache::has('modpack.' . $slug . '.build.' . $buildpass . 'modversion') && empty($this->client) && empty($this->key)) { $response['mods'] = Cache::get('modpack.' . $slug . '.build.' . $buildpass . 'modversion'); } else { foreach ($build->modversions as $modversion) { $response['mods'][] = array("name" => $modversion->mod->name, "version" => $modversion->version, "md5" => $modversion->md5, "url" => env('SOLDER_MIRROR_URL') . 'mods/' . $modversion->mod->name . '/' . $modversion->mod->name . '-' . $modversion->version . '.zip'); } usort($response['mods'], function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); Cache::put('modpack.' . $slug . '.build.' . $buildpass . 'modversion', $response['mods'], 5); } } else { if ($request->input('include') == "mods") { if (Cache::has('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.mods') && empty($this->client) && empty($this->key)) { $response['mods'] = Cache::get('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.mods'); } else { foreach ($build->modversions as $modversion) { $response['mods'][] = array("name" => $modversion->mod->name, "version" => $modversion->version, "md5" => $modversion->md5, "pretty_name" => $modversion->mod->pretty_name, "author" => $modversion->mod->author, "description" => $modversion->mod->description, "link" => $modversion->mod->link, "donate" => $modversion->mod->donatelink, "url" => env('SOLDER_MIRROR_URL') . 'mods/' . $modversion->mod->name . '/' . $modversion->mod->name . '-' . $modversion->version . '.zip'); } usort($response['mods'], function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); Cache::put('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.mods', $response['mods'], 5); } } else { $request = explode(",", $request->input('include')); if (Cache::has('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.' . $request) && empty($this->client) && empty($this->key)) { $response['mods'] = Cache::get('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.' . $request); } else { foreach ($build->modversions as $modversion) { $data = array("name" => $modversion->mod->name, "version" => $modversion->version, "md5" => $modversion->md5); $mod = (array) $modversion->mod; $mod = $mod['attributes']; foreach ($request as $type) { if (isset($mod[$type])) { $data[$type] = $mod[$type]; } } $response['mods'][] = $data; } usort($response['mods'], function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); Cache::put('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.' . $request, $response['mods'], 5); } } } return $response; }