From eb94c4333daa6cd077c33ec9eab24a1a8cf73b4a Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 8 Jul 2017 14:47:43 -0700 Subject: [PATCH] Fixes #3702 - Added artisan command to walk through special characters and unescape them in the DB --- app/Console/Commands/FixDoubleEscape.php | 78 ++++++++++++++++++++++++ app/Console/Kernel.php | 1 + 2 files changed, 79 insertions(+) create mode 100644 app/Console/Commands/FixDoubleEscape.php diff --git a/app/Console/Commands/FixDoubleEscape.php b/app/Console/Commands/FixDoubleEscape.php new file mode 100644 index 0000000000..24f158e578 --- /dev/null +++ b/app/Console/Commands/FixDoubleEscape.php @@ -0,0 +1,78 @@ + ['name'], + '\App\Models\License' => ['name'], + '\App\Models\Consumable' => ['name'], + '\App\Models\Accessory' => ['name'], + '\App\Models\Component' => ['name'], + '\App\Models\Company' => ['name'], + '\App\Models\Location' => ['name'], + '\App\Models\User' => ['first_name', 'last_name'], + ]; + + $count = array(); + + + + foreach ($tables as $classname => $fields) { + $count[$classname] = array(); + $count[$classname]['classname'] = 0; + + foreach($fields as $field) { + + $count[$classname]['classname']++; + $count[$classname][$field] = 0; + + foreach($classname::where("$field",'LIKE','%&%')->get() as $row) { + $this->info('Updating '.$field.' for '.$classname); + $row->{$field} = html_entity_decode($row->{$field}); + $row->save(); + $count[$classname][$field]++; + + } + } + } + + $this->info('Update complete'); + + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 09741dbd1f..35385ce128 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -23,6 +23,7 @@ class Kernel extends ConsoleKernel Commands\DisableLDAP::class, Commands\Purge::class, Commands\LdapSync::class, + Commands\FixDoubleEscape::class ]; /**