Skip to content

Commit

Permalink
update workflow with composer prefix-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Dec 9, 2023
1 parent 7637c88 commit 9398172
Show file tree
Hide file tree
Showing 65 changed files with 383 additions and 7,151 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Check if version has changed
id: check_version
run: |
VERSION=$(grep -oP "Version:\s*\K\d+(\.\d+)*" woocommerce-pos.php)
VERSION=$(grep -oP "Version:\s*\K\d+(\.\d+)*(-\w+)?(\.\d+)?" woocommerce-pos.php)
echo "VERSION=$VERSION" >> $GITHUB_ENV
git fetch --prune --unshallow
LAST_TAG=$(git describe --tags --abbrev=0)
Expand All @@ -41,14 +41,15 @@ jobs:
tag_name: v${{ env.VERSION }}
release_name: Release v${{ env.VERSION }}
draft: true
prerelease: false
prerelease: ${{ contains(env.VERSION, '-beta') }}

- name: Build
if: steps.check_version.outputs.release == 'true'
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
run: |
yarn install
composer prefix-dependencies
composer install --no-dev
yarn build:js
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/wp-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
run: |
yarn install
composer prefix-dependencies
composer install --no-dev
yarn build:js
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/wporg-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to WordPress.org

on:
release:
types: [ published ]
types: [ released ]

jobs:
tag:
Expand All @@ -12,13 +12,14 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
run: |
yarn install
composer prefix-dependencies
composer install --no-dev
yarn build:js
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ To prepare the repository for local development you should rename `.env.example`
Next you will need to install the required PHP via `composer` and JavaScript packages via `yarn`.

```sh
composer prefix-dependencies
composer install
yarn install
```
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"require": {
"php": ">=7.4",
"ext-json": "*",
"erusev/parsedown": "^1.7",
"ramsey/uuid": "^4.2",
"salesforce/handlebars-php": "3.0.1"
},
Expand All @@ -47,7 +48,7 @@
"fix": "php-cs-fixer fix .",
"prefix-dependencies": [
"@composer --working-dir=php-scoper install",
"php-scoper/vendor/bin/php-scoper add-prefix --config=php-scoper/config.php --output-dir=./vendor_prefixed --force",
"cd php-scoper && vendor/bin/php-scoper --output-dir=../vendor_prefixed add-prefix --force && cd ..",
"@composer dump-autoload -o -a"
]
},
Expand All @@ -56,8 +57,7 @@
"WCPOS\\WooCommercePOS\\": "includes/"
},
"classmap": [
"vendor_prefixed/firebase/php-jwt/src",
"vendor_prefixed/yahnis-elsts/plugin-update-checker"
"vendor_prefixed/vendor/firebase/php-jwt/src"
]
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion includes/API/Stores.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}

use WP_REST_Controller;
use WCPOS\WooCommercePOS\Services\Store;
use WCPOS\WooCommercePOS\Abstracts\Store;
use const WCPOS\WooCommercePOS\SHORT_NAME;

