Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inadequate or missing sanity/error checks in Migrate #85

Open
mambax7 opened this issue Dec 5, 2021 · 1 comment
Open

Inadequate or missing sanity/error checks in Migrate #85

mambax7 opened this issue Dec 5, 2021 · 1 comment
Assignees
Labels

Comments

@mambax7
Copy link
Contributor

mambax7 commented Dec 5, 2021

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
Copy link
Collaborator

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.

@geekwright geekwright changed the title PHP 8.1 warnings in Migrate (Trying to access array offset on value of type null) Inadequate or missing sanity/error checks in Migrate Feb 23, 2022
@geekwright geekwright added the bug label Feb 23, 2022
geekwright added a commit to geekwright/xmf that referenced this issue Apr 13, 2022
If table was identified in $modversion['tables'] in
xoops_version.php, but did not exist in the database,
schema was not applied to the new table.

This is related to the errors mentioned in XOOPS#85

Also includes fixes for:
- schema errors for column default by MySQL function (i.e. CURRENT_TIMESTAMP)
- tweaks to generated schema file names for new module versioning
- minor docblock cleanups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants