Skip to content

Commit

Permalink
More verbose error reporting for shortcodes, and dependency updates
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson committed Nov 28, 2016
1 parent 6c6b359 commit 0133727
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 49 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ php:
- "7.0"

# WordPress versions to be tested against.
# Include the highest patch versions of the last 3 versions (including the current one), as well as master.
env:
- WP_VERSION=4.3.5
- WP_VERSION=4.4.4
- WP_VERSION=4.5.3
- WP_VERSION=4.4.5
- WP_VERSION=4.5.4
- WP_VERSION=4.6.1
- WP_VERSION=master

# Clones WordPress and configures our testing environment.
Expand Down
3 changes: 3 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ form.tabulate-schema td.primary-key,
form.tabulate-schema td.unique { text-align:center }
form.tabulate-schema td.reorder { font-size:smaller; white-space:nowrap }
form.tabulate-schema td.reorder a.move { }

.tabulate.shortcode-error { border:1px solid #ccc; padding:0.5em }
.tabulate.shortcode-error .message { color:red }
42 changes: 21 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
project = u'Tabulate for WordPress'
copyright = u'2016, Sam Wilson'
version = '2.7'
release = '2.7.13'
release = '2.7.14'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
25 changes: 18 additions & 7 deletions src/Controllers/ShortcodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,24 @@ public function __construct( $wpdb ) {
/**
* Substitute the Shortcode with the relevant formatted output.
*
* @param string[] $atts The shortcode attributes.
* @param string[] $raw_attrs The shortcode attributes.
* @return string
*/
public function run( $atts ) {
public function run( $raw_attrs ) {
$defaults = array(
'format' => 'table',
'table' => null,
'ident' => null,
'search' => null,
);
$attrs = shortcode_atts( $defaults, $atts );
$attrs = shortcode_atts( $defaults, $raw_attrs );
if ( ! isset( $attrs['table'] ) ) {
return $this->error( "The 'table' attribute must be set." );
$msg = "The 'table' attribute must be set. Attributes found: [";
foreach ( $raw_attrs as $k => $v ) {
$msg .= ' ' . htmlentities2( $k ) .' = "' . htmlentities2( $v ) . '" ';
}
$msg .= "]";
return $this->error( $msg );
}
$table = $this->db->get_table( $attrs['table'] );
if ( ! $table ) {
Expand All @@ -73,13 +78,19 @@ public function run( $atts ) {
}

/**
* Get an error message, and dequeue scripts.
* It's too late now to dequeue styles.
* Get a formatted error message.
*
* @param string $message The error message to display.
* @return string The error HTML.
*/
protected function error( $message = '' ) {
return "<div class='tabulate shortcode-error'>$message</div>";
$url = "http://tabulate.readthedocs.io/en/latest/shortcode.html";
return "<div class='tabulate shortcode-error'>"
. "<h3>Tabulate shortcode error:</h3> "
. "<p class='message'>$message</p>"
. "<p>For more information, please "
. "<a href='$url' target='_blank' title='Opens in new tab'>read the docs</a>."
. "</p></div>";
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/DB/Grants.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class Grants {
*/
const ANON_ROLE = 'anon';

/**
* The name of the option under which grants are saved. Is always 'tabulate_grants'.
*
* @var string
*/
private $option_name;

/**
Expand Down
6 changes: 5 additions & 1 deletion src/DB/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ public static function report_sources_table_name() {
public function get_template( $report_id ) {
// Find the report.
$reports = $this->db->get_table( self::reports_table_name() );
if ( false === $reports ) {
$msg = "Reports table not found. Please re-activate Tabulate to create it.";
throw new Exception( $msg );
}
$report = $reports->get_record( $report_id );
if ( ! $report ) {
if ( false === $report ) {
throw new Exception( "Report $report_id not found." );
}
$template = new \WordPress\Tabulate\Template( false, $report->template() );
Expand Down
30 changes: 15 additions & 15 deletions src/DB/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,22 @@ public function apply_filters( &$sql ) {
$f_column = "`" . $this->get_name() . "`.`$f_column`";
}

// LIKE or NOT LIKE.
if ( 'like' === $filter['operator'] || 'not like' === $filter['operator'] ) {
// LIKE or NOT LIKE.
$where_clause .= " AND CONVERT($f_column, CHAR) " . strtoupper( $filter['operator'] ) . " %s ";
$params[ $param_name ] = '%' . trim( $filter['value'] ) . '%';
} // Equals or does-not-equal
elseif ( '=' === $filter['operator'] || '!=' === $filter['operator'] ) {
} elseif ( '=' === $filter['operator'] || '!=' === $filter['operator'] ) {
// Equals or does-not-equal.
$where_clause .= " AND $f_column " . $filter['operator'] . " %s ";
$params[ $param_name ] = trim( $filter['value'] );
} // IS EMPTY
elseif ( 'empty' === $filter['operator'] ) {
} elseif ( 'empty' === $filter['operator'] ) {
// IS EMPTY.
$where_clause .= " AND ($f_column IS NULL OR $f_column = '')";
} // IS NOT EMPTY
elseif ( 'not empty' === $filter['operator'] ) {
} elseif ( 'not empty' === $filter['operator'] ) {
// IS NOT EMPTY.
$where_clause .= " AND ($f_column IS NOT NULL AND $f_column != '')";
} // IN or NOT IN
elseif ( 'in' === $filter['operator'] || 'not in' === $filter['operator'] ) {
} elseif ( 'in' === $filter['operator'] || 'not in' === $filter['operator'] ) {
// IN or NOT IN.
$placeholders = array();
foreach ( Util::split_newline( $filter['value'] ) as $vid => $val ) {
$placeholders[] = "%s";
Expand All @@ -322,14 +322,14 @@ public function apply_filters( &$sql ) {
}
$negate = ( 'not in' === $filter['operator'] ) ? 'NOT' : '';
$where_clause .= " AND ($f_column $negate IN (" . join( ", ", $placeholders ) . "))";
} // Other operators. They're already validated in self::addFilter().
else {
} else {
// Other operators. They're already validated in self::addFilter().
$where_clause .= " AND ($f_column " . $filter['operator'] . " %s)";
$params[ $param_name ] = trim( $filter['value'] );
}
} // End if().

$param_num++;
} // end foreach filter.
} // End foreach().

// Add clauses into SQL.
if ( ! empty( $where_clause ) ) {
Expand Down Expand Up @@ -1175,8 +1175,8 @@ public function save_record( $data, $pk_value = null ) {
// Everything else.
$sql_values[ $field ] = "'" . esc_sql( $value ) . "'";

}
}
} // End if().
} // End foreach().

// Find the PK, and hide errors (for now).
$pk_name = $this->get_pk_column()->get_name();
Expand Down
2 changes: 1 addition & 1 deletion tabulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Version: 2.7.13
*/

define( 'TABULATE_VERSION', '2.7.13' );
define( 'TABULATE_VERSION', '2.7.14' );
define( 'TABULATE_SLUG', 'tabulate' );

// Load textdomain.
Expand Down

0 comments on commit 0133727

Please sign in to comment.