Skip to content

Commit

Permalink
do not fallback to plugin if to priority is set
Browse files Browse the repository at this point in the history
  • Loading branch information
arunshenoy99 committed Sep 7, 2023
1 parent 756a24d commit f079766
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 13 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/lint-check-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'Lint Checker: PHP'
on:
push:
paths:
- '**.php'
- '!build/**/*.php'
pull_request:
types: [opened, edited, reopened, ready_for_review]
paths:
- '**.php'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
phpcs:
name: Run PHP Code Sniffer
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

# User PHP 7.4 here for compatibility with the WordPress codesniffer rules.
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer, cs2pr

- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
**/*.php
!build/**/*.php
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
if: "!! env.GIT_DIFF"

- name: Cache Composer vendor directory
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
if: "!! env.GIT_DIFF"

- name: Validate composer.json and composer.lock
run: composer validate
if: "!! env.GIT_DIFF"

- name: Install dependencies
run: composer install --no-progress --optimize-autoloader --prefer-dist
if: "!! env.GIT_DIFF"

- name: Detecting PHP Code Standards Violations
run: vendor/bin/phpcs --standard=phpcs.xml -s ${{ env.GIT_DIFF }}
if: "!! env.GIT_DIFF"
24 changes: 15 additions & 9 deletions includes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public static function current_plan() {
);
}

$current_flow = Flows::get_flow_from_top_priority();
if ( 'ecommerce' === $current_flow ) {
return array(
'flow' => 'ecommerce',
'subtype' => 'wc_priority',
'type' => null,
);
} elseif ( Flows::get_default_flow() === $current_flow ) {
return array(
'flow' => $current_flow,
'subtype' => null,
'type' => null,
);
}

$current_flow = Flows::get_flow_from_plugins();
if ( false !== $current_flow ) {
switch ( $current_flow ) {
Expand All @@ -81,15 +96,6 @@ public static function current_plan() {
}
}

$current_flow = Flows::get_flow_from_top_priority();
if ( false !== $current_flow ) {
return array(
'flow' => 'ecommerce',
'subtype' => 'wc_priority',
'type' => null,
);
}

return array(
'flow' => Flows::get_default_flow(),
'subtype' => null,
Expand Down
11 changes: 8 additions & 3 deletions includes/Flows/Flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class Flows {
// Any manual fixes or modification made to topPriority shall also be made in FlowServices::update_default_data_for_ecommerce()
// Enums: `publishing`, `designing`, `selling`, 'migrating', 'regenerate' and 'skip'
'topPriority' => array(
'priority1' => 'publishing',
'priority1' => '',
),

// This data will map to WordPress default 'blogname'
Expand Down Expand Up @@ -276,9 +276,14 @@ public static function get_flow_from_plan_subtype( $plan_subtype ) {
*/
public static function get_flow_from_top_priority() {
$flow_data = FlowService::read_data_from_wp_option();
if ( $flow_data && isset( $flow_data['data']['topPriority']['priority1'] ) && 'selling' === $flow_data['data']['topPriority']['priority1'] ) {
if ( ! ( $flow_data && isset( $flow_data['data']['topPriority']['priority1'] ) ) ) {
return false;
}

if ( 'selling' === $flow_data['data']['topPriority']['priority1'] ) {
return true === self::get_flows()['ecommerce'] ? 'ecommerce' : false;
}
return false;

return self::get_default_flow();
}
}
2 changes: 2 additions & 0 deletions includes/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ public static function get_theme_step_patterns_from_step( $step, $squash = false

$pattern_slugs = self::get_theme_step_patterns()[ $active_theme ][ $step ];

$block_patterns = $squash ? '' : array();

foreach ( array_keys( $pattern_slugs ) as $pattern_slug ) {
if ( true !== $pattern_slugs[ $pattern_slug ]['active'] ) {
continue;
Expand Down
4 changes: 3 additions & 1 deletion includes/Services/FlowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ private static function update_data_for_ecommerce( $data ) {
$flow_type = Data::current_flow();
if ( 'ecommerce' === $flow_type ) {
// update default data with ecommerce data
$data['data']['topPriority']['priority1'] = 'selling';
if ( empty( $data['data']['topPriority']['priority1'] ) ) {
$data['data']['topPriority']['priority1'] = 'selling';
}
if ( empty( $data['data']['siteType']['primary']['value'] ) ) {
$data['data']['siteType']['primary']['refers'] = 'slug';
$data['data']['siteType']['primary']['value'] = 'business';
Expand Down
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Project Rules">
<rule ref="Newfold"/>
<config name="testVersion" value="7.0-"/>
<config name="minimum_supported_wp_version" value="5.8"/>
</ruleset>

0 comments on commit f079766

Please sign in to comment.