history.section autofill should not be case sensitive #1813

Closed
opened 2026-10-05 00:57:38 +02:00 by adam · 0 comments
Owner

In this code (include/functions.inc.php function pwg_log:

  // If plugin developers add their own sections, Piwigo will automatically add it in the history.section enum column
  if (isset($page['section']))
  {
    // set cache if not available
    if (!isset($conf['history_sections_cache']))
    {
      conf_update_param('history_sections_cache', get_enums(HISTORY_TABLE, 'section'), true);
    }

    $conf['history_sections_cache'] = safe_unserialize($conf['history_sections_cache']);

    if (in_array($page['section'], $conf['history_sections_cache']))
    {
      $section = $page['section'];
    }
    elseif (preg_match('/^[a-zA-Z0-9_-]+$/', $page['section']))
    {
      $history_sections = get_enums(HISTORY_TABLE, 'section');
      $history_sections[] = $page['section'];

      // alter history table structure, to include a new section
      pwg_query('ALTER TABLE '.HISTORY_TABLE.' CHANGE section section enum(\''.implode("','", array_unique($history_sections)).'\') DEFAULT NULL;');

      // and refresh cache
      conf_update_param('history_sections_cache', get_enums(HISTORY_TABLE, 'section'), true);

      $section = $page['section'];
    }
  }

We do as if the history.section is case sensitive. It's not. If you try to add section42 in the ENUM field while Section42 already exists, MySQL will throw an error.

In this code (`include/functions.inc.php` function `pwg_log`: ``` // If plugin developers add their own sections, Piwigo will automatically add it in the history.section enum column if (isset($page['section'])) { // set cache if not available if (!isset($conf['history_sections_cache'])) { conf_update_param('history_sections_cache', get_enums(HISTORY_TABLE, 'section'), true); } $conf['history_sections_cache'] = safe_unserialize($conf['history_sections_cache']); if (in_array($page['section'], $conf['history_sections_cache'])) { $section = $page['section']; } elseif (preg_match('/^[a-zA-Z0-9_-]+$/', $page['section'])) { $history_sections = get_enums(HISTORY_TABLE, 'section'); $history_sections[] = $page['section']; // alter history table structure, to include a new section pwg_query('ALTER TABLE '.HISTORY_TABLE.' CHANGE section section enum(\''.implode("','", array_unique($history_sections)).'\') DEFAULT NULL;'); // and refresh cache conf_update_param('history_sections_cache', get_enums(HISTORY_TABLE, 'section'), true); $section = $page['section']; } } ``` We do as if the `history.section` is case sensitive. It's not. If you try to add `section42` in the ENUM field while `Section42` already exists, MySQL will throw an error. <!-- github-sync-id:2087971812 -->
adam closed this issue 2026-10-05 00:57:38 +02:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#1813