class Stores extends WP_REST_Controller {
Expand Down
20 changes: 14 additions & 6 deletions includes/Services/Store.php → includes/Abstracts/Store.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<?php
/**
* Abstract Store class.
*
* @package WooCommerce\POS\Abstracts
*/

namespace WCPOS\WooCommercePOS\Services;
namespace WCPOS\WooCommercePOS\Abstracts;

use WC_Data;

if ( ! class_exists( 'WC_Data' ) ) {
return;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

class Store extends WC_Data {
/**
* Abstract Store class.
*
* Handles the store data, and provides CRUD methods.
*/
class Store extends \WC_Data {
/**
* This is the name of this object type.
*
Expand Down
77 changes: 40 additions & 37 deletions includes/Activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function init(): void {

// Init update script if required
$this->version_check();
$this->pro_version_check();
$this->pro_version_check();

// resolve plugin plugins
$this->plugin_check();
Expand Down Expand Up @@ -89,10 +89,12 @@ public function single_activate(): void {
$this->create_pos_roles();

// add pos capabilities to non POS roles
$this->add_pos_capability(array(
'administrator' => array( 'manage_woocommerce_pos', 'access_woocommerce_pos' ),
'shop_manager' => array( 'manage_woocommerce_pos', 'access_woocommerce_pos' ),
));
$this->add_pos_capability(
array(
'administrator' => array( 'manage_woocommerce_pos', 'access_woocommerce_pos' ),
'shop_manager' => array( 'manage_woocommerce_pos', 'access_woocommerce_pos' ),
)
);

// set the auto redirection on next page load
// set_transient( 'woocommere_pos_welcome', 1, 30 );
Expand Down Expand Up @@ -123,9 +125,9 @@ private function php_check() {
}

$message = sprintf(
__( '<strong>WooCommerce POS</strong> requires PHP %1$s or higher. Read more information about <a href="%2$s">how you can update</a>', 'woocommerce-pos' ),
PHP_MIN_VERSION,
'http://www.wpupdatephp.com/update/'
__( '<strong>WooCommerce POS</strong> requires PHP %1$s or higher. Read more information about <a href="%2$s">how you can update</a>', 'woocommerce-pos' ),
PHP_MIN_VERSION,
'http://www.wpupdatephp.com/update/'
) . ' &raquo;';

Admin\Notices::add( $message );
Expand All @@ -140,10 +142,10 @@ private function woocommerce_check() {
}

$message = sprintf(
__( '<strong>WooCommerce POS</strong> requires <a href="%1$s">WooCommerce %2$s or higher</a>. Please <a href="%3$s">install and activate WooCommerce</a>', 'woocommerce-pos' ),
'http://wordpress.org/plugins/woocommerce/',
WC_MIN_VERSION,
admin_url( 'plugins.php' )
__( '<strong>WooCommerce POS</strong> requires <a href="%1$s">WooCommerce %2$s or higher</a>. Please <a href="%3$s">install and activate WooCommerce</a>', 'woocommerce-pos' ),
'http://wordpress.org/plugins/woocommerce/',
WC_MIN_VERSION,
admin_url( 'plugins.php' )
) . ' &raquo;';

Admin\Notices::add( $message );
Expand Down Expand Up @@ -184,9 +186,9 @@ private function version_check(): void {
*/
private function plugin_check(): void {
// disable NextGEN Gallery resource manager
// if ( ! \defined( 'NGG_DISABLE_RESOURCE_MANAGER' ) ) {
// \define( 'NGG_DISABLE_RESOURCE_MANAGER', true );
// }
// if ( ! \defined( 'NGG_DISABLE_RESOURCE_MANAGER' ) ) {
// \define( 'NGG_DISABLE_RESOURCE_MANAGER', true );
// }
}

/**
Expand Down Expand Up @@ -222,14 +224,16 @@ private function create_pos_roles(): void {
);

add_role(
'cashier',
__( 'Cashier', 'woocommerce-pos' ),
$cashier_capabilities
'cashier',
__( 'Cashier', 'woocommerce-pos' ),
$cashier_capabilities
);

$this->add_pos_capability(array(
'cashier' => array( 'access_woocommerce_pos' ),
));
$this->add_pos_capability(
array(
'cashier' => array( 'access_woocommerce_pos' ),
)
);
}

/**
Expand Down Expand Up @@ -269,33 +273,32 @@ private function db_upgrade( $old, $current ): void {
}
}

/**
* If \WCPOS\WooCommercePOSPro\ is installed, check the version is above MIN_PRO_VERSION
*/
/**
* If \WCPOS\WooCommercePOSPro\ is installed, check the version is above MIN_PRO_VERSION
*/
private function pro_version_check() {
if ( class_exists( '\WCPOS\WooCommercePOSPro\Activator' ) ) {
if ( class_exists( '\WCPOS\WooCommercePOSPro\Activator' ) ) {
if ( version_compare( \WCPOS\WooCommercePOSPro\VERSION, MIN_PRO_VERSION, '<' ) ) {
/**
* NOTE: the deactivate_plugins function is not available in the frontend or ajax
* This is an extreme situation where the Pro plugin could crash the site, so we need to deactivate it
*/
if ( ! function_exists( 'deactivate_plugins' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
/**
* NOTE: the deactivate_plugins function is not available in the frontend or ajax
* This is an extreme situation where the Pro plugin could crash the site, so we need to deactivate it
*/
if ( ! function_exists( 'deactivate_plugins' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}

// WooCommerce POS Pro is activated, but the version is too low
deactivate_plugins( 'woocommerce-pos-pro/woocommerce-pos-pro.php' );

$message = sprintf(
__( '<strong>WooCommerce POS</strong> requires <a href="%1$s">WooCommerce POS Pro %2$s or higher</a>. Please <a href="%3$s">install and activate WooCommerce POS Pro</a>', 'woocommerce-pos' ),
'https://wcpos.com/my-account',
MIN_PRO_VERSION,
admin_url( 'plugins.php' )
__( '<strong>WooCommerce POS</strong> requires <a href="%1$s">WooCommerce POS Pro %2$s or higher</a>. Please <a href="%3$s">install and activate WooCommerce POS Pro</a>', 'woocommerce-pos' ),
'https://wcpos.com/my-account',
MIN_PRO_VERSION,
admin_url( 'plugins.php' )
) . ' &raquo;';

Admin\Notices::add( $message );
}
}
}

}
Loading

0 comments on commit 9398172

Please sign in to comment.