Plugin Directory

Changeset 2888447


Ignore:
Timestamp:
03/28/2023 01:56:20 PM (3 years ago)
Author:
blockprotocol
Message:

update files in trunk to code for 0.0.6 release

Location:
blockprotocol/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • blockprotocol/trunk/block-protocol.php

    r2886540 r2888447  
    22/**
    33 * @package blockprotocol
    4  * @version 0.0.5
     4 * @version 0.0.6
    55 */
    66/*
     
    1010Author: Block Protocol
    1111Author URI: https://blockprotocol.org/?utm_medium=organic&utm_source=wordpress_plugin-directory_blockprotocol-plugin_author-name
    12 Version: 0.0.5
     12Version: 0.0.6
    1313Requires at least: 5.6.0
    1414Tested up to: 6.1.1
     
    1717*/
    1818
    19 const BLOCK_PROTOCOL_PLUGIN_VERSION = "0.0.5";
     19const BLOCK_PROTOCOL_PLUGIN_VERSION = "0.0.6";
    2020
    2121if (is_readable(__DIR__ . '/vendor/autoload.php')) {
  • blockprotocol/trunk/changelog.txt

    r2886540 r2888447  
    11== Changelog ==
     2
     3= 0.0.6 =
     4* Support older versions of MySQL (Minimum version is now 5.7.8 down from 8.0)
    25
    36= 0.0.5 =
  • blockprotocol/trunk/readme.txt

    r2886540 r2888447  
    66Tested up to: 6.1.1
    77Requires PHP: 7.4
    8 Stable tag: 0.0.5
     8Stable tag: 0.0.6
    99License: AGPL-3.0
    1010License URI: https://www.gnu.org/licenses/agpl-3.0.en.html
     
    3737**5.** If you want to add your own block to the plugin, visit https://blockprotocol.org/docs/developing-blocks
    3838
    39 Note that you must be using at least MySQL 8. To check please navigate to `Admin -> Tools -> Site Health -> Info -> Database`.
    40 The previous versions of MySQL (5.6 and 5.7) respectively reach(ed) end of life in February 2021 and October 2023.
    41 You should upgrade to MySQL 8 now to continue to receive security updates, as well as to use the Block Protocol within WordPress.
     39Note that you must be using at least MySQL 5.7.8. To check please navigate to `Admin -> Tools -> Site Health -> Info -> Database`.
     40MySQL 5.6 and 5.7 respectively reach(ed) end of life in February 2021 and October 2023.
     41You should upgrade to MySQL 8 now to continue to receive security updates, as well as to get the best Block Protocol experience within WordPress.
    4242
    4343When you install or use the _Block Protocol for WordPress_ plugin, we don’t send any data to any third-party analytics services.
     
    8585<!-- Only the latest release's entry should appear here – the full log should be in changelog.txt -->
    8686
    87 = 0.0.5 =
    88 * Handle blocks being inside an iFrame in editor view (fixes incompatibility with Gutenberg plugin)
     87= 0.0.6 =
     88* Support older versions of MySQL (Minimum version is now 5.7.8 down from 8.0)
    8989
    9090== Upgrade Notice ==
     
    9292<!-- Upgrade notices describe the reason a user should upgrade. No more than 300 characters. -->
    9393
    94 = 0.0.5 =
    95 Upgrade for compatibility with the Gutenberg plugin
     94= 0.0.6 =
     95Upgrade for support for older versions of MySQL (new minimum 5.7.8)
  • blockprotocol/trunk/server/block-api-endpoints.php

    r2882010 r2888447  
    2121}
    2222
    23 function get_block_protocol_subgraph(
    24   string $base_where_term,
    25   int $has_left_incoming_depth,
    26   int $has_right_incoming_depth,
    27   int $has_left_outgoing_depth,
    28   int $has_right_outgoing_depth
    29 )
    30 {
    31   global $wpdb;
    32 
    33   $table = get_block_protocol_table_name();
    34 
    35   $selection = "
     23function block_protocol_entity_selection()
     24{
     25  return "
    3626  entity_id,
    3727  entity_type_id,
     
    4535  updated_by_id,
    4636  updated_at";
     37
     38}
     39
     40/**
     41 * Natively traverse a subgraph using a base where term.
     42 * This functions is meant to be as compatible as possible with various MySQL/MariaDB versions
     43 */
     44function block_protocol_native_subgraph_query(
     45  string $base_where_term,
     46  int $has_left_incoming_depth,
     47  int $has_right_incoming_depth,
     48  int $has_left_outgoing_depth,
     49  int $has_right_outgoing_depth
     50) {
     51  global $wpdb;
     52
     53  $table = get_block_protocol_table_name();
     54
     55  $subgraph = [];
     56  $queue = [];
     57
     58  // Initial query using the base where term
     59  $selection = block_protocol_entity_selection();
     60  $sql = $wpdb->prepare("
     61    SELECT
     62      " . $selection . ",
     63      0 as has_left_incoming_depth,
     64      0 as has_right_incoming_depth,
     65      0 as has_left_outgoing_depth,
     66      0 as has_right_outgoing_depth
     67    FROM {$table}
     68    " . $base_where_term
     69  );
     70
     71  // Initialize the queue with the starting nodes
     72  $queue = $wpdb->get_results($sql, ARRAY_A);
     73
     74  $visited = [];
     75
     76  // Loop while the queue is not empty
     77  while (!empty($queue)) {
     78    // Dequeue the next node
     79    $node = array_shift($queue);
     80
     81    // Skip nodes that have already been visited
     82    if ($visited[$node['entity_id']] ?? false) {
     83        continue;
     84    }
     85
     86    $visited[$node['entity_id']] = true;
     87
     88    // ensure that the depths are all ints
     89    $node['has_left_incoming_depth'] = (int) $node['has_left_incoming_depth'];
     90    $node['has_right_incoming_depth'] = (int) $node['has_right_incoming_depth'];
     91    $node['has_left_outgoing_depth'] = (int) $node['has_left_outgoing_depth'];
     92    $node['has_right_outgoing_depth'] = (int) $node['has_right_outgoing_depth'];
     93
     94    // Add the node to the result list
     95    $subgraph[] = $node;
     96
     97    $next_nodes = [];
     98
     99    // Add nodes connected by incoming has_left links
     100    if ($node['has_left_incoming_depth'] < $has_left_incoming_depth) {
     101      $sql = $wpdb->prepare(
     102        "SELECT
     103          " . $selection . ",
     104          %d + 1 as has_left_incoming_depth,
     105          %d as has_right_incoming_depth,
     106          %d as has_left_outgoing_depth,
     107          %d as has_right_outgoing_depth
     108        FROM {$table}
     109        WHERE left_entity_id = %d
     110        ",
     111        $node['has_left_incoming_depth'],
     112        $node['has_right_incoming_depth'],
     113        $node["has_left_outgoing_depth"],
     114        $node["has_right_outgoing_depth"],
     115        $node['entity_id']
     116      );
     117
     118      $next_nodes = array_merge($next_nodes, $wpdb->get_results($sql, ARRAY_A));
     119    }
     120
     121    // Add nodes connected by incoming has_right links
     122    if ($node['has_right_incoming_depth'] < $has_right_incoming_depth) {
     123      $sql = $wpdb->prepare(
     124        "SELECT
     125          " . $selection . ",
     126          %d as has_left_incoming_depth,
     127          %d + 1 as has_right_incoming_depth,
     128          %d as has_left_outgoing_depth,
     129          %d as has_right_outgoing_depth
     130        FROM {$table}
     131        WHERE right_entity_id = %d
     132        ",
     133        $node['has_left_incoming_depth'],
     134        $node['has_right_incoming_depth'],
     135        $node["has_left_outgoing_depth"],
     136        $node["has_right_outgoing_depth"],
     137        $node['entity_id']
     138      );
     139
     140      $next_nodes = array_merge($next_nodes, $wpdb->get_results($sql, ARRAY_A));
     141    }
     142
     143    // Add nodes connected by outgoing has_left links
     144    if ($node['has_left_outgoing_depth'] < $has_left_outgoing_depth) {
     145      $sql = $wpdb->prepare(
     146        "SELECT
     147          " . $selection . ",
     148          %d as has_left_incoming_depth,
     149          %d as has_right_incoming_depth,
     150          %d + 1 as has_left_outgoing_depth,
     151          %d as has_right_outgoing_depth
     152        FROM {$table}
     153        WHERE entity_id = %d
     154        ",
     155        $node['has_left_incoming_depth'],
     156        $node['has_right_incoming_depth'],
     157        $node["has_left_outgoing_depth"],
     158        $node["has_right_outgoing_depth"],
     159        $node['left_entity_id']
     160      );
     161
     162      $next_nodes = array_merge($next_nodes, $wpdb->get_results($sql, ARRAY_A));
     163    }
     164
     165    // Add nodes connected by outgoing has_right links
     166    if ($node['has_right_outgoing_depth'] < $has_right_outgoing_depth) {
     167      $sql = $wpdb->prepare(
     168        "SELECT
     169          " . $selection . ",
     170          %d as has_left_incoming_depth,
     171          %d as has_right_incoming_depth,
     172          %d as has_left_outgoing_depth,
     173          %d + 1 as has_right_outgoing_depth
     174        FROM {$table}
     175        WHERE entity_id = %d
     176        ",
     177        $node['has_left_incoming_depth'],
     178        $node['has_right_incoming_depth'],
     179        $node["has_left_outgoing_depth"],
     180        $node["has_right_outgoing_depth"],
     181        $node['right_entity_id']
     182      );
     183
     184      $next_nodes = array_merge($next_nodes, $wpdb->get_results($sql, ARRAY_A));
     185    }
     186
     187    // Add the next nodes to the queue
     188    foreach ($next_nodes as $next_node)  {
     189      $entity_id = $next_node['entity_id'];
     190
     191      if (!($visited[$entity_id] ?? false)) {
     192        $queue[] = $next_node;
     193      }
     194    }
     195  }
     196
     197  foreach($subgraph as &$element) {
     198    unset($element["has_left_incoming_depth"]);
     199    unset($element["has_right_incoming_depth"]);
     200    unset($element["has_left_outgoing_depth"]);
     201    unset($element["has_right_outgoing_depth"]);
     202  }
     203
     204  return $subgraph;
     205}
     206
     207
     208/**
     209 * Traverse a subgraph using Recursive CTEs in the DB.
     210 * This functions is likely unsupported by older versions of the DB.
     211 */
     212function block_protocol_db_subgraph_query(
     213  string $base_where_term,
     214  int $has_left_incoming_depth,
     215  int $has_right_incoming_depth,
     216  int $has_left_outgoing_depth,
     217  int $has_right_outgoing_depth
     218)
     219{
     220  global $wpdb;
     221
     222  $table = get_block_protocol_table_name();
     223
     224  $selection = block_protocol_entity_selection();
    47225
    48226  $sql = $wpdb->prepare(
     
    78256        has_left_outgoing_depth,
    79257        has_right_outgoing_depth
    80     FROM {$table} e2 
    81     JOIN linked_entities 
     258    FROM {$table} e2
     259    JOIN linked_entities
    82260      ON e2.left_entity_id = linked_entities.entity_id
    83261    WHERE has_left_incoming_depth < %d
     
    102280        has_left_outgoing_depth,
    103281        has_right_outgoing_depth
    104     FROM {$table} e2 
    105     JOIN linked_entities 
     282    FROM {$table} e2
     283    JOIN linked_entities
    106284      ON e2.right_entity_id = linked_entities.entity_id
    107285    WHERE has_right_incoming_depth < %d
     
    126304        has_left_outgoing_depth +1,
    127305        has_right_outgoing_depth
    128     FROM {$table} e2 
    129     JOIN linked_entities 
     306    FROM {$table} e2
     307    JOIN linked_entities
    130308      ON e2.entity_id = linked_entities.left_entity_id
    131309    WHERE has_left_outgoing_depth < %d
     
    150328        has_left_outgoing_depth,
    151329        has_right_outgoing_depth + 1
    152     FROM {$table} e2 
    153     JOIN linked_entities 
     330    FROM {$table} e2
     331    JOIN linked_entities
    154332      ON e2.entity_id = linked_entities.right_entity_id
    155333    WHERE has_right_outgoing_depth < %d
     
    166344
    167345  $subgraph = $wpdb->get_results($sql, ARRAY_A);
     346
     347  return $subgraph;
     348}
     349
     350function get_block_protocol_subgraph(
     351  string $base_where_term,
     352  int $has_left_incoming_depth,
     353  int $has_right_incoming_depth,
     354  int $has_left_outgoing_depth,
     355  int $has_right_outgoing_depth
     356)
     357{
     358  global $wpdb;
     359  // See https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html
     360  $mysql_recursive_cte_version = "8.0";
     361  // See https://mariadb.com/kb/en/mariadb-1022-release-notes/#notable-changes
     362  $mariadb_recursive_cte_version = "10.2.2";
     363
     364  // Dynamically choose how to execute the query based on the database version
     365  $action =
     366    block_protocol_database_at_version(
     367      $mysql_recursive_cte_version,
     368      $mariadb_recursive_cte_version
     369    )
     370    ? "block_protocol_db_subgraph_query"
     371    : "block_protocol_native_subgraph_query";
     372
     373  $subgraph = ($action)(
     374    $base_where_term,
     375    $has_left_incoming_depth,
     376    $has_right_incoming_depth,
     377    $has_left_outgoing_depth,
     378    $has_right_outgoing_depth,
     379  );
    168380
    169381  block_protocol_maybe_capture_error($wpdb->last_error);
  • blockprotocol/trunk/server/block-db-table.php

    r2882010 r2888447  
    11<?php
    22
    3 const BLOCK_PROTOCOL_MINIMUM_MYSQL_VERSION = "8.0.0";
     3const BLOCK_PROTOCOL_MINIMUM_MYSQL_VERSION = "5.7.8";
    44const BLOCK_PROTOCOL_MINIMUM_MARIADB_VERSION = "10.2.7";
    55
    6 function block_protocol_is_database_supported()
     6function block_protocol_database_at_version(string $mysql_version, string $mariadb_version)
    77{
     8
    89  global $wpdb;
    910 
     
    1314  if (strpos($db_server_info, 'MariaDB') != false) {
    1415    // site is using MariaDB
    15     return $db_version >= BLOCK_PROTOCOL_MINIMUM_MARIADB_VERSION;
     16    return strnatcmp($db_version, $mariadb_version) > 0;
    1617  } else {
    1718    // site is using MySQL
    18     return $db_version >= BLOCK_PROTOCOL_MINIMUM_MYSQL_VERSION;
     19    return strnatcmp($db_version, $mysql_version) > 0;
    1920  }
     21}
     22
     23function block_protocol_is_database_supported()
     24{
     25  return block_protocol_database_at_version(
     26    BLOCK_PROTOCOL_MINIMUM_MYSQL_VERSION,
     27    BLOCK_PROTOCOL_MINIMUM_MARIADB_VERSION
     28  );
    2029}
    2130
     
    5564}
    5665
     66function block_protocol_set_migration_version_to(int $migration_version)
     67{
     68  global $wpdb;
     69
     70  if (!$wpdb->last_error){
     71    update_site_option('block_protocol_db_migration_version', $migration_version);
     72  }
     73}
     74
    5775function block_protocol_migrate()
    5876{
     
    6684  if ($saved_version < 2) {
    6785    block_protocol_migration_1();
    68     update_site_option('block_protocol_db_migration_version', 2);
     86    block_protocol_set_migration_version_to(2);
    6987  }
    7088
  • blockprotocol/trunk/vendor/composer/autoload_psr4.php

    r2886540 r2888447  
    1515    'Sentry\\' => array($vendorDir . '/sentry/sentry/src'),
    1616    'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
    17     'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src', $vendorDir . '/psr/http-factory/src'),
     17    'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-factory/src', $vendorDir . '/psr/http-message/src'),
    1818    'Psr\\Http\\Client\\' => array($vendorDir . '/psr/http-client/src'),
    1919    'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
    2020    'Jean85\\' => array($vendorDir . '/jean85/pretty-package-versions/src'),
    2121    'Http\\Promise\\' => array($vendorDir . '/php-http/promise/src'),
    22     'Http\\Message\\' => array($vendorDir . '/php-http/message-factory/src', $vendorDir . '/php-http/message/src'),
     22    'Http\\Message\\' => array($vendorDir . '/php-http/message/src', $vendorDir . '/php-http/message-factory/src'),
    2323    'Http\\Factory\\Guzzle\\' => array($vendorDir . '/http-interop/http-factory-guzzle/src'),
    2424    'Http\\Discovery\\' => array($vendorDir . '/php-http/discovery/src'),
  • blockprotocol/trunk/vendor/composer/autoload_static.php

    r2886540 r2888447  
    9595        'Psr\\Http\\Message\\' =>
    9696        array (
    97             0 => __DIR__ . '/..' . '/psr/http-message/src',
    98             1 => __DIR__ . '/..' . '/psr/http-factory/src',
     97            0 => __DIR__ . '/..' . '/psr/http-factory/src',
     98            1 => __DIR__ . '/..' . '/psr/http-message/src',
    9999        ),
    100100        'Psr\\Http\\Client\\' =>
     
    116116        'Http\\Message\\' =>
    117117        array (
    118             0 => __DIR__ . '/..' . '/php-http/message-factory/src',
    119             1 => __DIR__ . '/..' . '/php-http/message/src',
     118            0 => __DIR__ . '/..' . '/php-http/message/src',
     119            1 => __DIR__ . '/..' . '/php-http/message-factory/src',
    120120        ),
    121121        'Http\\Factory\\Guzzle\\' =>
  • blockprotocol/trunk/vendor/composer/installed.php

    r2886540 r2888447  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '0cfe96ccb03939381934792c133c29a90db1ff14',
     6        'reference' => '73f2ebf03d03a41d55d3ab999e367d0fd7ca22c2',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '0cfe96ccb03939381934792c133c29a90db1ff14',
     16            'reference' => '73f2ebf03d03a41d55d3ab999e367d0fd7ca22c2',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.