Skip to content

Commit

Permalink
[IM] Be determinate on the customer what will be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Jan 27, 2025
1 parent ec1e261 commit 5fa7f97
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
7 changes: 4 additions & 3 deletions app/Console/Commands/Irrdb/UpdateAsnDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class UpdateAsnDb extends UpdateDb
*
* @var string
*/
protected $signature = 'irrdb:update-asn-db
{customer? : Customer ASN, ID or shortname (in that order). Otherwise all customers.}';
protected $signature = 'irrdb:update-asn-db
{--asn= : Only update the member with this ASN}
{--id= : Only update the member with this customer ID}';

/**
* The console command description.
Expand All @@ -66,7 +67,7 @@ public function handle(): int
return -99;
}

$customers = $this->resolveCustomers();
$customers = $this->resolveCustomers( $this->options() );

foreach( $customers as $c ) {
try {
Expand Down
31 changes: 15 additions & 16 deletions app/Console/Commands/Irrdb/UpdateDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,31 @@ protected function setupChecks(): bool
*
* @return mixed
*/
protected function resolveCustomers(): mixed
protected function resolveCustomers( array $options ): mixed
{
$custarg = $this->argument('customer' );
if( $options[ 'asn' ] ) {
$c = Customer::whereAutsys( $options[ 'asn' ] )->get();

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

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

// then ID:
if( is_numeric( $custarg ) && ( $c = Customer::find( $custarg ) ) ) {
return [ $c ];
}
if( $options[ 'id' ] ) {
$c = Customer::whereId( $options[ 'id' ] )->get();

if( !count( $c ) ) {
$this->error( "No customer found with ID {$options[ 'id' ]}" );
exit(-1);
}

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

$this->error( "Could not find a customer matching id/shortname: " . $custarg );

exit(-1);
return Customer::currentActive( true )->get();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions app/Console/Commands/Irrdb/UpdatePrefixDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class UpdatePrefixDb extends UpdateDb
* @var string
*/
protected $signature = 'irrdb:update-prefix-db
{customer? : Customer ASN, ID or shortname (in that order). Otherwise all customers.}';
{--asn= : Only update the member with this ASN}
{--id= : Only update the member with this customer ID}';

/**
* The console command description.
Expand All @@ -66,7 +67,7 @@ public function handle(): int
return -99;
}

$customers = $this->resolveCustomers();
$customers = $this->resolveCustomers( $this->options() );

foreach( $customers as $c ) {
try {
Expand Down

0 comments on commit 5fa7f97

Please sign in to comment.