Skip to content

Fatal Error: count() on null when overwriting existing pages #30

@webmanufaktur

Description

@webmanufaktur

When importing CSV data with the "Modify the existing page" option selected for duplicate page names, the module throws a fatal error:

Fatal Error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in ImportPagesCSV.module:515

This occurs because $page->get('ImportPagesCSVData') returns null for existing pages that are being modified, but the code attempts to call count() on it without checking if it's an array first.

Steps to Reproduce

  1. Import CSV data to create pages
  2. Re-import the same CSV data with "Modify the existing page" option selected
  3. Fatal error occurs on line 515

Proposed Fix

Line 515: Add null/array check before count()

// Before:
if($page->id && count($page->get('ImportPagesCSVData'))) {

// After:
$importData = $page->get('ImportPagesCSVData');
if($page->id && is_array($importData) && count($importData)) {

Line 609 (in modifyPage method): Transfer ImportPagesCSVData to existing page

// Add after the foreach loop, before return:
if($data) {
    $existingPage->set('ImportPagesCSVData', $data);
}

This ensures file imports and other post-save data work correctly when overwriting existing pages.

Environment

  • PHP 8.2 (stricter type checking for count())
  • ProcessWire 3.0.252 (and earlier)
  • ImportPagesCSV module 1.0.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions