Skip to content

Commit 4814fab

Browse files
authored
CRM: 3416 - SQLite + WP Playground compatibility tweaks (#35201)
* SQLite translation requires second param on WEEK * Set permalinks in blueprint * Add changelog * Support non-pretty permalink calls to REST API * Update changelog
1 parent dd98e6f commit 4814fab

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

projects/plugins/crm/.wordpress-org/blueprints/blueprint.json

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"step": "login",
1111
"username": "admin",
1212
"password": "password"
13+
},
14+
{
15+
"step": "runPHP",
16+
"code": "<?php require_once 'wordpress/wp-load.php'; global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules();"
1317
}
1418
]
1519
}

projects/plugins/crm/admin/dashboard/dashboard.ajax.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function jetpackcrm_dash_refresh() {
7676
$sql = $wpdb->prepare( 'SELECT count(ID) as count, zbsc_created as ts, MONTH(FROM_UNIXTIME(zbsc_created)) as month, YEAR(FROM_UNIXTIME(zbsc_created)) as year FROM ' . $ZBSCRM_t['contacts'] . ' WHERE zbsc_created > %d AND zbsc_created < %d GROUP BY month, year ORDER BY year, month', $start_date, $end_date ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
7777
$monthly = $wpdb->get_results( $sql );
7878

79-
$sql = $wpdb->prepare( 'SELECT count(ID) as count, zbsc_created as ts, WEEK(FROM_UNIXTIME(zbsc_created)) as week, YEAR(FROM_UNIXTIME(zbsc_created)) as year FROM ' . $ZBSCRM_t['contacts'] . ' WHERE zbsc_created > %d AND zbsc_created < %d GROUP BY week, year ORDER BY year, week', $start_date, $end_date ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
79+
$sql = $wpdb->prepare( 'SELECT count(ID) as count, zbsc_created as ts, WEEK(FROM_UNIXTIME(zbsc_created), 1) as week, YEAR(FROM_UNIXTIME(zbsc_created)) as year FROM ' . $ZBSCRM_t['contacts'] . ' WHERE zbsc_created > %d AND zbsc_created < %d GROUP BY week, year ORDER BY year, week', $start_date, $end_date ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
8080
$weekly = $wpdb->get_results( $sql );
8181

8282
$sql = $wpdb->prepare( 'SELECT count(ID) as count, zbsc_created as ts, DAY(FROM_UNIXTIME(zbsc_created)) as day, MONTH(FROM_UNIXTIME(zbsc_created)) as month, YEAR(FROM_UNIXTIME(zbsc_created)) as year FROM ' . $ZBSCRM_t['contacts'] . ' WHERE zbsc_created > %d AND zbsc_created < %d GROUP BY day, month, year ORDER BY year, month, day', $start_date, $end_date ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Dashboard: Adjust queries for SQLite compatibility.
5+
REST API: Allow calls when not using pretty permalinks.

projects/plugins/crm/includes/ZeroBSCRM.CustomerFilters.php

+24-9
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ function zeroBSCRM_CustomerTypeList( $jsCallbackFuncStr = '', $inputDefaultValue
5050
global $haszbscrmBHURLCustomersOut;
5151
if ( ! isset( $haszbscrmBHURLCustomersOut ) ) {
5252

53-
// cachebusting for now... (ESP needed when migrating from DAL1 -> DAL2)
53+
$nonce = wp_create_nonce( 'wp_rest' );
54+
$rest_base_url = get_rest_url();
5455

55-
$cacheBusterStr = '&time=' . time();
56+
// handle bare permalink structure
57+
if ( empty( get_option( 'permalink_structure' ) ) ) {
58+
$param_separator = '&';
59+
} else {
60+
$param_separator = '?';
61+
}
62+
$rest_url = $rest_base_url . 'zbscrm/v1/contacts' . $param_separator . '_wpnonce=' . $nonce;
63+
64+
$ret .= '<script type="text/javascript">var zbscrmBHURLCustomers = "' . $rest_url . '";</script>';
5665

57-
// change to proper WP REST (not cached) and wont be impacted by setup connection issues. Is also the "proper" way to do it
58-
$nonce = wp_create_nonce( 'wp_rest' );
59-
$rest_url = esc_url( get_rest_url() . 'zbscrm/v1/contacts?_wpnonce=' . $nonce );
60-
$ret .= '<script type="text/javascript">var zbscrmBHURLCustomers = "' . $rest_url . '";</script>';
6166
$haszbscrmBHURLCustomersOut = true;
6267
}
6368

@@ -125,9 +130,19 @@ function zeroBSCRM_CompanyTypeList( $jsCallbackFuncStr = '', $inputDefaultValue
125130
global $haszbscrmBHURLCompaniesOut;
126131
if ( ! isset( $haszbscrmBHURLCompaniesOut ) ) {
127132

128-
$nonce = wp_create_nonce( 'wp_rest' );
129-
$rest_url = esc_url( get_rest_url() . 'zbscrm/v1/companies?_wpnonce=' . $nonce );
130-
$ret .= '<script type="text/javascript">var zbscrmBHURLCompanies = "' . $rest_url . '";</script>';
133+
$nonce = wp_create_nonce( 'wp_rest' );
134+
$rest_base_url = get_rest_url();
135+
136+
// handle bare permalink structure
137+
if ( empty( get_option( 'permalink_structure' ) ) ) {
138+
$param_separator = '&';
139+
} else {
140+
$param_separator = '?';
141+
}
142+
$rest_url = $rest_base_url . 'zbscrm/v1/companies' . $param_separator . '_wpnonce=' . $nonce;
143+
144+
$ret .= '<script type="text/javascript">var zbscrmBHURLCompanies = "' . $rest_url . '";</script>';
145+
131146
$haszbscrmBHURLCompaniesOut = true;
132147
}
133148

projects/plugins/crm/js/ZeroBSCRM.admin.invoicebuilder.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,8 @@ function zbscrm_JS_calculatediscount() {
16631663
*/
16641664
function zbscrm_JS_invoice_typeahead_bind() {
16651665
// endpoint - pass nonce this was as before send wasn't working weirdly in Bloodhound.
1666-
endpoint = wpApiSettings.root + 'zbscrm/v1/concom?_wpnonce=' + wpApiSettings.nonce;
1666+
param_separator = wpApiSettings.root.indexOf('?rest_route=/') === -1 ? '?' : '&';
1667+
endpoint = wpApiSettings.root + 'zbscrm/v1/concom' + param_separator + '_wpnonce=' + wpApiSettings.nonce;
16671668

16681669
var zbsInvoiceTo = new Bloodhound( {
16691670
datumTokenizer: function ( d ) {
@@ -1687,7 +1688,7 @@ function zbscrm_JS_invoice_typeahead_bind() {
16871688
},
16881689
remote: {
16891690
// this checks when users type, via ajax search ... useful addition to (cached) prefetch
1690-
url: wpApiSettings.root + 'zbscrm/v1/concom?_wpnonce=' + wpApiSettings.nonce + '&s=%QUERY',
1691+
url: wpApiSettings.root + 'zbscrm/v1/concom' + param_separator + '_wpnonce=' + wpApiSettings.nonce + '&s=%QUERY',
16911692
wildcard: '%QUERY',
16921693
},
16931694
} );

0 commit comments

Comments
 (0)