Server: PHP Error: key() and reset() function parameter mismatch (expect array, string given) in Activity Provider

Created on 31 Jan 2017  路  11Comments  路  Source: nextcloud/server

Steps to reproduce

  1. Unknown

Expected behaviour

No Error messages about wrong parameter type in log.

Actual behaviour

PHP Errors shown in log:

key() expects parameter 1 to be array, string given at /path/to/nextcloud/apps/files/lib/Activity/Provider.php#251
reset() expects parameter 1 to be array, string given at /path/to/nextcloud/apps/files/lib/Activity/Provider.php#250

Server configuration

Operating system:
Gentoo

Web server:
Apache 2.4.20

Database:
MySQL 5.6.19

PHP version:
5.6.21

Nextcloud version: (see Nextcloud admin page)
11.0.1

Updated from an older Nextcloud/ownCloud or fresh install:
OwnCloud 9.1.2

Where did you install Nextcloud from:
Downloaded from nextcloud.com

Signing status:


Signing status
No errors have been found.

List of activated apps:


App list
Enabled:

  • activity: 2.4.1
  • admin_audit: 1.1.0
  • bookmarks: 0.9.1
  • calendar: 1.5.0
  • comments: 1.1.0
  • contacts: 1.5.2
  • dav: 1.1.1
  • encryption: 1.4.1
  • federatedfilesharing: 1.1.1
  • federation: 1.1.1
  • files: 1.6.1
  • files_external: 1.1.2
  • files_pdfviewer: 1.0.1
  • files_sharing: 1.1.1
  • files_texteditor: 2.2
  • files_trashbin: 1.1.0
  • files_versions: 1.4.0
  • files_videoplayer: 1.0.0
  • firstrunwizard: 2.0
  • gallery: 16.0.0
  • logreader: 2.0.0
  • lookup_server_connector: 1.0.0
  • nextcloud_announcements: 1.0
  • notes: 2.2.0
  • notifications: 1.0.1
  • password_policy: 1.1.0
  • provisioning_api: 1.1.0
  • serverinfo: 1.1.1
  • sharebymail: 1.0.1
  • survey_client: 0.1.5
  • systemtags: 1.1.3
  • tasks: 0.9.4
  • templateeditor: 0.2
  • theming: 1.1.1
  • twofactor_backupcodes: 1.0.0
  • updatenotification: 1.1.1
  • workflowengine: 1.1.1
    Disabled:
  • external
  • files_accesscontrol
  • files_automatedtagging
  • files_retention
  • user_external
  • user_ldap
  • user_saml

The content of config/config.php:


Config report
{
"system": {
"instanceid": "occ850a97fd1",
"passwordsalt": "REMOVED SENSITIVE VALUE",
"trusted_domains": [
"my.domain.rocks"
],
"datadirectory": "/my/data/dir",
"dbtype": "mysql",
"version": "11.0.1.2",
"dbname": "REMOVED SENSITIVE VALUE",
"dbhost": "REMOVED SENSITIVE VALUE",
"dbtableprefix": "oc_",
"dbuser": "REMOVED SENSITIVE VALUE",
"dbpassword": "REMOVED SENSITIVE VALUE",
"installed": true,
"forcessl": true,
"loglevel": 2,
"theme": "",
"maintenance": false,
"singleuser": false,
"secret": "REMOVED SENSITIVE VALUE",
"mail_smtpmode": "smtp",
"mail_smtpsecure": "tls",
"mail_from_address": "REMOVED SENSITIVE VALUE",
"mail_domain": "REMOVED SENSITIVE VALUE",
"mail_smtpauth": 1,
"mail_smtphost": "REMOVED SENSITIVE VALUE",
"mail_smtpport": "25",
"mail_smtpname": "REMOVED SENSITIVE VALUE",
"mail_smtppassword": "REMOVED SENSITIVE VALUE",
"mail_smtpauthtype": "LOGIN",
"forceSSLforSubdomains": true,
"trashbin_retention_obligation": "auto",
"tempdirectory": "/my/temp/dir"
},
"apps": {
"activity": {
"enabled": "yes",
"installed_version": "2.4.1",
"types": "filesystem"
},
"admin_audit": {
"enabled": "yes",
"installed_version": "1.1.0",
"types": "logging"
},
"backgroundjob": {
"lastjob": "4287"
},
"bookmarks": {
"enabled": "yes",
"installed_version": "0.9.1",
"ocsid": "168710",
"types": ""
},
"calendar": {
"enabled": "yes",
"installed_version": "1.5.0",
"ocsid": "168707",
"signed": "true",
"types": ""
},
"comments": {
"enabled": "yes",
"installed_version": "1.1.0",
"types": "logging"
},
"contacts": {
"enabled": "yes",
"installed_version": "1.5.2",
"ocsid": "168708",
"signed": "true",
"types": ""
},
"core": {
"OC_Channel": "stable",
"backgroundjobs_mode": "cron",
"default_encryption_module": "OC_DEFAULT_MODULE",
"encryption_enabled": "yes",
"global_cache_gc_lastrun": "1441088447",
"installedat": "1396365139.9175",
"lastcron": "1485900008",
"lastupdateResult": "[]",
"lastupdatedat": "1485898638",
"moveavatarsdone": "yes",
"oc.integritycheck.checker": "[]",
"previewsCleanedUp": "1",
"public_caldav": "calendar/share.php",
"public_calendar": "calendar/share.php",
"public_documents": "documents/public.php",
"public_files": "files_sharing/public.php",
"public_gallery": "gallery/public.php",
"public_webdav": "dav/appinfo/v1/publicwebdav.php",
"remote_caldav": "dav/appinfo/v1/caldav.php",
"remote_calendar": "dav/appinfo/v1/caldav.php",
"remote_carddav": "dav/appinfo/v1/carddav.php",
"remote_contacts": "dav/appinfo/v1/carddav.php",
"remote_core.css": "/core/minimizer.php",
"remote_core.js": "/core/minimizer.php",
"remote_dav": "dav/appinfo/v2/remote.php",
"remote_files": "dav/appinfo/v1/webdav.php",
"remote_filesync": "files/appinfo/filesync.php",
"remote_mozilla_sync": "mozilla_sync/appinfo/remote.php",
"remote_webdav": "dav/appinfo/v1/webdav.php",
"repairlegacystoragesdone": "yes",
"shareapi_allow_links": "yes",
"shareapi_allow_mail_notification": "yes",
"shareapi_allow_public_notification": "yes",
"shareapi_allow_public_upload": "no",
"shareapi_allow_resharing": "yes",
"shareapi_default_expire_date": "yes",
"shareapi_enabled": "yes",
"shareapi_enforce_expire_date": "yes",
"shareapi_enforce_links_password": "yes",
"umgmt_show_backend": "false",
"umgmt_show_email": "true",
"umgmt_show_last_login": "true",
"umgmt_show_storage_location": "false",
"vendor": "nextcloud"
},
"dav": {
"OCA\DAV\Migration\ValueFixInsert_ran": "true",
"enabled": "yes",
"installed_version": "1.1.1",
"types": "filesystem"
},
"documents": {
"converter": "off",
"enabled": "no",
"installed_version": "0.11.2",
"ocsid": "168711",
"types": "",
"unstable": "false"
},
"encryption": {
"enabled": "yes",
"installed_version": "1.4.1",
"masterKeyId": "master_removed",
"publicShareKeyId": "pubShare_removed",
"recoveryAdminEnabled": "0",
"recoveryKeyId": "recovery_removed",
"types": "filesystem"
},
"federatedfilesharing": {
"enabled": "yes",
"installed_version": "1.1.1",
"types": ""
},
"federation": {
"enabled": "yes",
"installed_version": "1.1.1",
"types": "authentication"
},
"files": {
"backgroundwatcher_previous_file": "960",
"backgroundwatcher_previous_folder": "55",
"cronjob_scan_files": "500",
"default_quota": "1 GB",
"enabled": "yes",
"installed_version": "1.6.1",
"types": "filesystem"
},
"files_external": {
"enabled": "yes",
"installed_version": "1.1.2",
"ocsid": "166048",
"types": "filesystem",
"user_mounting_backends": "dav,owncloud,sftp,amazons3,dropbox,googledrive,swift,\OC\Files\Storage\SFTP_Key"
},
"files_locking": {
"enabled": "no",
"installed_version": "",
"types": "filesystem"
},
"files_pdfviewer": {
"enabled": "yes",
"installed_version": "1.0.1",
"ocsid": "166049",
"types": ""
},
"files_sharing": {
"enabled": "yes",
"installed_version": "1.1.1",
"outgoing_server2server_share_enabled": "no",
"types": "filesystem"
},
"files_texteditor": {
"enabled": "yes",
"installed_version": "2.2",
"ocsid": "166051",
"types": ""
},
"files_trashbin": {
"enabled": "yes",
"installed_version": "1.1.0",
"types": "filesystem"
},
"files_versions": {
"enabled": "yes",
"installed_version": "1.4.0",
"types": "filesystem"
},
"files_videoplayer": {
"enabled": "yes",
"installed_version": "1.0.0",
"types": ""
},
"files_videoviewer": {
"enabled": "no",
"installed_version": "0.1.3",
"ocsid": "166054",
"types": ""
},
"firstrunwizard": {
"enabled": "yes",
"installed_version": "2.0",
"types": "logging"
},
"gallery": {
"enabled": "yes",
"installed_version": "16.0.0",
"types": ""
},
"logreader": {
"enabled": "yes",
"installed_version": "2.0.0",
"levels": "11111",
"ocsid": "170871",
"types": ""
},
"lookup_server_connector": {
"enabled": "yes",
"installed_version": "1.0.0",
"types": "authentication"
},
"mozilla_sync": {
"enabled": "no",
"installed_version": "1.4",
"ocsid": "161793",
"types": ""
},
"nextcloud_announcements": {
"enabled": "yes",
"installed_version": "1.0",
"pub_date": "Sat, 10 Dec 2016 00:00:00 +0100",
"types": "logging"
},
"notes": {
"enabled": "yes",
"installed_version": "2.2.0",
"types": ""
},
"notifications": {
"enabled": "yes",
"installed_version": "1.0.1",
"types": "logging"
},
"ownnote": {
"enabled": "no",
"folder": "",
"installed_version": "1.08",
"ocsid": "168512",
"types": ""
},
"password_policy": {
"enabled": "yes",
"enforceNumericCharacters": "1",
"enforceSpecialCharacters": "1",
"enforceUpperLowerCase": "1",
"installed_version": "1.1.0",
"types": ""
},
"provisioning_api": {
"enabled": "yes",
"installed_version": "1.1.0",
"types": "prevent_group_restriction"
},
"search_lucene": {
"enabled": "no",
"installed_version": "0.5.3",
"ocsid": "168709",
"types": "filesystem"
},
"serverinfo": {
"enabled": "yes",
"installed_version": "1.1.1",
"types": ""
},
"sharebymail": {
"enabled": "yes",
"installed_version": "1.0.1",
"types": "filesystem"
},
"survey_client": {
"enabled": "yes",
"installed_version": "0.1.5",
"stats": "no",
"types": ""
},
"systemtags": {
"enabled": "yes",
"installed_version": "1.1.3",
"types": "logging"
},
"tasks": {
"enabled": "yes",
"installed_version": "0.9.4",
"ocsid": "164356",
"signed": "true",
"types": ""
},
"templateeditor": {
"enabled": "yes",
"installed_version": "0.2",
"types": ""
},
"theming": {
"enabled": "yes",
"installed_version": "1.1.1",
"types": "logging"
},
"twofactor_backupcodes": {
"enabled": "yes",
"installed_version": "1.0.0",
"types": ""
},
"updatenotification": {
"enabled": "yes",
"installed_version": "1.1.1",
"tasks": "0.9.4",
"types": ""
},
"updater": {
"enabled": "no",
"installed_version": "0.6",
"types": ""
},
"workflowengine": {
"enabled": "yes",
"installed_version": "1.1.1",
"types": "filesystem"
}
}
}

Are you using external storage, if yes which one: No.

Are you using encryption: Yes

Are you using an external user-backend, if yes which one: No.

Client configuration

Browser:
Firefox 51

Operating system:
Linux Mint 18.1

Nextcloud log (data/nextcloud.log)


Nextcloud log
{"reqId":"WI4WUn8AAAEAACk3qYcAAAAb","remoteAddr":"92.77.107.238","app":"PHP","message":"reset() expects parameter 1 to be array, string given at /path/to/nextcloud/apps/files/lib/Activity/Provider.php#250","level":3,"time":"2017-01-29T16:20:35+00:00","method":"GET","url":"/ocs/v1.php/cloud/activity?page=0&pagesize=100&format=json","user":"myuser","version":"11.0.1.2"}
{"reqId":"WI4WUn8AAAEAACk3qYcAAAAb","remoteAddr":"92.77.107.238","app":"PHP","message":"key() expects parameter 1 to be array, string given at /path/to/nextcloud/apps/files/lib/Activity/Provider.php#251","level":3,"time":"2017-01-29T16:20:35+00:00","method":"GET","url":"/ocs/v1.php/cloud/activity?page=0&pagesize=100&format=json","user":"myuser","version":"11.0.1.2"}

bug activity and notification needs info

All 11 comments

Can you please run the followin query?

SELECT *
FROM `oc_activity`
WHERE `subjectparams` NOT LIKE '%}]'
    AND `subjectparams` NOT LIKE '[{%'
    AND `app` = 'files' 

That got me 2224 of 2490 rows, all of them containing strings like these encoded as blobs:
["\/2015-08-07 Datei Name - Foo, einiger Text.pdf"]
or
["\/2015-04-27 Dateiname mit Umlaut - \u00e4nderung.png"]
or
["\/2015-08-22 Foo\/IMG_1014.jpg","sebastian"]
or
["\/Urlaub"]

(I changed the above file names due to privacy concerns - but I did not change the data's structure.)

There are no rows with strings which are not enclosed in [ ] .

The rest of the rows is formatted as JSON arrays of objects:
[{"61963":"\/Folder\/test.md"}]
I checked on the timestamp and autoincrement values, too. The newest entries are formatted in JSON syntax while the older ones are all missing the curly brackets and object_ids

I suppose all entries in oc_activity should be formatted accordingly? I upgraded from OC 9.1.2 a few weeks ago. May this be an upgrad issue?

Maybe one can I fix it by updating the problematic rows?
First I thought it might work within an update statement with something like
SET subjectparams=concat('[{\"', object_id, '\":', substring(substring_index(cast(subjectparams AS CHAR(10000) CHARACTER SET utf8), '\"', 2), 2), '\"}]')

Unfortunately, this must be extended to deal with multiple array elements. So I might be better off exporting the data, transforming it into JSON with a small script and update the table rows with the transformed data afterwards.

Any suggestions?

Either a script like that or the simple way to make it usable again would be to delete such entries.
Can you confirm that all these entries are "old" (from before the update)? Or are any of them new.
I think we don't create such entries anymore since before Nextcloud 9...

Also can you tell me the subject of those "broken" entries?

Are all non-JSON entries "old"?
Yes, but older than I first thought. I can confirm that the last of this old non-JSON entries has a timestamp value of 1481056461 (i.e. 2016-12-06 21:34:21 for people living outside the Unix timezone. ;-) ).
The first entry with correct JSON syntax is from 2016-12-12 22:43:28. That is exactly the day I upgraded from OC 9.0.6 to OC 9.1.2 (tried to upgrade to NC 10 that day but delayed that until January due to #2203 where I upgraded to 11.0.1).

Long story short: The syntax of oc_activity.subjectparams changed somewhere between that two OC versions. But I never had PHP errors complaining about the old activity entries until I migrated to NC 11.0.1.

Subjects of the broken entries
SELECT DISTINCT(subject) FROM ... gave me:

  • created_self
  • deleted_self
  • changed_self
  • renamed_self
  • restored_self

Seems like an issue other people migrating from OC to NC could face, too. Thus it could be worth fixing such old entries in the upgrade script. (To prevent a frustrating experience for new users.)

I think it would be an easy task: explode array, build JSON objects out of the elements, put them in an array and store the stringified JSON in the blob column. Your thoughts?

Can you make the following change and see if that fixes your issue?
https://github.com/nextcloud/server/pull/3394/commits/c031c77e3c0a78afa82867a583c2e13e3db04bd6

Almost! No more errors logged in the files app. But similar adjustments might be needed in files_sharing as following errors suggest:

{"reqId":"WJo7gH8AAAEAAGEsXWgAAAAy","remoteAddr":"91.52.15.38","app":"PHP","message":"key() expects parameter 1 to be array, string given at \/path\/to\/my\/nextcloud\/apps\/files_sharing\/lib\/Activity\/Providers\/Users.php#229","level":3,"time":"2017-02-07T21:26:25+00:00","method":"GET","url":"\/index.php\/apps\/activity\/api\/v2\/activity\/all?format=json&previews=true&since=10890","user":"myUser","version":"11.0.1.2"}
{"reqId":"WJo7gH8AAAEAAGEsXWgAAAAy","remoteAddr":"91.52.15.38","app":"PHP","message":"String offset cast occurred at \/path\/to\/my\/nextcloud\/apps\/files_sharing\/lib\/Activity\/Providers\/Users.php#231","level":3,"time":"2017-02-07T21:26:25+00:00","method":"GET","url":"\/index.php\/apps\/activity\/api\/v2\/activity\/all?format=json&previews=true&since=10890","user":"myUser","version":"11.0.1.2"}
{"reqId":"WJo7gH8AAAEAAGEsXWgAAAAy","remoteAddr":"91.52.15.38","app":"PHP","message":"key() expects parameter 1 to be array, string given at \/path\/to\/my\/nextcloud\/apps\/files_sharing\/lib\/Activity\/Providers\/Users.php#229","level":3,"time":"2017-02-07T21:26:25+00:00","method":"GET","url":"\/index.php\/apps\/activity\/api\/v2\/activity\/all?format=json&previews=true&since=10890","user":"myUser","version":"11.0.1.2"}
{"reqId":"WJo7gH8AAAEAAGEsXWgAAAAy","remoteAddr":"91.52.15.38","app":"PHP","message":"String offset cast occurred at \/path\/to\/my\/nextcloud\/apps\/files_sharing\/lib\/Activity\/Providers\/Users.php#231","level":3,"time":"2017-02-07T21:26:25+00:00","method":"GET","url":"\/index.php\/apps\/activity\/api\/v2\/activity\/all?format=json&previews=true&since=10890","user":"myUser","version":"11.0.1.2"}

Thanks a lot @nickvergessen !

Nevertheless, personally I am not a huge fan of code that works around such legacies. I would prefer to remove the root cause in the long run. An additional migration task in the upgrade routine would do the trick and keeps the code base cleaner. ;-)

And an additional error message regarding line 238 in /apps/files_sharing/lib/Activity/Providers/Users.php:

{"reqId":"WJpFrH8AAAEAAEDVzB4AAAAa","remoteAddr":"91.52.15.38","app":"PHP","message":"String offset cast occurred at /path/to/my/nextcloud/apps/files_sharing/lib/Activity/Providers/Users.php#238","level":3,"time":"2017-02-07T22:09:49+00:00","method":"GET","url":"/index.php/apps/activity/api/v2/activity/files_sharing?format=json&previews=true&since=0","user":"myUser","version":"11.0.1.2"}

Well the main issue is, that a migration for things like this can potentially take forever.
There are instances with millions of activities. Not sure if we can do that...

If you don't mind, feel free to send a copy of your activity table to <my username>@nextcloud.com. Otherwise we will continue this step by step...

Can you try to put the following files into apps/files_sharing/lib/Activity/Providers:
Providers.zip

Works! Thanks again!

I see your point @nickvergessen . I have not considered large scale deployments.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blackcrack picture blackcrack  路  3Comments

rullzer picture rullzer  路  3Comments

arno01 picture arno01  路  3Comments

juliushaertl picture juliushaertl  路  3Comments

MorrisJobke picture MorrisJobke  路  3Comments