XOOPS / xmf

XOOPS Module Framework
7 stars 6 forks source link

Inadequate or missing sanity/error checks in Migrate #85

Open mambax7 opened 2 years ago

mambax7 commented 2 years ago

In PHP 8.1 I'm getting errors:

Warning: Undefined array key "publisher_categories" in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
--
Warning: Trying to access array offset on value of type null in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: foreach() argument must be of type array\|object, null given in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Undefined array key "publisher_items" in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Trying to access array offset on value of type null in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: foreach() argument must be of type array\|object, null given in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Undefined array key "publisher_files" in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Trying to access array offset on value of type null in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: foreach() argument must be of type array\|object, null given in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Undefined array key "publisher_meta" in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Trying to access array offset on value of type null in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: foreach() argument must be of type array\|object, null given in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Undefined array key "publisher_mimetypes" in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Trying to access array offset on value of type null in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: foreach() argument must be of type array\|object, null given in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Undefined array key "publisher_rating" in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: Trying to access array offset on value of type null in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216
Warning: foreach() argument must be of type array\|object, null given in file /class/libraries/vendor/xoops/xmf/src/Database/Migrate.php line 216

After adding isset() check as below, the warnings are gone:

     if (isset($this->targetDefinitions[$tableName])) {
         foreach ($this->targetDefinitions[$tableName]['columns'] as $column) {
             $attributes = $this->tableHandler->getColumnAttributes($tableName, $column['name']);
             if ($attributes === false) {
                 $this->tableHandler->addColumn($tableName, $column['name'], $column['attributes']);
             } elseif ($column['attributes'] !== $attributes) {
                 $this->tableHandler->alterColumn($tableName, $column['name'], $column['attributes']);
             }
         }
     }
geekwright commented 2 years ago

This has nothing to do with PHP 8.1

A table name specified in $modversion['tables'] does not have a corresponding table in the schema you are referencing.

This IS a bug in XMF, as this should have prompted an error, but there appears to also be something amiss in your module.