Skip to content

Commit

Permalink
cleanup + unify indent & escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
froger-me committed Jan 10, 2024
1 parent b641cf2 commit f37c114
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions integration/dummy-generic/wppus-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function init() {
public static function install( $license_key ) {
# add the license key to wppus.json
self::$config['licenseKey'] = $license_key;
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode

# add a file '.installed' in current directory
// touch "$(cd "$(dirname "$0")"; pwd -P)/.installed" (convert to php)
Expand All @@ -67,7 +67,7 @@ public static function install( $license_key ) {
public static function uninstall() {
# remove the license key from wppus.json
unset( self::$config['licenseKey'] );
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode

# remove the file '.installed' from current directory
unlink( __DIR__ . '/.installed' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
Expand Down Expand Up @@ -140,7 +140,7 @@ public static function activate() {
$signature = rawurldecode( json_decode( $response, true )['license_signature'] );
# add the license signature to wppus.json
self::$config['licenseSignature'] = $signature;
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
self::$license_signature = $signature;
}

Expand All @@ -159,7 +159,7 @@ public static function deactivate() {
self::send_api_request( $endpoint, $args );
# remove the license signature from wppus.json
unset( self::$config['licenseSignature'] );
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
self::$license_signature = '';
}

Expand Down Expand Up @@ -232,10 +232,10 @@ public static function update() {

# add the license key to wppus.json
self::$config['licenseKey'] = self::$license_key;
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
# add the license signature to wppus.json
self::$config['licenseSignature'] = self::$license_signature;
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode
file_put_contents( __DIR__ . '/wppus.json', json_encode( self::$config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.WP.AlternativeFunctions.json_encode_json_encode

# remove the directory
foreach ( glob( '/tmp/' . self::$package_name . '/*' ) as $file ) {
Expand Down
26 changes: 13 additions & 13 deletions integration/dummy-generic/wppus-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fi

function install() {
# add the license key to wppus.json
jq '.licenseKey = "'"$1"'"' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
jq --indent 4 '.licenseKey = "'"$1"'"' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
# add a file '.installed' in current directory
touch "$(cd "$(dirname "$0")"; pwd -P)/.installed"
}
Expand All @@ -53,9 +53,9 @@ function uninstall() {
license_signature=""

# remove the license key from wppus.json
jq '.licenseKey = ""' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
jq --indent 4 '.licenseKey = ""' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
# remove the license signature from wppus.json
jq '.licenseSignature = ""' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
jq --indent 4 '.licenseSignature = ""' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
# remove the file '.installed' from current directory
rm "$(cd "$(dirname "$0")"; pwd -P)/.installed"
}
Expand Down Expand Up @@ -153,15 +153,15 @@ function activate_license() {
local signature=$(urldecode $(echo -n "$response" | jq -r '.license_signature'))

# add the license signature to wppus.json
jq '.licenseSignature = "'"$signature"'"' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
jq --indent 4 '.licenseSignature = "'"$signature"'"' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"

license_signature=$signature
}

### DEACTIVATING A LICENSE ###

function deactivate_license() {
# build the request url
# # build the request url
local endpoint="wppus-license-api"
local args=(
"action=deactivate"
Expand All @@ -170,10 +170,10 @@ function deactivate_license() {
"package_slug=$(urlencode "$package_name")"
)

# make the request
send_api_request "$endpoint" "${args[@]}"
# # make the request
send_api_request "$endpoint" "${args[@]}" > /dev/null
# remove the license signature from wppus.json
jq '.licenseSignature = ""' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
jq --indent 4 'del(.licenseSignature)' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"

license_signature=""
}
Expand Down Expand Up @@ -263,9 +263,9 @@ if [ "$1" == "update" ]; then
done

# add the license key to wppus.json
jq '.licenseKey = "'"$license_key"'"' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
jq --indent 4 '.licenseKey = "'"$license_key"'"' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
# add the license signature to wppus.json
jq '.licenseSignature = "'"$signature"'"' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"
jq --indent 4 '.licenseSignature = "'"$signature"'"' "$(cd "$(dirname "$0")"; pwd -P)/wppus.json" > tmp.json && mv tmp.json "$(cd "$(dirname "$0")"; pwd -P)/wppus.json"

# remove the directory
rm -rf /tmp/$package_name
Expand All @@ -281,23 +281,23 @@ fi
# check if the script was called with the argument "activate_license"
if [ "$1" == "activate_license" ]; then
# activate the license
echo $(activate_license)
activate_license

exit 0
fi

# check if the script was called with the argument "deactivate_license"
if [ "$1" == "deactivate_license" ]; then
# deactivate the license
echo $(deactivate_license)
deactivate_license

exit 0
fi

# check if the script was called with the argument "get_update"
if [ "$1" == "get_update_info" ]; then
# get the update information
echo "$(check_for_updates)"
check_for_updates

exit 0
fi
Expand Down

0 comments on commit f37c114

Please sign in to comment.