• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 11714183904

07 Nov 2024 12:23AM UTC coverage: 83.665% (-0.8%) from 84.451%
11714183904

push

github

web-flow
devops: Name officially changed to "WPGraphQL for WooCommerce" (#900)

* devops: Name officially changed to "WPGraphQL for WooCommerce"

* devops: GA workflow environment updated

* devops: GA workflow environment updated

* devops: composer-git-hooks downgraded to "2.8.5"

* devops: Unstable session manager tests skipped

* chore: cleanup applied

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

2 of 8 new or added lines in 5 files covered. (25.0%)

268 existing lines in 20 files now uncovered.

12431 of 14858 relevant lines covered (83.67%)

71.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/includes/data/class-db-hooks.php
1
<?php
2
/**
3
 * Register hooks for the filtering DB queries.
4
 *
5
 * @package WPGraphQL\WooCommerce\Data
6
 * @since 0.14.0
7
 */
8

9
namespace WPGraphQL\WooCommerce\Data;
10

11
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
12

13
/**
14
 * Class DB_Hooks
15
 */
16
class DB_Hooks {
17
        /**
18
         * DB_Hooks constructor.
19
         */
20
        public function __construct() {
21
                add_filter( 'woocommerce_orders_table_query_clauses', [ $this, 'add_cursor' ], 10, 3 );
×
22
        }
23

24
        /**
25
         * Add the cursor to the WHERE clause of the query.
26
         *
27
         * @param string[]                                                            $clauses {
28
         *                                                        Associative array of the clauses for the query.
29
         *
30
         *     @type string $fields  The SELECT clause of the query.
31
         *     @type string $join    The JOIN clause of the query.
32
         *     @type string $where   The WHERE clause of the query.
33
         *     @type string $groupby The GROUP BY clause of the query.
34
         *     @type string $orderby The ORDER BY clause of the query.
35
         *     @type string $limits  The LIMIT clause of the query.
36
         * }
37
         * @param \Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableQuery $query The OrdersTableQuery instance (passed by reference).
38
         * @param array                                                               $args  Query args.
39
         *
40
         * @return string[]
41
         */
42
        public function add_cursor( $clauses, $query, $args ) {
43
                if ( true !== is_graphql_request() ) {
×
44
                        return $clauses;
×
45
                }
46

47
                /** @var \Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore $order_datastore */
48
                $order_datastore = wc_get_container()->get( OrdersTableDataStore::class );
×
49
                $tables          = $order_datastore::get_all_table_names_with_id();
×
50

51
                // apply the after cursor to the query.
52
                if ( ! empty( $args['graphql_after_cursor'] ) ) {
×
53
                        $after_cursor      = new Cursor\COT_Cursor( $args, $query, 'after' );
×
54
                        $clauses['where'] .= $after_cursor->get_where();
×
55
                }
56

57
                // apply the before cursor to the query.
58
                if ( ! empty( $args['graphql_before_cursor'] ) ) {
×
59
                        $before_cursor     = new Cursor\COT_Cursor( $args, $query, 'before' );
×
60
                        $clauses['where'] .= $before_cursor->get_where();
×
61
                }
62

63
                // If the cursor "graphql_cursor_compare" arg is not in the query,
64
                // default to using ID DESC as the stabilizer.
65
                $orderby = ! empty( $clauses['orderby'] ) && is_string( $clauses['orderby'] )
×
66
                        ? $clauses['orderby'] . ','
×
67
                        : '';
×
68

69
                if ( ! isset( $args['graphql_cursor_compare'] ) ) {
×
70
                        $clauses['orderby'] = "{$orderby} {$tables['orders']}.id DESC ";
×
71
                } else {
72
                        // Check the cursor compare order.
73
                        $order = '>' === $args['graphql_cursor_compare'] ? 'ASC' : 'DESC';
×
74

75
                        $clauses['orderby'] = "{$orderby} {$tables['orders']}.id {$order} ";
×
76
                }
77

78
                return $clauses;
×
79
        }
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc