* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ namespace Pterodactyl\Repositories\ServiceRepository; use DB; use Validator; use Pterodactyl\Models; use Pterodactyl\Services\UuidService; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayValidationException; class Variable { public function __construct() { // } public function update($id, array $data) { $variable = Models\ServiceVariables::findOrFail($id); $validator = Validator::make($data, [ 'name' => 'sometimes|required|string|min:1|max:255', 'description' => 'sometimes|required|string', 'env_variable' => 'sometimes|required|regex:/^[\w]{1,255}$/', 'default_value' => 'sometimes|required|string', 'user_viewable' => 'sometimes|required|numeric|size:1', 'user_editable' => 'sometimes|required|numeric|size:1', 'required' => 'sometimes|required|numeric|size:1', 'regex' => 'sometimes|required|string|min:1' ]); if ($validator->fails()) { throw new DisplayValidationException($validator->errors()); } $data['default_value'] = (isset($data['default_value'])) ? $data['default_value'] : $variable->default_value; $data['regex'] = (isset($data['regex'])) ? $data['regex'] : $variable->regex; if (!preg_match($data['regex'], $data['default_value'])) { throw new DisplayException('The default value you entered cannot violate the regex requirements.'); } $data['user_viewable'] = (isset($data['user_viewable']) && in_array((int) $data['user_viewable'], [0, 1])) ? $data['user_viewable'] : $variable->user_viewable; $data['user_editable'] = (isset($data['user_editable']) && in_array((int) $data['user_editable'], [0, 1])) ? $data['user_editable'] : $variable->user_editable; $data['required'] = (isset($data['required']) && in_array((int) $data['required'], [0, 1])) ? $data['required'] : $variable->required; $variable->fill($data); $variable->save(); } }