/** * Update already existing theme. * * @param ThemeModel $theme * @param array $data * * @return ThemeModel */ public function update(ThemeModel $theme, array $data) { if (!empty($data)) { $old = json_decode($theme->modified_vars, true); //merge newly changed vars and the ones saved in database $m = array_merge(is_array($old) ? $old : array(), $data['vars']); $css = $this->less->parse('bootstrap', $m, $data['custom']); if ($theme->name != $data['name']) { $this->fs->remove('themes/' . $theme->name); } $theme->modified_vars = json_encode($m); $theme->name = $data['name']; $theme->type = $data['type']; $theme->path = $this->saveStylesheet($theme->name, $css); $theme->custom_less = $data['custom']; $theme->save(); } return $theme; }