Merge pull request #18939 from colemanw/serializeFix
[civicrm-core.git] / CRM / Core / BAO / SchemaHandler.php
index 5f54af1478f1fa8c4a962d8c350dc30a79514db5..52f08c45139e7492abab4dc3a8bf1ecaa8a27401 100644 (file)
@@ -899,7 +899,7 @@ MODIFY      {$columnName} varchar( $length )
    *
    * @return string
    */
-  public static function getInUseCollation() {
+  public static function getInUseCollation(): string {
     if (!isset(\Civi::$statics[__CLASS__][__FUNCTION__])) {
       $dao = CRM_Core_DAO::executeQuery('SHOW TABLE STATUS LIKE \'civicrm_contact\'');
       $dao->fetch();
@@ -908,6 +908,23 @@ MODIFY      {$columnName} varchar( $length )
     return \Civi::$statics[__CLASS__][__FUNCTION__];
   }
 
+  /**
+   * Does the database support utf8mb4.
+   *
+   * Utf8mb4 is required to support emojis but older databases may not have it enabled.
+   *
+   * This is aggressively cached despite just being a string function
+   * as it is expected it might be called many times.
+   *
+   * @return bool
+   */
+  public static function databaseSupportsUTF8MB4(): bool {
+    if (!isset(\Civi::$statics[__CLASS__][__FUNCTION__])) {
+      \Civi::$statics[__CLASS__][__FUNCTION__] = stripos(self::getInUseCollation(), 'utf8mb4') === TRUE;
+    }
+    return \Civi::$statics[__CLASS__][__FUNCTION__];
+  }
+
   /**
    * Get the database collation.
    *