ProtectedPagesStorage::insertProtectedPage() returns wrong type

Created on 20 June 2023, over 1 year ago

Problem/Motivation

The documentation of ProtectedPagesStorage::insertProtectedPage() specifies that the method should return an integer:

  /**
   * Insert data into protected pages table.
   *
   * @param array $page_data
   *   An array containing all values.
   *
   * @return int
   *   The protected page id.
   */
  public function insertProtectedPage(array $page_data);

However it blindly returns the query result without checking the type. The default MySQL database driver returns string results.

Steps to reproduce

  1. Install Drupal using the default MySQL database connection.
  2. Enable the Protected Pages module.
  3. Execute the following command:

    $ drush eval "print(gettype(\Drupal::service('protected_pages.storage')->insertProtectedPage(['password' => 'test', 'path' => '/mypath'])))"

Expected result: integer
Actual result: string

Proposed resolution

Cast the query result to an integer before returning it.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇧🇬Bulgaria pfrenssen Sofia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024