While testing a recent media upgrade we noted this error when randomly uploading cat videos. Any that happen to have emojis in the title throw an sql-error.

https://www.youtube.com/watch?v=P2RkTCHTLbY
https://www.youtube.com/watch?v=-x7GjsfGvLE

The following error appears:

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x98\xB9 F...' for column 'filename' at row 1
Notice: Undefined index: upload in file_entity_add_upload_submit() (line 349 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.pages.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 175 of /home/rcaoj/www/includes/entity.inc).
Notice: Trying to get property of non-object in file_entity_file_type() (line 45 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.file.inc).
Notice: Trying to get property of non-object in file_entity_file_type() (line 45 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.file.inc).
Notice: Trying to get property of non-object in file_entity_file_type() (line 45 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.file.inc).
Notice: Trying to get property of non-object in file_entity_file_type() (line 45 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.file.inc).
Notice: Undefined index: upload in file_entity_add_upload_submit() (line 349 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.pages.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 175 of /home/rcaoj/www/includes/entity.inc).
Notice: Trying to get property of non-object in file_entity_file_is_writeable() (line 2232 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.module).
Notice: Trying to get property of non-object in file_entity_add_upload_submit() (line 379 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.pages.inc).
Notice: Undefined index: upload in file_entity_add_upload_submit() (line 405 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.pages.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 175 of /home/rcaoj/www/includes/entity.inc).
Notice: Undefined index: upload in file_entity_add_upload_submit() (line 430 of /home/rcaoj/www/sites/all/modules/file_entity/file_entity.pages.inc).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 175 of /home/rcaoj/www/includes/entity.inc).
An error occurred and no file was uploaded.

I have verified this error with a clean install of media_youtube 7.x-3.4 w/ Drupal 7.55 on simplytest.me

Contrib Dependencies installed:

  • File Entity 7.x-2.2
  • Media 7.x-2.8

Comments

afoster created an issue. See original summary.

steinmb’s picture

Category: Bug report » Support request

First make sure you got - https://www.drupal.org/node/2754539 working.

reszli’s picture

In my case, it was not possible to achieve Multi-byte UTF-8 support on the server, so I needed to work around it
My solution was to replace the original YouTube provider with a custom one that extends the original one and strips non-ASCII characters from the filename on preSave() method.

add these hook implementations to mymodule.module file

/**
 * Implements hook_media_internet_providers_alter().
 */
function mymodule_media_media_internet_providers_alter(&$providers) {
  unset($providers['MediaInternetYouTubeHandler']);
}

/**
 * Implements hook_media_internet_providers().
 */
function mymodule_media_media_internet_providers() {
  return [
    'MymoduleMediaInternetYouTubeHandler' => [
      'title' => t('YouTube'),
      'module' => 'mymodule',
      'weight' => 3,
    ],
  ];
}

create a new file under mymodule/includes/MymoduleMediaInternetYouTubeHandler.inc with the following content:


/**
 * @file
 * Extends the MediaInternetYouTubeHandler class to handle YouTube videos.
 */

/**
 * Implementation of MediaInternetBaseHandler.
 *
 * @see hook_media_internet_providers().
 */
class MymoduleMediaInternetYouTubeHandler extends MediaInternetYouTubeHandler {

  /**
   * Before the file has been saved, implementors may do additional operations.
   *
   * @param object $file_obj
   */
  public function preSave(&$file_obj) {
    parent::preSave($file_obj);
    // Remove non-ASCII characters from the filename.
    $file_obj->filename = trim(preg_replace('/[^\x20-\x7E]/','', $file_obj->filename));
  }

}
steinmb’s picture

Title: Youtube videos with emjois in title cause SQL-errors ;( » Youtube videos with emjois in title cause SQL-errors if multi-byte UTF-8 support is not enabled
Version: 7.x-3.4 » 7.x-3.x-dev
Status: Active » Fixed

That should work :) - I'll going to close this. Only one post in 6 years :)

Status: Fixed » Closed (fixed)

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