When I have updated my system to PHP 7, download count showed Never downloaded for all files even though they had a download count before.
I read log and found this:
Notice: Undefined property: stdClass::$Array in download_count_field_formatter_view() - line 31
and
Notice: Array to string conversion in download_count_field_formatter_view() - line 31
I fixed this by changing line 31 in file download_count.field.inc from
$item['downloads'] = db_query("SELECT COUNT(fid) from {download_count} where fid = :fid AND type = :type AND id = :id", array(':fid' => $item['fid'], ':type' => $entity_type, ':id' => $entity->$entity_info['entity keys']['id']))->fetchField();
to
$item['downloads'] = db_query("SELECT COUNT(fid) from {download_count} where fid = :fid AND type = :type AND id = :id", array(':fid' => $item['fid'], ':type' => $entity_type, ':id' => $entity->{$entity_info['entity keys']['id']}))->fetchField();
Now download count is shown, but I get another error:
Error: Call to undefined function fetchField() in download_count_field_formatter_view()
and
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null: INSERT INTO {download_count} (fid, uid, type, id, ip_address, referrer, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => (censored) [:db_insert_placeholder_1] => 0 [:db_insert_placeholder_2] => node [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => (censored) [:db_insert_placeholder_5]
I think the scope of the problem is bigger so could one of the developers try to use this module with PHP 7 so they can try to reproduce these bugs and possibly fix them.
Comment | File | Size | Author |
---|---|---|---|
#8 | download_count_not-2814107-8.patch | 1.47 KB | kristofferwiklund |
#6 | download_count-n2814107-6.patch | 980 bytes | DamienMcKenna |
#5 | download_count-php7-2814107-7.x-3.1.patch | 1.81 KB | tamsoftware |
Comments
Comment #2
KlemenDEV CreditAttribution: KlemenDEV as a volunteer commentedComment #3
KlemenDEV CreditAttribution: KlemenDEV as a volunteer commentedSo after some more work, chagning line 191 of file download_count.module from
'id' => $entity->$entity_info['entity keys']['id'],
to
'id' => $entity->{$entity_info['entity keys']['id']},
removed these errors and now download count module works as it should with PHP 7. I need to do some more testing though. Could someone check if this (and previous changes) fixed the problem for them and post patch?
Comment #4
KlemenDEV CreditAttribution: KlemenDEV as a volunteer commentedComment #5
tamsoftware CreditAttribution: tamsoftware commentedPylo's code changes work here (PHP 7 and MySQL 5.7) so here is the patch.
Thanks !
Comment #6
DamienMcKennaThe first change is also fixed in #2798767: Entity id is NULL, cannot insert into download_count db table, so lets leave this one to focus on just the second change.
Comment #7
ydahipatch in #5 worked for me on 7.x-3.1
RTBC. Should be committed.
Comment #8
kristofferwiklund CreditAttribution: kristofferwiklund at Websystem for ComplianceOnline Ltd commentedWe found another part that does not work with PHP 7.
Updated the patch
Comment #9
GoldThe patch at #8 includes the same fix as that described in "Entity id is NULL, cannot insert into download_count db table (2798767)" but this one spots the same sort of error in 2 locations.
I've closed that in favour of people bumping this one.
This is working for me and has been flagged RTBC for a while now.
Any chance of getting this merged in?
Comment #10
nithinkolekar CreditAttribution: nithinkolekar commented+1 RTBCstill error if file system is private
Comment #11
Sagar Ramgade CreditAttribution: Sagar Ramgade as a volunteer commentedComment #12
wmfinck CreditAttribution: wmfinck commentedPlease fix and commit this!
Comment #13
GoldHmm... Just retested this. I've created a node with 2 file fields. One in the private file system and one in the public. The private one is counting okay and the public one isn't. Will hopefully have some time in the morning to dig a little deeper.
Looking at issue #2977389 the public files are not counted anyway and xdebug does not take me into Drupal at all. From the point of view of counting private files the patch at #8 is working for me.
@nithinkolekar, can you give any more insight into the error you saw with the private file system? Any php error in Drupal? Anything in the server logs? Or just silently doesn't count it?
If you can't give more insight into your issue I'm inclined to set this back to RTBC.
@wmfinck, you could help the process by testing (and fixing) this yourself too. ;) Just saying...
Comment #14
nithinkolekar CreditAttribution: nithinkolekar commented@Gold
to reproduce follow these step.
1. Configure file field to have private dir
2. Set fields display settings format as "generic file with download count"
3. give View private files permission to anonymous.
4. upload file
5. try downloading the file as anonymous.
6. error in log :
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null: INSERT INTO {download_count}
Comment #15
GoldThanks @nithinkolekar.
I've followed what you described with the following exceptions;
Step 3: I don't have "View private files" as a permission.
Step 6: I don't see the error in my logs.
Can anyone else replicate this also?
@nithinkolekar, this would be happening in
download_count_file_download_access_alter()
, line 186 indownload_count.module
. Can you examine$file
at that point and see what you can see?Also, how are you standing up your environment? Are you using an existing site or standing up a clean site, checking out the module and patching it?
I'm standing mine up using a fresh download of Drupal via
drush make
which also checks out the module and patch being tested. The site is stood up like this for each test usingdrush $DRUSH_ROOT -y si standard
.Just looking at the patch at #8 again, I would also expect to see that error if the patch hadn't been applied. Can you double check that your
download_count.module
file has actually been patched correctly?Comment #16
GoldBeing unable to replicate the issue with the patch applied and the lack of response I'm going to push this back to RTBC.
Comment #17
bubuI can confirm that patch #8 works well with system files (...
/system/files/
...).Comment #18
jweowu CreditAttribution: jweowu at Catalyst IT commentedConfirming the correctness of these PHP 7 compatibility fixes.
Refer to https://secure.php.net/manual/en/migration70.incompatible.php#migration7...
#8 should be committed.
Comment #19
iamweird CreditAttribution: iamweird commentedPatch #8 works good for me too.
Comment #20
Smesko CreditAttribution: Smesko commentedThank you very much for all of you and your effort!!! :-)
This resolve big problem for us!
Patch #8 works good for us too! :-)
Best regards! :-)
Comment #21
joseph.olstadPlease commit
Comment #23
Sagar Ramgade CreditAttribution: Sagar Ramgade as a volunteer commentedComment #24
joseph.olstadThanks! I also see a new tagged release, double thanks!