Skip to content

Commit

Permalink
fix: allow smooth taxonomy update
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanveen committed Oct 28, 2023
1 parent ac42401 commit ea969c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion faq-with-categories/faq-with-categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
defined( 'ABSPATH' ) or die();
const RUIGEHOND010_VERSION = '1.2.0';
// This is plugin nr. 10 by ruige hond. It identifies with: ruigehond010.
if ( ! class_exists( 'ruigehond_0_4_0\ruigehond', false ) ) {
if ( ! class_exists( 'ruigehond_0_4_1\ruigehond', false ) ) {
include_once( dirname( __FILE__ ) . '/includes/ruigehond.php' ); // base class
}
include_once( dirname( __FILE__ ) . '/includes/ruigehond010.php' );
Expand Down
7 changes: 4 additions & 3 deletions faq-with-categories/includes/ruigehond.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function ruigehond_activation_error() {
}
}

namespace ruigehond_0_4_0 {
namespace ruigehond_0_4_1 {

use stdClass;

Expand Down Expand Up @@ -252,7 +252,7 @@ public function postExists( int $id ): bool {
public function insertDb( string $table_name, array $values ): int {
$rows_affected = $this->wpdb->insert( $table_name, $values );
if ( 1 === $rows_affected ) {
return $this->wpdb->insert_id; // var holds the last inserted id
return $this->wpdb->insert_id ?: PHP_INT_MAX; // var holds the last inserted id
} else {
return 0;
}
Expand All @@ -264,6 +264,7 @@ public function insertDb( string $table_name, array $values ): int {
* @param array $where
*
* @return int 0 on failure, > 0 is the insert id, < 0 is the number of rows affected for update
* return value will be PHP_INT_MAX when insert succeeded, but there was no id column updated
*/
public function upsertDb( string $table_name, array $values, array $where ): int {
$where_condition = 'WHERE 1 = 1';
Expand Down Expand Up @@ -403,4 +404,4 @@ public function __construct( $text, $data = null ) {
// if data is null it means javascript doesn't have to send anything back
}
}
} // end of namespace ruigehond_0_4_0
} // end of namespace ruigehond_0_4_1
11 changes: 6 additions & 5 deletions faq-with-categories/includes/ruigehond010.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace ruigehond010;

// TODO BUG if you put central faq short_code or any exclusive tag on multiple pages, the $on option keeps getting updated
use ruigehond_0_4_0;
use ruigehond_0_4_1;

defined( 'ABSPATH' ) or die();

class ruigehond010 extends ruigehond_0_4_0\ruigehond {
class ruigehond010 extends ruigehond_0_4_1\ruigehond {
private $name, $database_version, $taxonomies, $slug, $choose_option, $choose_all, $search_faqs, $table_prefix,
$more_button_text, $no_results_warning, $max, $max_ignore_elsewhere,
$order_table, $header_tag,
Expand Down Expand Up @@ -420,6 +420,7 @@ public function getHtmlForFrontend( $attributes = [], $content = null, $short_co
}

private function getTerms(): array {
// TODO have o.o sort the same for 1 as null
if ( true === isset( $this->terms ) ) {
return $this->terms;
} // return cached value if available
Expand All @@ -436,7 +437,7 @@ private function getTerms(): array {
LEFT OUTER JOIN {$wp_prefix}term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy = '$taxonomies'
GROUP BY t.term_id, tt.parent, t.name, o.t, o.post_id, o.o
ORDER BY o.o, t.name;";
ORDER BY tt.parent, COALESCE(o.o, 1), t.name;";
$rows = $this->wpdb->get_results( $sql, OBJECT );
$terms = array();
foreach ( $rows as $key => $row ) {
Expand Down Expand Up @@ -518,7 +519,7 @@ private function getPosts( $exclusive = null, $term = null ): array {
return $return_arr;
}

public function handle_input( $args ): ruigehond_0_4_0\returnObject {
public function handle_input( $args ): ruigehond_0_4_1\returnObject {
$returnObject = $this->getReturnObject();
$wp_prefix = $this->wpdb->prefix;
if ( isset( $args['id'] ) ) {
Expand Down Expand Up @@ -588,7 +589,7 @@ public function handle_input( $args ): ruigehond_0_4_0\returnObject {
"$this->table_prefix$table_name", $update,
array( $id_column => $id ) );
if ( 0 === $rows_affected ) {
$returnObject->add_message( __( 'Not updated', 'faq-with-categories' ) );
$returnObject->add_message( __( 'Not updated', 'faq-with-categories' ), 'warn' );
} else {
$returnObject->set_success( true );
$args['value'] = $this->wpdb->get_var(
Expand Down

0 comments on commit ea969c9

Please sign in to comment.