Deprecate singleOrFail() in favour of sole()
This commit is contained in:
parent
f0f2d74a14
commit
72ad1307c5
@ -160,7 +160,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|
||||
try {
|
||||
$o->zone = Zone::where('zone_id',$o->fz)
|
||||
->where('default',TRUE)
|
||||
->singleOrFail();
|
||||
->sole();
|
||||
|
||||
} catch (ModelNotFoundException $e) {
|
||||
throw new InvalidPacketException(sprintf('%s:! We couldnt work out the packet zone, and there isnt a default for[%d]',self::LOGKEY,$o->fz));
|
||||
|
@ -179,11 +179,11 @@ final class DNS extends BaseProtocol
|
||||
|
||||
switch ($labels->first()) {
|
||||
case '_binkp':
|
||||
$mailer = Mailer::where('name','BINKP')->singleOrFail();
|
||||
$mailer = Mailer::where('name','BINKP')->sole();
|
||||
break;
|
||||
|
||||
case '_ifcico':
|
||||
$mailer = Mailer::where('name','EMSI')->singleOrFail();
|
||||
$mailer = Mailer::where('name','EMSI')->sole();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -30,7 +30,7 @@ class AddressIdle extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
|
||||
$do = Domain::where('name',$this->argument('domain'))->sole();
|
||||
|
||||
return Job::dispatchSync($do,$this->option('ftn') ? Address::findFTN($this->option('ftn')) : NULL);
|
||||
}
|
||||
|
@ -27,8 +27,6 @@ class CommBinkpSend extends Command
|
||||
*/
|
||||
protected $description = 'BINKP send';
|
||||
|
||||
private const ID = 'BINKP';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@ -42,7 +40,7 @@ class CommBinkpSend extends Command
|
||||
|
||||
Log::info(sprintf('CBS:- Call BINKP send for %s',$ao->ftn));
|
||||
|
||||
$mo = Mailer::where('name',self::ID)->singleOrFail();
|
||||
$mo = Mailer::where('name','BINKP')->sole();
|
||||
|
||||
if ($this->option('now'))
|
||||
Job::dispatchSync($ao,$mo);
|
||||
|
@ -27,8 +27,6 @@ class CommEMSISend extends Command
|
||||
*/
|
||||
protected $description = 'EMSI send';
|
||||
|
||||
private const ID = 'EMSI';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@ -42,7 +40,7 @@ class CommEMSISend extends Command
|
||||
|
||||
Log::info(sprintf('CES:- Call EMSI send for %s',$ao->ftn));
|
||||
|
||||
$mo = Mailer::where('name',self::ID)->singleOrFail();
|
||||
$mo = Mailer::where('name','EMSI')->sole();
|
||||
|
||||
if ($this->option('now'))
|
||||
Job::dispatchSync($ao,$mo);
|
||||
|
@ -16,7 +16,7 @@ class ZoneCheck extends Command
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
|
||||
$do = Domain::where('name',$this->argument('domain'))->sole();
|
||||
|
||||
foreach ($do->zones->sortby('zone_id') as $zo) {
|
||||
if ($this->option('zone') && ($this->option('zone') != $zo->zone_id))
|
||||
|
@ -34,7 +34,8 @@ class EchoareaImport extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$do = Domain::where('name',strtolower($this->argument('domain')))->singleOrFail();
|
||||
$do = Domain::where('name',strtolower($this->argument('domain')))->single();
|
||||
|
||||
return Job::dispatchSync($this->argument('file'),$do,$this->option('prefix') ?: '',$this->option('unlink'));
|
||||
}
|
||||
}
|
@ -34,7 +34,8 @@ class FileareaImport extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$do = Domain::where('name',strtolower($this->argument('domain')))->singleOrFail();
|
||||
$do = Domain::where('name',strtolower($this->argument('domain')))->sole();
|
||||
|
||||
return Job::dispatchSync($this->argument('file'),$do,$this->option('prefix') ?: '',$this->option('unlink'));
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ class Rescan extends Command
|
||||
if (! $this->argument('area'))
|
||||
throw new \Exception('Areaname is required');
|
||||
|
||||
$fao = Filearea::where('name',$this->argument('area'))->singleOrFail();
|
||||
$fao = Filearea::where('name',$this->argument('area'))->sole();
|
||||
if ($fao->domain_id !== $ao->zone->domain_id)
|
||||
throw new \Exception(sprintf('File area [%s] is not in domain [%s] for FTN [%s]',$fao->name,$ao->zone->domain->name,$ao->ftn));
|
||||
|
||||
|
@ -33,7 +33,7 @@ class NodesNew extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$do = Domain::where('name',$this->argument('domain'))->singleOrFail();
|
||||
$do = Domain::where('name',$this->argument('domain'))->sole();
|
||||
$ao = NULL;
|
||||
|
||||
if ($this->option('netmail')) {
|
||||
|
@ -25,7 +25,7 @@ class UserCodeSend extends Command
|
||||
public function handle(): int
|
||||
{
|
||||
$ao = Address::findFTN($this->argument('ftn'));
|
||||
$uo = User::where('email',$this->argument('email'))->singleOrFail();
|
||||
$uo = User::where('email',$this->argument('email'))->sole();
|
||||
|
||||
Notification::route('netmail',$ao->uplink())->notify(new AddressLink($uo));
|
||||
|
||||
|
@ -69,7 +69,7 @@ class ZoneController extends Controller
|
||||
$o->save();
|
||||
$zo = Zone::where('zone_id',$request->zone_id)
|
||||
->where('domain_id',$request->domain_id)
|
||||
->singleOrFail();
|
||||
->sole();
|
||||
|
||||
// Find the zones 0/0 address, and assign it to this host.
|
||||
$ao = Address::where('zone_id',$zo->id)
|
||||
|
@ -144,8 +144,8 @@ class NodelistImport implements ShouldQueue
|
||||
return;
|
||||
}
|
||||
|
||||
$mailer_binkp = Mailer::where('name','BINKP')->singleOrFail();
|
||||
$mailer_emsi = Mailer::where('name','EMSI')->singleOrFail();
|
||||
$mailer_binkp = Mailer::where('name','BINKP')->sole();
|
||||
$mailer_emsi = Mailer::where('name','EMSI')->sole();
|
||||
|
||||
$p = $c = 0;
|
||||
|
||||
|
@ -34,7 +34,7 @@ class TicProcess implements ShouldQueue
|
||||
*/
|
||||
public function __construct(private string $file,private ?string $domain=NULL)
|
||||
{
|
||||
$this->do = $domain ? Domain::where('name',$domain)->singleOrFail() : NULL;
|
||||
$this->do = $domain ? Domain::where('name',$domain)->sole() : NULL;
|
||||
|
||||
$this->onQueue(self::QUEUE);
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ use App\Listeners\EchomailListener;
|
||||
use App\Listeners\Matrix\MessageListener;
|
||||
use App\Notifications\Channels\{EchomailChannel,MatrixChannel,NetmailChannel};
|
||||
use App\Models\{Echomail,Netmail,User};
|
||||
use App\Traits\SingleOrFail;
|
||||
use App\Traits\Single;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
use SingleOrFail;
|
||||
use Single;
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
@ -52,7 +52,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
static::bootSingleOrFail();
|
||||
static::bootSingle();
|
||||
|
||||
// Add our page assets
|
||||
Blade::directive('pa',function($expression) {
|
||||
|
@ -1,31 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Add eloquent queries single(), singleOrFail(), singleOrNew()
|
||||
* Add eloquent queries single(), singleOrNew()
|
||||
*/
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
trait SingleOrFail
|
||||
trait Single
|
||||
{
|
||||
private static function bootSingleOrFail(): void
|
||||
private static function bootSingle(): void
|
||||
{
|
||||
// When a query should return 1 object, or FAIL if it doesnt
|
||||
// @deprecated use sole()
|
||||
Builder::macro('singleOrFail',function () {
|
||||
$result = $this->get();
|
||||
|
||||
if (($x=$result->count()) === 1)
|
||||
return $result->first();
|
||||
|
||||
if ($x === 0)
|
||||
throw new ModelNotFoundException('Query brings back 0 record(s) called for singleOrFail()');
|
||||
else
|
||||
throw new \Exception(sprintf('Query brings back %d record(s) called for singleOrFail()',$x));
|
||||
});
|
||||
|
||||
// When a query should return 1 object, or NULL if it doesnt
|
||||
Builder::macro('single',function () {
|
||||
$result = $this->get();
|
@ -38,7 +38,7 @@ class TestNodeHierarchy extends Seeder
|
||||
]);
|
||||
|
||||
foreach (['a','b'] as $domain) {
|
||||
$do = Domain::where('name',$domain)->singleOrFail();
|
||||
$do = Domain::where('name',$domain)->sole();
|
||||
$this->hierarchy($do,100);
|
||||
$this->hierarchy($do,101);
|
||||
}
|
||||
@ -84,7 +84,7 @@ class TestNodeHierarchy extends Seeder
|
||||
'updated_at'=>Carbon::now(),
|
||||
]);
|
||||
|
||||
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->singleOrFail();
|
||||
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->sole();
|
||||
if (self::DEBUG)
|
||||
dump(['zo'=>$zo->zone_id,'rid'=>0,'hid'=>0,'nid'=>0]);
|
||||
|
||||
|
@ -57,7 +57,7 @@ class RoutingTest extends TestCase
|
||||
{
|
||||
//$this->seed(TestNodeHierarchy::class);
|
||||
|
||||
$do = Domain::where('name','a')->singleOrFail();
|
||||
$do = Domain::where('name','a')->sole();
|
||||
$zo = $do->zones->where('zone_id',100)->pop();
|
||||
return $zo->addresses;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user