cleaner service

master
Константин 2023-09-07 10:59:34 +03:00
parent 6fdca191e0
commit e69b219e32
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace App\Services\Registries;
use App\Models\Publications\Publication;
use App\Models\Registries\Entry;
use Illuminate\Support\Str;
class CleanerService {
public function __construct() {
}
public function clean() {
$this->cleanPublications();
$this->cleanRegistryEntries();
}
public function cleanPublications() {
$items = Publication::all();
foreach ($items as $item) {
$item->update(['name' => $this->cleanString($item->name), 'excerpt' => $this->cleanString($item->excerpt)]);
}
}
public function cleanRegistryEntries() {
$items = Entry::all();
foreach ($items as $item) {
$item->update(['name' => $this->cleanString($item->name)]);
}
}
public function cleanString(string $string): string {
$string = Str::replace('&quot;', '"', $string);
$string = Str::replace('&#40', '«', $string);
$string = Str::replace('&#41', '»', $string);
return trim(Str::replace('(***)', '', $string));
}
}

View File

@ -28,6 +28,11 @@ Artisan::command('dev:generate-personal-token {userId}', function ($userId) {
})->describe('Generates a personal access token for a user');
Artisan::command('cleaner:clean', function() {
});
Artisan::command('htmlparser:import-rulesets', function() {
$registry = Registry::query()->where(['type' => RegistryType::RULESET])->first();