Skip to content

Commit

Permalink
feat: add the BLOCKERA_DATA_STREAM_OFF constant
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaelahidev committed Oct 31, 2024
1 parent 1b9119e commit 1a1f615
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_MODE=production
DATA_STREAM_SERVER_URL=http://127.0.0.1:8000/v1
BLOCKERA_DATA_STREAM_OFF=false
WP_TESTS_DIR=/Users/User/Desktop/workflow/wordpress-develop/tests/phpunit/

DB=wp_tests

6 changes: 3 additions & 3 deletions .github/workflows/cypress-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ jobs:
run: |
case "${{ matrix.category }}" in
"woocommerce")
echo '{"plugins": [".", "https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip"], "config": {"WP_FS__SIMULATE_FREEMIUS_OFF": true}}' >> .wp-env.json
echo '{"plugins": [".", "https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip"], "config": {"BLOCKERA_DATA_STREAM_OFF": true}}' >> .wp-env.json
;;
"freemius")
echo '{"plugins": ["."]}' >> .wp-env.json
;;
"plugins")
echo '{"plugins": [".", "https://downloads.wordpress.org/plugin/icon-block.latest-stable.zip"], "config": {"WP_FS__SIMULATE_FREEMIUS_OFF": true}}' >> .wp-env.json
echo '{"plugins": [".", "https://downloads.wordpress.org/plugin/icon-block.latest-stable.zip"], "config": {"BLOCKERA_DATA_STREAM_OFF": true}}' >> .wp-env.json
;;
*)
echo '{"plugins": [".", "https://downloads.wordpress.org/plugin/svg-support.latest-stable.zip"], "config": {"WP_FS__SIMULATE_FREEMIUS_OFF": true}}' >> .wp-env.json
echo '{"plugins": [".", "https://downloads.wordpress.org/plugin/svg-support.latest-stable.zip"], "config": {"BLOCKERA_DATA_STREAM_OFF": true}}' >> .wp-env.json
;;
esac
cat .wp-env.json
Expand Down
2 changes: 1 addition & 1 deletion .wp-env.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"https://downloads.wordpress.org/plugin/icon-block.latest-stable.zip"
],
"config": {
"WP_FS__SIMULATE_FREEMIUS_OFF": true
"BLOCKERA_DATA_STREAM_OFF": true
}
}
4 changes: 3 additions & 1 deletion packages/blockera-admin/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export const Dashboard = (): MixedElement => {

return (
<div className={'blockera-settings-dashboard'}>
<OptInModal kind={'blockera/v1'} name={'opt-in'} />
{'1' === window.blockeraDataStreamIsOff && (
<OptInModal kind={'blockera/v1'} name={'opt-in'} />
)}
<SettingsContext.Provider
value={{
config,
Expand Down
2 changes: 1 addition & 1 deletion packages/blockera-admin/js/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GeneralPanel, BlockManagerPanel, DashboardPanel } from './components';

export const Panel = (tab: {
...TTabProps,
settingSlug: string,
settingSlug?: string,
}): MixedElement => {
let description: Element<any> = <></>;
let activePanel: any = <></>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function createInlineScript( string $inline_script ): string {
}

return 'window.blockeraTermsOfServicesLink = "' . blockera_core_config( 'dataStream.terms_of_services_link' ) . '";
window.blockeraDataStreamIsOff = "' . ! blockera_ds_is_off() . '";
window.blockeraOptInStatus = "' . get_option( blockera_core_config( 'dataStream.options.opt_in_status' ), null ) . '";
window.blockeraPrivacyAndPolicyLink = "' . blockera_core_config( 'dataStream.privacy_and_policy_link' ) . '";
window.blockeraOptInDescription = "' . blockera_core_config( 'dataStream.opt_in_description' ) . '";
Expand Down
21 changes: 12 additions & 9 deletions packages/blockera/php/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,18 @@ public function boot(): void {

$this->renderBlocks();

Config::setRestParams(
array_merge(
blockera_core_config( 'dataStream.rest_params' ),
[ 'root_path' => blockera_core_config( 'app.root_path' ) ]
)
);
Config::setOptionKeys( blockera_core_config( 'dataStream.options' ) );
Config::setServerURL( blockera_core_config( 'dataStream.server_url' ) );
Config::setHookPrefix( blockera_core_config( 'dataStream.hook_prefix' ) );
if ( ! blockera_ds_is_off() ) {

Config::setRestParams(
array_merge(
blockera_core_config( 'dataStream.rest_params' ),
[ 'root_path' => blockera_core_config( 'app.root_path' ) ]
)
);
Config::setOptionKeys( blockera_core_config( 'dataStream.options' ) );
Config::setServerURL( blockera_core_config( 'dataStream.server_url' ) );
Config::setHookPrefix( blockera_core_config( 'dataStream.hook_prefix' ) );
}

add_action( 'after_setup_theme', [ $this, 'after_setup_theme' ] );
}
Expand Down
5 changes: 4 additions & 1 deletion packages/blockera/php/Routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
$routes->get( 'settings', [ Blockera\Admin\Http\Controllers\SettingsController::class, 'index' ] );
$routes->update( 'settings', [ Blockera\Admin\Http\Controllers\SettingsController::class, 'response' ] );

$routes->post( 'opt-in', [ Blockera\DataStream\Http\Controllers\OptInController::class, 'optIn' ] );
if ( ! blockera_ds_is_off() ) {

$routes->post( 'opt-in', [ Blockera\DataStream\Http\Controllers\OptInController::class, 'optIn' ] );
}

} catch ( Exception $exception ) {

Expand Down
17 changes: 10 additions & 7 deletions packages/data-stream/php/Jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ class Jobs {
*/
public function __construct( Sender $sender, string $plugin_file, array $config ) {

$this->sender = $sender;
$this->config = $config;
if ( ! blockera_ds_is_off() ) {

add_filter( 'cron_schedules', [ $this, 'addCronInterval' ] );
add_action( 'blockera_each_six_days', [ $this, 'doRefreshToken' ] );
add_action( 'blockera_each_seven_days', [ $this, 'doUpdateRegisteredData' ] );
$this->sender = $sender;
$this->config = $config;

register_activation_hook( $plugin_file, [ $this, 'activationHook' ] );
register_deactivation_hook( $plugin_file, [ $this, 'deactivationHook' ] );
add_filter( 'cron_schedules', [ $this, 'addCronInterval' ] );
add_action( 'blockera_each_six_days', [ $this, 'doRefreshToken' ] );
add_action( 'blockera_each_seven_days', [ $this, 'doUpdateRegisteredData' ] );

register_activation_hook( $plugin_file, [ $this, 'activationHook' ] );
register_deactivation_hook( $plugin_file, [ $this, 'deactivationHook' ] );
}
}

/**
Expand Down
23 changes: 23 additions & 0 deletions packages/data-stream/php/functions.php
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
<?php

if ( ! function_exists( 'blockera_ds_is_off' ) ) {

/**
* Check the blockera data stream system is off?
*
* @return bool true on success, false on otherwise!
*/
function blockera_ds_is_off(): bool {

if ( isset( $_ENV['BLOCKERA_DATA_STREAM_OFF'] ) && 'false' !== $_ENV['BLOCKERA_DATA_STREAM_OFF'] ) {

return true;
}

if ( ! defined( 'BLOCKERA_DATA_STREAM_OFF' ) ) {

return false;
}

return BLOCKERA_DATA_STREAM_OFF;
}
}

0 comments on commit 1a1f615

Please sign in to comment.