mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
Fixes #3702 - Added artisan command to walk through special characters and unescape them in the DB
This commit is contained in:
parent
a49fd16916
commit
eb94c4333d
78
app/Console/Commands/FixDoubleEscape.php
Normal file
78
app/Console/Commands/FixDoubleEscape.php
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class FixDoubleEscape extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'snipeit:unescape';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'This should be run to fix some double-escaping issues from earlier versions of Snipe-IT.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
$tables = [
|
||||||
|
'\App\Models\Asset' => ['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');
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ class Kernel extends ConsoleKernel
|
||||||
Commands\DisableLDAP::class,
|
Commands\DisableLDAP::class,
|
||||||
Commands\Purge::class,
|
Commands\Purge::class,
|
||||||
Commands\LdapSync::class,
|
Commands\LdapSync::class,
|
||||||
|
Commands\FixDoubleEscape::class
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue