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

Conflict with the Postie Plugin #370

Open
fbertini opened this issue Jan 24, 2023 · 18 comments
Open

Conflict with the Postie Plugin #370

fbertini opened this issue Jan 24, 2023 · 18 comments

Comments

@fbertini
Copy link

I'm using Postie to add Posts on my Wordpress site since a long time ago.
I've been using Postie and UAM since at least 5 years without any issue but now I'm facing an annoying one.

On every new post created from an e-mail, a new article is created but the following parameter is not correct:

  • Category (no category is associated to the new post but only the tag).

Let's describe with a practical example:
I have category having ID = 10 and tag with ID = 11.
For what I could see, every time a new post is created via Postie message,
the batch runs and it creates just one new row into the wp_term_relationships table.
This means that I have only one new row with ID 11 only within this table for such new post. If I make a comparison to the posts having the category and tag being associated, I see this for the correct posts:

{"object_id":"7174","term_taxonomy_id":"11","term_order":"0"},
{"object_id":"7174","term_taxonomy_id":"10","term_order":"0"},

While I only see this one for the new post without the category:

{"object_id":"7182","term_taxonomy_id":"11","term_order":"0"},

I tried to manually insert a new entry into the wp_term_relationships table and could see the post correctly in the Admin panel (meaning that I can see both category and tag set as well as the author). This is equivalent to setting up the category in the admin panel.

Basically the root cause is that the following INSERT is being skipped:

INSERT INTO 
wp_term_relationships
 (
object_id
, 
term_taxonomy_id
) VALUES (7182, 10);

Could you please chack this out?

Thanks!

WordPress version: 6.1.1
Postie version: 1.9.64
User Access Manager: 2.2.19

@GM-Alex
Copy link
Owner

GM-Alex commented Feb 7, 2023

Could you revert the following change and try again: ebc4ddf#diff-1e55d4d09272c1fe017db9ee8b1481cec1d995320b790781fedb4878484792aeR569

I think this will cause the issue. Because you are only identified as admin if there is an rest request. If this will not solve the issue it would be nice if you could older version of the plugin because you mentioned you used the both plugins for years and the worked. So the problem could be also related to changes made by Postie.

@fbertini
Copy link
Author

fbertini commented Feb 7, 2023

Is there any specific procedure to go back to that previous version? I think it's a bit dangerous to make this change in production (I see there are many changes over there). I could checkout a specific tag for example but I think it's not a good idea to do this change in prod.

The Postie author suggested me to try with UAM disabled. Could you please check this out and reply?

@GM-Alex
Copy link
Owner

GM-Alex commented Feb 7, 2023

@fbertini I already read the thread at the Postie plugin forum. So since I only edited minor things, the postie author too and you used both plugins for years without an issue, I think this could be the reason. And please do this at a test system.

I think the problem is that you try to assign a restricted category, but since you are not logged in you don't have the permission to see the category and UAM filters the categories which are restricted. If the downgrade doesn't work I think I can not do much about it. The post should be created via Postie by the user which would do this at the backend, so this is nothing I can do about because that must happen within the Postie plugin.

@fbertini
Copy link
Author

fbertini commented Feb 8, 2023

Thank you @GM-Alex
I want to make a test. Could you please tell me the exact tag I need to checkout? Otherwise, in case the change is very small, can you confirm what to change exactly? I clicked on the link you reported and I see one change in Wordpress.php line 569:
if (wp_doing_ajax() === true || defined('REST_REQUEST') && REST_REQUEST) {
Do you mean I should checkout and test the whole version 2.2.18? In this case I should completely unistall UAM from my WP installation and try a manual install(?)
Also, can you suggest a mail server to perform a test in localhost? (I mean also a mail server running with docker on Windows host system).

Thanks!

@fbertini
Copy link
Author

Hello,

I tested the same functionality on my local test environment and I'm really surprised: it works without any downgrade/change to the code.

Honestly I have no idea why this is happening in production. My only guess is that some data is different in production (I mean some configuration/relationship in the database).

I could see this in the log file:

INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`) VALUES (7193, 10)
INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`) VALUES (7193, 11)

