Skip to content

Commit

Permalink
see #1704 and #1705: updated funtionality for the jsonld
Browse files Browse the repository at this point in the history
  • Loading branch information
mykytadudariev committed Aug 21, 2023
1 parent 91e4b65 commit 41eaa7d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Wordlift\Assertions;
use Wordlift\Content\Content_Service;
use Wordlift\Jsonld\Jsonld_Utils;
use Wordlift\Object_Type_Enum;
use Wordlift_Configuration_Service;

Expand Down Expand Up @@ -79,7 +80,7 @@ public function set_about_jsonld( $content_id, $value ) {

// Cleanup value.
$value = ( is_string( $value ) && strlen( $value ) > 2 ) ? $value : null;
$match_name = $this->get_match_name( $value );
$match_name = Jsonld_Utils::get_about_match_name( $value );

// This `hack` is necessary to ensure the entity exists in the entities table, but we
// should revise how this works really.
Expand Down Expand Up @@ -123,18 +124,4 @@ public function set_about_jsonld( $content_id, $value ) {

return $wpdb->query( $wpdb->prepare( $query, $params ) );
}

/**
* @param $jsonld
*
* @return mixed|null
*/
public function get_match_name( $jsonld ) {
$data = json_decode( $jsonld, true );
if ( ! $data || ! array_key_exists( 'name', $data ) ) {
return null;
}

return $data['name'];
}
}
22 changes: 22 additions & 0 deletions src/classes/jsonld/class-jsonld-utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Wordlift\Jsonld;

class Jsonld_Utils {

/**
* Get about match name value
*
* @param $jsonld
*
* @return mixed|null
*/
public static function get_about_match_name( $jsonld ) {
$data = json_decode( $jsonld, true );
if ( ! $data || ! array_key_exists( 'name', $data ) ) {
return null;
}

return $data['name'];
}
}
20 changes: 2 additions & 18 deletions src/install/class-wordlift-install-3-50-1.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Wordlift\Cache\Ttl_Cache;
use Wordlift\Jsonld\Jsonld_Utils;

/**
* @since 3.49.1
Expand Down Expand Up @@ -57,7 +57,7 @@ public function install() {

// Update 'match_name' for each row
foreach ( $results as $row ) {
$match_name = $this->get_match_name( $row['about_jsonld'] );
$match_name = Jsonld_Utils::get_about_match_name( $row['about_jsonld'] );

if ( is_null( $match_name ) ) {
continue;
Expand All @@ -70,20 +70,4 @@ public function install() {
);
}
}

/**
* Get match name
*
* @param $jsonld
*
* @return mixed|null
*/
public function get_match_name( $jsonld ) {
$data = json_decode( $jsonld, true );
if ( ! $data || ! array_key_exists( 'name', $data ) ) {
return null;
}

return $data['name'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ public function __construct( $request, $cursor, $cursor_sort, $limit ) {
$this->has_match();
$this->term_contains();
$this->taxonomies();
$this->group_by();
$this->sort();
$this->limit();

$this->sql = " GROUP BY t.term_id";
}

public function get_results() {
Expand Down Expand Up @@ -122,6 +121,10 @@ private function has_match() {
}
}

private function group_by() {
$this->sql .= ' GROUP BY t.term_id';
}

private function sort() {
switch ( $this->direction . '$' . $this->sort ) {
case 'ASCENDING$ASC':
Expand Down

0 comments on commit 41eaa7d

Please sign in to comment.