Skip to content

Commit 1a78ebe

Browse files
committed
Replace getSpecV and getBlobV logic with getOption
- Use a single getOption to create OptionData from an OptionSpec - Replace the logic in getSpecValue and getBlobValue with calls to getOption This makes sure that the same logic is followed in both cases and that the logic in OptionData gets used for all option lookups. The current logic was not consistent.
1 parent 3260303 commit 1a78ebe

2 files changed

Lines changed: 6 additions & 67 deletions

File tree

src/Options.php

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -447,55 +447,7 @@ public static function getValue( string $name ): string {
447447
throw new StaticDeployException( "Unknown option: $name" );
448448
}
449449

450-
return self::getSpecValue( $option_spec );
451-
}
452-
453-
/**
454-
* Get option value for a given OptionSpec
455-
*
456-
* @throws StaticDeployException
457-
* @return string option value
458-
*/
459-
public static function getSpecValue(
460-
OptionSpec $option_spec,
461-
): string {
462-
$name = $option_spec->name;
463-
$option_lookups = ( $name !== 'debugLogging' );
464-
WsLog::l(
465-
"Getting value of option: $name",
466-
$level = 'debug',
467-
$option_lookups = $option_lookups,
468-
);
469-
470-
global $wpdb;
471-
472-
$table_name = self::getTableName();
473-
474-
$sql = $wpdb->prepare(
475-
"SELECT value FROM $table_name WHERE" . ' name = %s LIMIT 1',
476-
$name
477-
);
478-
479-
$option_value = $wpdb->get_var( $sql );
480-
481-
if ( ! is_string( $option_value ) ) {
482-
$option_value = (string) $option_spec->default_value;
483-
}
484-
485-
if ( $option_spec->type === 'password' ) {
486-
$option_value = self::encrypt_decrypt( 'decrypt', $option_value );
487-
}
488-
489-
// default deploymentURL is '/', else remove trailing slash
490-
if ( $name === 'deploymentURL' ) {
491-
if ( $option_value !== '/' ) {
492-
$option_value = untrailingslashit( $option_value );
493-
}
494-
}
495-
496-
$option_value = apply_filters( (string) $option_spec->filter_name, $option_value );
497-
498-
return $option_value;
450+
return self::getOption( $option_spec )->value;
499451
}
500452

501453
/**
@@ -507,26 +459,13 @@ public static function getSpecValue(
507459
public static function getBlobValue( string $name ): string {
508460
WsLog::d( "Getting blob value of option: $name" );
509461

510-
global $wpdb;
511-
512-
$table_name = self::getTableName();
513-
514-
$sql = $wpdb->prepare(
515-
"SELECT blob_value FROM $table_name WHERE" . ' name = %s LIMIT 1',
516-
$name
517-
);
518-
519-
$option_value = $wpdb->get_var( $sql );
462+
$option_spec = self::optionSpecs()[ $name ];
520463

521-
if ( ! is_string( $option_value ) ) {
522-
$os = self::optionSpecs()[ $name ];
523-
if ( ! $os ) {
524-
return '';
525-
}
526-
$option_value = $os->default_blob_value;
464+
if ( ! $option_spec ) {
465+
throw WsLog::ex( "Unknown option: $name" );
527466
}
528467

529-
return $option_value;
468+
return self::getOption( $option_spec )->blob_value;
530469
}
531470

532471
/**

src/S3/S3Options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,6 @@ public static function getValue( string $slug ): string {
155155
throw WsLog::ex( "Unknown option: $name" );
156156
}
157157

158-
return Options::getSpecValue( $option_spec );
158+
return Options::getOption( $option_spec )->value;
159159
}
160160
}

0 commit comments

Comments
 (0)