I still can't explain why if I disable UAM in production, this is working fine.

@fbertini
Copy link
Author

fbertini commented Feb 18, 2023

Hi,

I did some more analysis with regards this issue and found out that the following query is built when the wordpress get_terms() function is executed within the class-wp-term-query.php file:

SELECT DISTINCT t.term_id
FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy IN ('category') AND t.term_id NOT IN (10,29,30,31) AND tr.object_id IN (7196)

Such "NOT IN" clause is added because of exclusions declared at line 484 and we go inside the first if block:

if ( ! empty( $exclusions ) ) {
	$exclusions = 't.term_id NOT IN (' . implode( ',', array_map( 'intval', $exclusions ) ) . ')';
} else {
	$exclusions = '';
}

So the question now is: is there any chance that User Access Manager has something to do with categories hiding so that the above NOT IN clause is built? I bet there is a difference on the database between the working one and production.

@fbertini
Copy link
Author

fbertini commented Mar 7, 2023

Hi,
I noticed a strange difference between the production environment and the localhost/test environment: I see many UAM queries that I don't see on my localhost. Do you have an idea why?

@GM-Alex
Copy link
Owner

GM-Alex commented Mar 8, 2023

I would say the problem is the hide post, term or what ever completely option. If Postie is not running as admin then all restricted objects are completely "hidden", which means they are not available because all queries are modified that the are not accessible. This would also explain why it works in manual mode and not in automatic mode:

During the manual mode you are logged in. During the automatic check you are not.

https://wordpress.org/support/topic/no-category-and-wrong-author-after-posting/#post-16409566

Try to disable the "hide" option and if it works this is the reason. But if this it the reason I can do nothing about it. The Postie then must provide a way to simulate a logged in user during the automatic mode.

@fbertini
Copy link
Author

fbertini commented Mar 8, 2023

What do mean for the "hide post" option? I couldn't find it on Postie or UAM.
Anyway, in the meantime I did one more test disabling UAM plugin and sending an e-mail to the configured address in Postie and could see it worked as expected. I noticed also that the logs provided by the Postie Support Addon plugin are pretty the same as the ones generated when I test in localhost.
In particular I see that everything works fine when the following queries are skipped:

[info] Query: SELECT ID FROM wp_uam_accessgroups
[info] Query: SELECT *
            FROM wp_uam_accessgroups
            WHERE ID = 4
            LIMIT 1
[info] Query: SELECT *
            FROM wp_uam_accessgroups
            WHERE ID = 5
            LIMIT 1
[info] Query: SELECT *
            FROM wp_uam_accessgroups
            WHERE ID = 6
            LIMIT 1
[info] Query: SELECT *
            FROM wp_uam_accessgroups
            WHERE ID = 7
            LIMIT 1
