Skip to content

Commit 5fa7f97

Browse files
committed
[IM] Be determinate on the customer what will be updated
1 parent ec1e261 commit 5fa7f97

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

Diff for: app/Console/Commands/Irrdb/UpdateAsnDb.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ class UpdateAsnDb extends UpdateDb
4343
*
4444
* @var string
4545
*/
46-
protected $signature = 'irrdb:update-asn-db
47-
{customer? : Customer ASN, ID or shortname (in that order). Otherwise all customers.}';
46+
protected $signature = 'irrdb:update-asn-db
47+
{--asn= : Only update the member with this ASN}
48+
{--id= : Only update the member with this customer ID}';
4849

4950
/**
5051
* The console command description.
@@ -66,7 +67,7 @@ public function handle(): int
6667
return -99;
6768
}
6869

69-
$customers = $this->resolveCustomers();
70+
$customers = $this->resolveCustomers( $this->options() );
7071

7172
foreach( $customers as $c ) {
7273
try {

Diff for: app/Console/Commands/Irrdb/UpdateDb.php

+15-16
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,31 @@ protected function setupChecks(): bool
5959
*
6060
* @return mixed
6161
*/
62-
protected function resolveCustomers(): mixed
62+
protected function resolveCustomers( array $options ): mixed
6363
{
64-
$custarg = $this->argument('customer' );
64+
if( $options[ 'asn' ] ) {
65+
$c = Customer::whereAutsys( $options[ 'asn' ] )->get();
6566

66-
// if not customer specific, return all appropriate ones:
67-
if( !$custarg ) {
68-
return Customer::currentActive( true )->get();
69-
}
67+
if( !count( $c ) ) {
68+
$this->error( "No customer found with ASN {$options[ 'asn' ]}" );
69+
exit(-1);
70+
}
7071

71-
// assume ASN first:
72-
if( is_numeric( $custarg ) && count( ( $c = Customer::whereAutsys( $custarg )->get() ) ) > 0 ) {
7372
return $c;
7473
}
7574

76-
// then ID:
77-
if( is_numeric( $custarg ) && ( $c = Customer::find( $custarg ) ) ) {
78-
return [ $c ];
79-
}
75+
if( $options[ 'id' ] ) {
76+
$c = Customer::whereId( $options[ 'id' ] )->get();
77+
78+
if( !count( $c ) ) {
79+
$this->error( "No customer found with ID {$options[ 'id' ]}" );
80+
exit(-1);
81+
}
8082

81-
if( count( $c = Customer::whereShortname( $custarg )->get() ) > 0 ) {
8283
return $c;
8384
}
8485

85-
$this->error( "Could not find a customer matching id/shortname: " . $custarg );
86-
87-
exit(-1);
86+
return Customer::currentActive( true )->get();
8887
}
8988

9089
/**

Diff for: app/Console/Commands/Irrdb/UpdatePrefixDb.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class UpdatePrefixDb extends UpdateDb
4444
* @var string
4545
*/
4646
protected $signature = 'irrdb:update-prefix-db
47-
{customer? : Customer ASN, ID or shortname (in that order). Otherwise all customers.}';
47+
{--asn= : Only update the member with this ASN}
48+
{--id= : Only update the member with this customer ID}';
4849

4950
/**
5051
* The console command description.
@@ -66,7 +67,7 @@ public function handle(): int
6667
return -99;
6768
}
6869

69-
$customers = $this->resolveCustomers();
70+
$customers = $this->resolveCustomers( $this->options() );
7071

7172
foreach( $customers as $c ) {
7273
try {

0 commit comments

Comments
 (0)