diff --git a/.github/workflows/demo-build-and-deploy.yml b/.github/workflows/demo-build-and-deploy.yml new file mode 100644 index 0000000000..71892f76dd --- /dev/null +++ b/.github/workflows/demo-build-and-deploy.yml @@ -0,0 +1,67 @@ +name: Build and Deploy + +on: + push: + branches: + - multisite + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Extract version number + id: get_version + run: | + version=$(grep -Po 'Version:\s*\K[\d.]+' tutor.php) + echo "VERSION_NUMBER=$version" >> $GITHUB_ENV + echo "ZIP_PATH=tutor-${version}.zip" >> $GITHUB_ENV + + - name: Set up pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + + - name: Install Composer + run: sudo apt-get update && sudo apt-get install -y composer + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build project + run: pnpm run build-dev + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: build-artifact + path: ${{ env.ZIP_PATH }} + + - name: Setup SSH + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.DEMO_SSH_PRIVATE_KEY }} + + - name: Add remote server to known hosts + run: | + mkdir -p ~/.ssh + ssh-keyscan -H 172.105.64.114 >> ~/.ssh/known_hosts + + - name: Transfer file to remote + run: scp ${{ env.ZIP_PATH }} root@172.105.64.114:/var/www/tutor-demo/wp-content/plugins + + - name: UNZIP file + run: | + ssh root@172.105.64.114 << 'EOF' + rm -rf /var/www/tutor-demo/wp-content/plugins/tutor + unzip -o /var/www/tutor-demo/wp-content/plugins/${{ env.ZIP_PATH }} -d /var/www/tutor-demo/wp-content/plugins + EOF \ No newline at end of file diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml deleted file mode 100644 index 1100ecf5fa..0000000000 --- a/.github/workflows/phpstan.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: PHPStan - -on: [push, pull_request] - -jobs: - phpstan: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - tools: composer - - - name: Install dependencies - run: composer install --no-progress --prefer-dist --no-scripts - - # 3. Run PHPStan Full Analysis (Now fast due to cache) - - name: Run PHPStan on Changed Files - run: vendor/bin/phpstan analyse -c phpstan.neon -l 1 $(git --no-pager diff --name-only --diff-filter=MARC | grep -E 'classes/|tests/|ecommerce/|helpers/|includes/|migrations/|models/|traits') \ No newline at end of file diff --git a/.github/workflows/staging-build-and-deploy.yml b/.github/workflows/staging-build-and-deploy.yml deleted file mode 100644 index 13e4c87b06..0000000000 --- a/.github/workflows/staging-build-and-deploy.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: Staging Build and Deploy - -on: - push: - branches: - - ecommerce-backend -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: '16.17.0' - - - name: Install dependencies - run: npm install --legacy-peer-deps - - - name: Install Composer - run: sudo apt-get update && sudo apt-get install -y composer - - - name: Install Composer Dependencies in Paypal Directory - run: composer install --no-dev --working-dir=./ecommerce/PaymentGateways/Paypal - - - name: Clone tutor-droip repository - run: | - if [ ! -d "includes/droip" ]; then - git clone https://github.com/themeum/tutor-droip.git includes/droip - fi - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract version number - id: get_version - run: | - version=$(grep -Po 'Version:\s*\K[\d.]+(?:-[\w]+)?' tutor.php) - echo "VERSION_NUMBER=$version" >> $GITHUB_ENV - - - name: Build project - run: npm run build - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: build-artifact - path: tutor-${{ env.VERSION_NUMBER }}.zip - - - name: Setup SSH - uses: webfactory/ssh-agent@v0.5.3 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - - name: Add remote server to known hosts - run: | - mkdir -p ~/.ssh - ssh-keyscan -H 45.79.123.135 >> ~/.ssh/known_hosts - - - name: Transfer file to remote - run: scp tutor-${{ env.VERSION_NUMBER }}.zip shewa@45.79.123.135:/var/www/html/subdomains/tutor-lms/wp-content/plugins - - - name: UNZIP file - run: | - ssh shewa@45.79.123.135 << 'EOF' - rm -rf /var/www/html/subdomains/tutor-lms/wp-content/plugins/tutor - unzip -o /var/www/html/subdomains/tutor-lms/wp-content/plugins/tutor-${{ env.VERSION_NUMBER }}.zip -d /var/www/html/subdomains/tutor-lms/wp-content/plugins - EOF diff --git a/classes/Utils.php b/classes/Utils.php index 5c23a36a21..ef6ee53877 100644 --- a/classes/Utils.php +++ b/classes/Utils.php @@ -525,14 +525,20 @@ public function is_monetize_by_tutor() { * * @since 1.0.0 * - * @param string $plugin_path plugin path. + * @param string|array $plugin_path plugin path. * * @return boolean */ public function is_plugin_active( $plugin_path ) { - $activated_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); - $depends = is_array( $plugin_path ) ? $plugin_path : array( $plugin_path ); - $has_plugin = count( array_intersect( $depends, $activated_plugins ) ) == count( $depends ); + $depends = is_array( $plugin_path ) ? $plugin_path : array( $plugin_path ); + $has_plugin = true; + + foreach ( $depends as $plugin ) { + if ( ! is_plugin_active( $plugin ) ) { + $has_plugin = false; + break; + } + } return $has_plugin; } @@ -576,10 +582,7 @@ public function is_addon_enabled( $basename ) { * @return bool */ public function has_bp() { - $activated_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); - $depends = array( 'buddypress/bp-loader.php' ); - $has_bp = count( array_intersect( $depends, $activated_plugins ) ) == count( $depends ); - return $has_bp; + return $this->is_plugin_active( 'buddypress/bp-loader.php' ); } /** diff --git a/helpers/QueryHelper.php b/helpers/QueryHelper.php index af3f5310eb..51f3da8a0b 100644 --- a/helpers/QueryHelper.php +++ b/helpers/QueryHelper.php @@ -1251,13 +1251,45 @@ public static function get_last_query(){ * * @since 3.7.0 * + * @since 4.0.0 $table_name param added + * + * @param string $table_name Table name. + * * @return string */ - public static function get_table_prefix() { + public static function get_table_prefix( $table_name ) { global $wpdb; + + if ( is_multisite() && self::is_base_table( $table_name ) ) { + return $wpdb->base_prefix; + } + return $wpdb->prefix; } + /** + * Check if accessing the base tables + * + * @since 4.0.0 + * + * @param string $table_name Table name. + * + * @return bool + */ + private static function is_base_table( string $table_name ): bool { + $base_tables = array( + 'users', + 'usermeta', + ); + + // Table name examples: wp_users, wp_3_users, td_12_usermeta, users, usermeta, wp_users u, wp_users AS u. + $pattern = '/(?:^|_)(?:' . + implode( '|', array_map( 'preg_quote', $base_tables ) ) . + ')(?:\s+(?:AS\s+)?[a-zA-Z_][a-zA-Z0-9_]*)?$/i'; + + return (bool) preg_match( $pattern, trim( $table_name ) ); + } + /** * Prepare table name with prefix. * @@ -1268,7 +1300,8 @@ public static function get_table_prefix() { * @return string */ public static function prepare_table_name( string $table_name ) { - $table_prefix = self::get_table_prefix(); + $table_name = trim( $table_name ); + $table_prefix = self::get_table_prefix( $table_name ); if ( strpos( $table_name,$table_prefix ) !== 0 ) { $table_name = $table_prefix . $table_name; } diff --git a/models/WithdrawModel.php b/models/WithdrawModel.php index 1d9e53bff8..4664f6ad88 100644 --- a/models/WithdrawModel.php +++ b/models/WithdrawModel.php @@ -195,7 +195,7 @@ public static function get_withdraw_summary( $instructor_id, $args = array() ) { HAVING user_id = u.ID ),0) total_matured - FROM {$wpdb->prefix}users u WHERE u.ID=%d + FROM {$wpdb->users} u WHERE u.ID=%d ) a", 'completed', diff --git a/templates/dashboard/account/withdrawals.php b/templates/dashboard/account/withdrawals.php index 601e322eda..a1a1686735 100644 --- a/templates/dashboard/account/withdrawals.php +++ b/templates/dashboard/account/withdrawals.php @@ -70,10 +70,10 @@ $currency_symbol = $currency_config['symbol'] ?? ''; $summary_data = WithdrawModel::get_withdraw_summary( $user_id ); -$available_for_withdraw = $summary_data->available_for_withdraw - $summary_data->total_pending; +$available_for_withdraw = $summary_data ? $summary_data->available_for_withdraw - $summary_data->total_pending : 0; $is_balance_sufficient = $available_for_withdraw >= $min_withdraw; $available_for_withdraw_formatted = tutor_utils()->tutor_price( $available_for_withdraw ); -$current_balance_formated = tutor_utils()->tutor_price( $summary_data->current_balance ); +$current_balance_formated = tutor_utils()->tutor_price( $summary_data->current_balance ?? 0 ); ?> @@ -123,7 +123,7 @@
-
tutor_price( $summary_data->total_income ), tutor_price_allowed_html() ); ?>
+
tutor_price( $summary_data->total_income ?? 0 ), tutor_price_allowed_html() ); ?>
@@ -131,7 +131,7 @@
- tutor_price( $summary_data->total_pending ), tutor_price_allowed_html() ); ?> + tutor_price( $summary_data->total_pending ?? 0 ), tutor_price_allowed_html() ); ?> content( __( 'Total amount requested but not yet processed.', 'tutor' ) ) @@ -144,7 +144,7 @@
-
tutor_price( $summary_data->total_withdraw ), tutor_price_allowed_html() ); ?>
+
tutor_price( $summary_data->total_withdraw ?? 0 ), tutor_price_allowed_html() ); ?>