[info] Query: SELECT group_id AS id, group_type AS type
                FROM wp_uam_accessgroup_to_object
                WHERE group_type IN ('role', 'user')
                  GROUP BY group_type, group_id
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '4'
                  AND group_type = 'UserGroup'
                  AND object_id != ''
                  AND (genera
[info] Query: SELECT term_id AS id, parent AS parentId, taxonomy AS type
                FROM wp_term_taxonomy
                WHERE parent != 0
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '5'
                  AND group_type = 'UserGroup'
                  AND object_id != ''
                  AND (genera
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '6'
                  AND group_type = 'UserGroup'
                  AND object_id != ''
                  AND (genera
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '7'
                  AND group_type = 'UserGroup'
                  AND object_id != ''
                  AND (genera
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '0'
                  AND group_type = 'user'
                  AND object_id != ''
                  AND (general_obj
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '4'
                  AND group_type = 'UserGroup'
                  AND object_id != ''
                  AND (genera
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '5'
                  AND group_type = 'UserGroup'
                  AND object_id != ''
                  AND (genera
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '6'
                  AND group_type = 'UserGroup'
                  AND object_id != ''
                  AND (genera
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '7'
                  AND group_type = 'UserGroup'
                  AND object_id != ''
                  AND (genera
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '0'
                  AND group_type = 'user'
                  AND object_id != ''
                  AND (general_obj
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '0'
                  AND group_type = 'user'
                  AND object_id != ''
                  AND (general_obj
[info] Query: SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate
                FROM wp_uam_accessgroup_to_object
                WHERE group_id = '_none-role_'
                  AND group_type = 'role'
                  AND object_id != ''
                  AND (g

Actually, the query that is executed just after the query above, doesn't have the "NOT IN" clause which is the cause of the problem I suppose:

NOT OK:

[info] Query: 
			SELECT DISTINCT t.term_id
			FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
			WHERE tt.taxonomy IN ('category') AND t.term_id NOT IN (10,29,30,31) AND tr.object_id IN (739

OK:

[info] Query: 
			SELECT DISTINCT t.term_id
			FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
			WHERE tt.taxonomy IN ('category') AND tr.object_id IN (7405)

Do you have an idea why and when the wp_uam_accessgroups is being accessed? I can't believe this table is accessed depending on the environment the website is running in! It sounds kind of weird to me 🤣

@GM-Alex
Copy link
Owner

GM-Alex commented Mar 8, 2023

I talking about the hide complete option, see the following screen:

image

If this is true UAM will "remove" the objects (by adding not in to the queries for restricted objects) from the queries.

@fbertini
Copy link
Author

fbertini commented Mar 8, 2023

No way. It was already set to no.

@GM-Alex
Copy link
Owner

GM-Alex commented Mar 8, 2023

No way. It was already set to no.

Also for categories and other types?

@fbertini
Copy link
Author

fbertini commented Mar 8, 2023

Yes, here's the configuration:
immagine
immagine

@GM-Alex
Copy link
Owner

GM-Alex commented Mar 8, 2023

Could you try setting "Hide empty" to "No"?

@fbertini
Copy link
Author

fbertini commented Mar 8, 2023

Hello,
nothing changed, unfortunately:
immagine

@GM-Alex
Copy link
Owner

GM-Alex commented Mar 8, 2023

Okay anyway the reason is the AccessHandler::getExcludedTerms function, this returns categories which should be excluded and so the query is adjusted. Changing that could lead to unwanted access so I will not change it. So the only way to make it work is run the job with the right user and this can only be done by the Postie plugin.

@fbertini
Copy link
Author

fbertini commented Mar 8, 2023

Thank you very much for your suggestion. Just one last question before closing this issue: what do you mean by "right user"? Consider that I have a list containing the authorized e-mails to post contents; they are just two: one is linked to the admin user and one to another user with an administrator role.

@fbertini fbertini reopened this Apr 16, 2023
@fbertini
Copy link
Author

fbertini commented Apr 16, 2023

Hello @GM-Alex
I have good news, at least under the point of view that I think I have found out the root cause of the problem.

I started by querying the wp_uam_accessgroup_to_object table like this:

SELECT * 
FROM wp_uam_accessgroup_to_object 
WHERE object_id = 10 OR object_id = 11

Here's the output of the query:

| object_id | general_object_type | object_type | group_id | group_type | from_date | to_date |
| --------- | ------------------- | ----------- | -------- | ---------- | --------- | ------- |
| 10        | _user_              | user        | 5        | UserGroup  | NULL      | NULL    |
| 10        | _term_              | _term_      | 5        | UserGroup  | NULL      | NULL    |
| 10        | _term_              | _term_      | 6        | UserGroup  | NULL      | NULL    |
| 11        | _user_              | user        | 5        | UserGroup  | NULL      | NULL    |

As you can see, there are two "strange" entries having object_id = 10 that I removed to obtain the following data only if you repeat the select query above:

| object_id | general_object_type | object_type | group_id | group_type | from_date | to_date |
| --------- | ------------------- | ----------- | -------- | ---------- | --------- | ------- |
| 10        | _user_              | user        | 5        | UserGroup  | NULL      | NULL    |
| 11        | _user_              | user        | 5        | UserGroup  | NULL      | NULL    |

Now I was able to use Postie again and I think there was something wrong with the UAM database (probably it is due to the migration I have done from Wordpress 4.2 to 6.1.1 last year after running the UAM database fix tool).

What do you think about this? Is there any other investigation I can do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants