backdrop-contrib / metatag

Add structured metadata, aka "meta tags", for various pages on your site.
GNU General Public License v2.0
3 stars 15 forks source link

Upgrading from D7 throws PHP notices on update.php #95

Closed quicksketch closed 1 year ago

quicksketch commented 2 years ago

When upgrading from Drupal 7, Metatag module throws a PHP notice when it tries to load metatag.settings config before values are defined.

Warning: array_filter() expects parameter 1 to be array, null given in metatag_get_info() (line 2030 of /var/www/html/web/modules/contrib/metatag/metatag.module).

image

quicksketch commented 2 years ago

I filed a PR at https://github.com/backdrop-contrib/metatag/pull/96 that prevents metatag from modifying install.php and update.php pages. This seems like it's a good idea because update.php can easily have situations where metatag's settings aren't as expected, not only when updating from Drupal 7 but even updates for metatag if we were to ever refactor the metatag.settings.json organization.

quicksketch commented 2 years ago

I found this error can still occur because metatag_get_info() can be called from metatag_permission_info(), or other hooks that might accidentally be invoked during an update hook.

laryn commented 1 year ago

I am seeing this on an attempt to upgrade a D7 site as well:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: https://app/core/update.php?op=selection&token=etc&id=12836&op=do_nojs&op=do StatusText: Internal Server Error ResponseText: TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 2036 of /app/backdrop/modules/metatag/metatag.module).

Temporary workaround is to split line 2036 up from this:

$enabled_tags = array_filter(config_get('metatag.settings', 'enabled_tags'));

to this:

$enabled_tags = config_get('metatag.settings', 'enabled_tags');
if (is_array($enabled_tags)) {
  $enabled_tags = array_filter($enabled_tags);
}
else {
  $enabled_tags = array();
}      
herbdool commented 1 year ago

Just saw this too on a dry run. I did something similar:

$enabled_tags_config = config_get('metatag.settings', 'enabled_tags');
$enabled_tags = is_array($enabled_tags_config) ? array_filter($enabled_tags_config) : [];

Probably makes sense to make this permanent since even regularly can't assume the variable is an array.

herbdool commented 1 year ago

I added a second PR. Perhaps both could be useful? @quicksketch

mazzech commented 1 year ago

I am trying to update from 1.x-1.22.1 to 1.x-1.22.2 (or later, same effect). The site was never a Drupal site, but a vanilla Backdrop installation back then.

After the update I loose all my configuration, and can't add new settings per Content type or whatever entity. I wonder if this is the same mistake as for the D7 upgrade....?

BTW, unistalling/reinstall the modulel solves the problem, but I loose the all the site's meta content entered by an SEO specialist.

[UPDATE 07012023] The conflict was because of an incompatibility with an older i18n module version, in the meantime I could upgrade without loosing the content.