From d8fb4da0c6575f5efa1fad9477731218bdd2e65d Mon Sep 17 00:00:00 2001 From: Nicolas Perrenoud Date: Sun, 3 Sep 2023 13:04:13 +0200 Subject: [PATCH] Fix code --- app/Console/Commands/AnonymizeVisitors.php | 3 ++- .../Accounting/API/BudgetController.php | 5 +---- .../Accounting/API/SuppliersController.php | 7 +++---- .../API/CommunityVolunteerController.php | 5 ++--- .../ImportExportController.php | 5 +---- app/Models/Fundraising/Donor.php | 15 +++++++-------- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/app/Console/Commands/AnonymizeVisitors.php b/app/Console/Commands/AnonymizeVisitors.php index a6458bec6..5fcf9c460 100644 --- a/app/Console/Commands/AnonymizeVisitors.php +++ b/app/Console/Commands/AnonymizeVisitors.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Models\Visitors\Visitor; +use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Log; @@ -43,7 +44,7 @@ public function handle() $visitor->id_number = sha1($visitor->id_number); } if ($visitor->date_of_birth !== null) { - $visitor->date_of_birth = $visitor->date_of_birth->startOfYear(); + $visitor->date_of_birth = (new Carbon($visitor->date_of_birth))->startOfYear(); } $visitor->anonymized = true; $visitor->save(); diff --git a/app/Http/Controllers/Accounting/API/BudgetController.php b/app/Http/Controllers/Accounting/API/BudgetController.php index 8432edcaa..fe23006c7 100644 --- a/app/Http/Controllers/Accounting/API/BudgetController.php +++ b/app/Http/Controllers/Accounting/API/BudgetController.php @@ -19,7 +19,6 @@ use Illuminate\Http\Response; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Storage; -use ZipStream\Option\Archive; use ZipStream\ZipStream; class BudgetController extends Controller @@ -137,9 +136,7 @@ public function export(Budget $budget, Request $request) return $export->download($file_name.'.'.$file_ext); } - $options = new Archive(); - $options->setSendHttpHeaders(true); - $zip = new ZipStream($file_name.'.zip', $options); + $zip = new ZipStream(outputName: $file_name.'.zip', sendHttpHeaders: true); $temp_file = 'temp/'.uniqid().'.'.$file_ext; $export->store($temp_file); $zip->addFileFromPath($file_name.'.'.$file_ext, storage_path('app/'.$temp_file)); diff --git a/app/Http/Controllers/Accounting/API/SuppliersController.php b/app/Http/Controllers/Accounting/API/SuppliersController.php index d8fe740a5..a3b3a3493 100644 --- a/app/Http/Controllers/Accounting/API/SuppliersController.php +++ b/app/Http/Controllers/Accounting/API/SuppliersController.php @@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Illuminate\Http\Response; -use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; class SuppliersController extends Controller @@ -74,9 +73,9 @@ private function filterQuery(Builder $query, string $filter): Builder ->orWhere('category', 'LIKE', '%'.$filter.'%') ->orWhere('remarks', 'LIKE', '%'.$filter.'%') ->orWhere('tax_number', $filter) - ->orWhere(DB::raw('REPLACE(phone, \' \', \'\')'), str_replace(' ', '', $filter)) - ->orWhere(DB::raw('REPLACE(mobile, \' \', \'\')'), str_replace(' ', '', $filter)) - ->orWhere(DB::raw('REPLACE(iban, \' \', \'\')'), str_replace(' ', '', $filter)) + ->orWhereRaw('REPLACE(phone, \' \', \'\') = ?', [str_replace(' ', '', $filter)]) + ->orWhereRaw('REPLACE(mobile, \' \', \'\') = ?', [str_replace(' ', '', $filter)]) + ->orWhereRaw('REPLACE(iban, \' \', \'\') = ?', [str_replace(' ', '', $filter)]) ); } diff --git a/app/Http/Controllers/CommunityVolunteers/API/CommunityVolunteerController.php b/app/Http/Controllers/CommunityVolunteers/API/CommunityVolunteerController.php index 6b53295de..9098dff03 100644 --- a/app/Http/Controllers/CommunityVolunteers/API/CommunityVolunteerController.php +++ b/app/Http/Controllers/CommunityVolunteers/API/CommunityVolunteerController.php @@ -9,7 +9,6 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; class CommunityVolunteerController extends Controller @@ -97,8 +96,8 @@ private function filterTerms(Builder $query, array $terms): Builder private function filterQuery(Builder $query, string $filter): Builder { return $query->where( - fn (Builder $q) => $q->where(DB::raw('CONCAT(first_name, \' \', family_name)'), 'LIKE', '%'.$filter.'%') - ->orWhere(DB::raw('CONCAT(family_name, \' \', first_name)'), 'LIKE', '%'.$filter.'%') + fn (Builder $q) => $q->whereRaw('CONCAT(first_name, \' \', family_name) LIKE ?', ['%'.$filter.'%']) + ->orWhereRaw('CONCAT(family_name, \' \', first_name) LIKE ?', ['%'.$filter.'%']) ->orWhere('first_name', 'LIKE', '%'.$filter.'%') ->orWhere('nickname', 'LIKE', '%'.$filter.'%') ->orWhere('family_name', 'LIKE', '%'.$filter.'%') diff --git a/app/Http/Controllers/CommunityVolunteers/ImportExportController.php b/app/Http/Controllers/CommunityVolunteers/ImportExportController.php index 7f10b11a5..582a8afa8 100644 --- a/app/Http/Controllers/CommunityVolunteers/ImportExportController.php +++ b/app/Http/Controllers/CommunityVolunteers/ImportExportController.php @@ -17,7 +17,6 @@ use Illuminate\Validation\Rule; use Illuminate\View\View; use JeroenDesloovere\VCard\VCard; -use ZipStream\Option\Archive; use ZipStream\ZipStream; class ImportExportController extends BaseController @@ -240,9 +239,7 @@ private function downloadExportable( \Debugbar::disable(); // Debugbar will inject additional code at end of zip file if enabled // Download as ZIP with portraits - $options = new Archive(); - $options->setSendHttpHeaders(true); - $zip = new ZipStream($file_name.'.zip', $options); + $zip = new ZipStream(outputName: $file_name.'.zip', sendHttpHeaders: true); $temp_file = 'temp/'.uniqid().'.'.$file_ext; $export->store($temp_file); $zip->addFileFromPath($file_name.'.'.$file_ext, storage_path('app/'.$temp_file)); diff --git a/app/Models/Fundraising/Donor.php b/app/Models/Fundraising/Donor.php index 008495c6e..10bf8d92c 100644 --- a/app/Models/Fundraising/Donor.php +++ b/app/Models/Fundraising/Donor.php @@ -17,7 +17,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\DB; class Donor extends Model { @@ -199,20 +198,20 @@ public function scopeForFilter(Builder $query, ?string $filter = ''): Builder ->map(fn ($name) => strtolower($name)) ->flip(); - return $wq->where(DB::raw('CONCAT(first_name, \' \', last_name)'), 'LIKE', '%'.$filter.'%') - ->orWhere(DB::raw('CONCAT(last_name, \' \', first_name)'), 'LIKE', '%'.$filter.'%') + return $wq->whereRaw('CONCAT(first_name, \' \', last_name) LIKE ?', ['%'.$filter.'%']) + ->orWhereRaw('CONCAT(last_name, \' \', first_name) LIKE ?', ['%'.$filter.'%']) ->orWhere('company', 'LIKE', '%'.$filter.'%') ->orWhere('first_name', 'LIKE', '%'.$filter.'%') ->orWhere('last_name', 'LIKE', '%'.$filter.'%') ->orWhere('street', 'LIKE', '%'.$filter.'%') ->orWhere('zip', $filter) ->orWhere('city', 'LIKE', '%'.$filter.'%') - ->orWhere(DB::raw('CONCAT(street, \' \', city)'), 'LIKE', '%'.$filter.'%') - ->orWhere(DB::raw('CONCAT(street, \' \', zip, \' \', city)'), 'LIKE', '%'.$filter.'%') + ->orWhereRaw('CONCAT(street, \' \', city) LIKE ?', ['%'.$filter.'%']) + ->orWhereRaw('CONCAT(street, \' \', zip, \' \', city) LIKE ?', ['%'.$filter.'%']) // Note: Countries filter only works for complete country code or country name ->orWhere('country_code', $countries[strtolower($filter)] ?? $filter) ->orWhere('email', 'LIKE', '%'.$filter.'%') - ->orWhere(DB::raw("REPLACE(REPLACE(REPLACE(REPLACE(phone, ' ', ''), '+', ''), '(', ''), ')', '')"), 'LIKE', '%'.str_replace(['+', '(', ')', ' '], '', $filter).'%'); + ->orWhereRaw("REPLACE(REPLACE(REPLACE(REPLACE(phone, ' ', ''), '+', ''), '(', ''), ')', '') LIKE ?", ['%'.str_replace(['+', '(', ')', ' '], '', $filter).'%']); }); } @@ -224,8 +223,8 @@ public function scopeForFilter(Builder $query, ?string $filter = ''): Builder */ public function scopeForSimpleFilter(Builder $query, string $filter): Builder { - return $query->where(DB::raw('CONCAT(first_name, \' \', last_name)'), 'LIKE', '%'.$filter.'%') - ->orWhere(DB::raw('CONCAT(last_name, \' \', first_name)'), 'LIKE', '%'.$filter.'%') + return $query->whereRaw('CONCAT(first_name, \' \', last_name) LIKE ?', ['%'.$filter.'%']) + ->orWhereRaw('CONCAT(last_name, \' \', first_name) LIKE ?', ['%'.$filter.'%']) ->orWhere('company', 'LIKE', '%'.$filter.'%') ->orWhere('first_name', 'LIKE', '%'.$filter.'%') ->orWhere('last_name', 'LIKE', '%'.$filter.'%');