As far as I can tell access is almost always denied.

I'm second guessing myself because apparently 140 people are using 7.x-1.3 without trouble but I'm pretty sure.

The database has a column fiid, which is for the field instance id, however the module is storing the field id in there, not the instance id, so when access is checked using the instance id it generally doesn't match the field id that is stored.

The only way I can see it working for people is if they don't reuse fields and the field instance id is always the same as the field id.

Marking critical as the module doesn't really work with this bug.

Comments

rooby’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.42 KB

This patch fixes it for me.

rooby’s picture

The downside is it means you have to re-save all your setting.

So I guess this will need an update function to update all the settings for people.

I will leave as needs review for now to get the functionality reviewed and I will add the update function in the next day or two.

mariacha1’s picture

Status: Needs review » Needs work
StatusFileSize
new10 KB
new45.68 KB

This patch loads the profile view page, but doesn't show me any fields. I am using the "main" profile and am using fields where the field id and instance id match.

Permissions

I just get the "Main Profile" title.

Blank page

rooby’s picture

I'm going to check this out as I have seen it too (strange as I tried it on one site and it worked but on another it didn't).

rooby’s picture

Status: Needs work » Needs review
StatusFileSize
new2.24 KB

Here is a new version that should work properly.

mariacha1’s picture

Status: Needs review » Needs work
StatusFileSize
new4.69 KB
new5.44 KB
new31.35 KB
new42.72 KB
new31.53 KB
new41.43 KB

Your patch looks good to me. Here's a few screenshots to confirm.

1) The "Name" field only exists once, so its field id matches its field instance id.
Here's the config:
Config
Here's the user page:
Config
Here's what the anonymous user sees:
Config

2) The "Last Name" field exists in another form, so its field id does not match its field instance id.
Here's the config:
Config
Here's the user page:
Config
Here's what the anonymous user sees:
Config

I'm not going to set this to RTBC, though, because it will need an update hook, as you mentioned, to be properly patched to be ported. I'd be happy to take a stab at that if you won't have time within the next few weeks.

mariacha1’s picture

Status: Needs work » Needs review
StatusFileSize
new2.9 KB

Here's the latest version of the patch with an update hook. It re-rolls patch from #5 into the latest dev version.

rooby’s picture

Thanks for the updated patch.

I have a couple of comments:

+++ b/profile2_privacy.install
@@ -86,3 +86,15 @@ function profile2_privacy_field_schema($field) {
+function profile2_privacy_update_7001() {
+  $query = 'UPDATE {profile2_privacy_fields} SET fiid = ' .
+    '(SELECT id FROM {field_config_instance} ' .
+    ' WHERE {field_config_instance}.field_id = {profile2_privacy_fields}.fiid ' .
+    ' AND {field_config_instance}.entity_type = \'profile2\')';
+
+  db_query($query);

The update function number should be 7101.

See https://api.drupal.org/api/drupal/modules!system!system.api.php/function... for further information. I might be able to simplify the explanation if that one isn't clear.

A couple of things regarding the sql:
* You can use double quotes around the sql string so that you don't have to escape the internal quotes.
* If you use table aliases it simplifies things a bit.
* You can make it a single string.

For example (there is no Druapl standard for indenting sql though so it comes down to personal preference, you don't have to do it this way):

$query = "UPDATE {profile2_privacy_fields} ppf
             SET ppf.fiid = (SELECT id
                               FROM {field_config_instance} fci
                              WHERE fci.field_id = ppf.fiid
                                AND fci.entity_type = 'profile2')";

Functionality wise, I'll try to test it soon.
The main thing to test is having multiple profiles that use multiple instances of the same field.
We might get into trouble when a single fid has multiple ffids.

mariacha1’s picture

Status: Needs review » Needs work

Thanks @rooby! Lots of helpful stuff there, and I'll make changes asap.

It came to me in the night, too, that I neglected to test against multiple profiles with the same field, and, sure enough, this is an issue. I'll need to change the reference to the "entity_type" to instead pull in the "bundle" or possibly refer to the profile id.

Setting back to needs work.

mariacha1’s picture

Status: Needs work » Needs review
StatusFileSize
new1.4 KB
new3.37 KB

Here's another attempt at an update hook. This completely recreates the original table by dumping all the new values into a temporary table, dropping the original table, and renaming it. I have a feeling this is not the ideal way to do this, but I believe it's less system-intensive doing all the updates in mysql. Criticism is welcome!

I'm attaching a patch and an interdiff between this and #7, although I see now that I've created it that it's not terribly helpful. :)

TBarina’s picture

I've applied the path in #10 and now it all works perfectly here.
Many thanks.

randallknutson’s picture

Status: Needs review » Reviewed & tested by the community

Patch worked for me and the update hook worked as well. This should be good to go and is critical since the main module just doesn't work without it.

jhedstrom’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Looks like this got committed back in October.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.