/** * Download a remote theme */ public function download() { App::response()->setContentType('json'); try { $api = new HawkApi(); $file = $api->downloadTheme($this->theme); $zip = new \ZipArchive(); if ($zip->open($file) !== true) { throw new \Exception('Impossible to open the zip archive'); } $zip->extractTo(THEMES_DIR); $theme = Theme::get($this->theme); if (!$theme) { throw new \Exception('An error occured while downloading the theme'); } unlink($file); return $theme; } catch (\Exception $e) { App::response()->setStatus(500); return array('message' => $e->getMessage()); } }