I was trying to add a unit to a node of a content type on which bee is enabled, and got this error (in the log, no message at all on the screen indicating that adding the unit was not successful):

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1: INSERT INTO {unit} (type, uuid, uid, unit_type_id, name, langcode, created, changed, status) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => default [:db_insert_placeholder_1] => d3e72b6e-7584-4230-bce3-9acd6138ee1f [:db_insert_placeholder_2] => 12 [:db_insert_placeholder_3] => 2 [:db_insert_placeholder_4] => A very long title that is longer than 50 characters 1 [:db_insert_placeholder_5] => nl [:db_insert_placeholder_6] => 1555179012 [:db_insert_placeholder_7] => 1555179012 [:db_insert_placeholder_8] => 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->doSaveFieldItems() (regel 864 van core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorage.php).

Note that (probably due to some mysql setting) data was not truncated, the insert just failed. So apparently, the name of the units created may have to be shortened beforehand to fit into the name field of the unit table.

I used this code to solve it (already without using the (D8.6) deprecated Unicode::strlen() and Unicode::substr()) (bee.module, function bee_node_add_more_units_submit()):

      $name = ' ' . (count($units_ids) + 1);
      $name = mb_substr($node->label(), 0, 50 - mb_strlen($name)) . $name;
      $bat_unit = bat_unit_create(
        [
          'name' => $name,
          'type' => 'default',
          'unit_type_id' => $bee_settings['type_id'],
        ]
      );
      bat_unit_save($bat_unit);

I am not sure if there are other places where the same error might be triggered.

Comments

fietserwin created an issue. See original summary.

  • nicola85 committed 3021445 on 8.x-1.x
    Issue #3047962: Unit names need to be truncated if node name is too long
    

acrollet credited nicola85.

acrollet’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.