From fb549d158966a0354f6a42d38d8c76602631e6d8 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 30 Jan 2025 13:01:04 +0100 Subject: [PATCH] wip #7291 @0.5 --- .../Tools/ImportFluidbookSettings.php | 98 ++++++++++--------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/Tools/ImportFluidbookSettings.php b/app/Http/Controllers/Admin/Operations/Tools/ImportFluidbookSettings.php index 285f01e1e..2b577eae6 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/ImportFluidbookSettings.php +++ b/app/Http/Controllers/Admin/Operations/Tools/ImportFluidbookSettings.php @@ -7,6 +7,7 @@ use App\Models\FluidbookPublication; use Cubist\Backpack\Magic\Fields\StandardFile; use Cubist\Backpack\Magic\Form; use Cubist\Excel\ExcelToArray; +use Cubist\Util\ArrayUtil; use Illuminate\Support\Facades\Date; use Prologue\Alerts\Facades\Alert; @@ -45,63 +46,68 @@ trait ImportFluidbookSettings $fields = $instance->getFields(); foreach ($ids as $id) { - try { - $f = FluidbookPublication::find($id); - } catch (\Exception $e) { - return redirect()->back()->with('error', 'Fluidbook id not found'); - } + $e = ArrayUtil::parseRange($id); + foreach ($e as $i) { + $i = trim($i); + + try { + $f = FluidbookPublication::find($i); + } catch (\Exception $e) { + return redirect()->back()->with('error', 'Fluidbook id not found'); + } - $settings = array_map(function ($n) { - return $n; - }, json_decode($f->settings, true)); + $settings = array_map(function ($n) { + return $n; + }, json_decode($f->settings, true)); - $sett = array_filter($res[$id], function ($v, $k) use ($settings) { - return array_key_exists($k, $settings); - }, ARRAY_FILTER_USE_BOTH); + $sett = array_filter($res[$id], function ($v, $k) use ($settings) { + return array_key_exists($k, $settings); + }, ARRAY_FILTER_USE_BOTH); - $diff = array_diff_key($res[$id], $settings); - $diff['settings'] = array_merge(json_decode($f->settings, true), $sett); + $diff = array_diff_key($res[$id], $settings); + $diff['settings'] = array_merge(json_decode($f->settings, true), $sett); - /* - * - * Format data - * - * */ - foreach ($diff as $k => &$value) { - if (!in_array($k, ['export_data', 'settings'])) { - $decode = json_decode($value, true); - if (is_array($decode)) { - $value = $decode; + /* + * + * Format data + * + * */ + foreach ($diff as $k => &$value) { + if (!in_array($k, ['export_data', 'settings'])) { + $decode = json_decode($value, true); + if (is_array($decode)) { + $value = $decode; + } } - } - if (array_key_exists($k, $fields)) { - if ($fields[$k]->getDatabaseType() === "boolean") { - $value = (bool)$value; + if (array_key_exists($k, $fields)) { + if ($fields[$k]->getDatabaseType() === "boolean") { + $value = (bool)$value; + } } } - } - /** - * - * Updated date - * - */ - $updated_at = Date::createFromDate()->toIso8601ZuluString(); - $diff['updated_at'] = $updated_at; - - /** - * - * Update data - * - */ - try { - $f->update($diff); - $f->save(); - } catch (\Exception $e) { - return redirect()->back()->with('error', 'An error occurred during the update'); + /** + * + * Updated date + * + */ + $updated_at = Date::createFromDate()->toIso8601ZuluString(); + $diff['updated_at'] = $updated_at; + + /** + * + * Update data + * + */ + try { + $f->update($diff); + $f->save(); + } catch (\Exception $e) { + return redirect()->back()->with('error', 'An error occurred during the update'); + } } } -- 2.39.5