-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[6.0] Add a global master language for Multilingual Associations #25403
base: 6.0-dev
Are you sure you want to change the base?
Changes from 1 commit
cec6bd5
57c3a12
655f7bb
9cd69c0
b74930c
d20257a
eb72d74
cc03c48
b669d7b
d834ab6
cd7aeb4
391e1a0
72f8963
03818fd
577c1c6
6812d99
1495977
7da2da0
8c61dd6
e6d7e3c
e0ceadd
0eed838
211400d
75ccfe9
b9361e6
500f10e
b9d451c
628c22e
69b7c05
7171c11
a123b14
4ab0293
cb4a7d3
666acbd
9b3d1c6
dbe7494
28010b8
b74287e
b34c098
561c01e
9f29efd
be8fdbf
591ced4
e22457d
fc95e69
550db64
eaf8ce2
2275c8a
ca7d5b0
7df0d4a
ef78227
3a109bb
7f42c40
978aac0
e6cdd7e
506059f
a866a13
0acf809
047bf74
55e46d1
eb2bdbb
285944f
3ac1800
6e30b12
ad19dc3
42a39b2
ba57d95
190ab67
3918c30
ef1eb55
5052e70
dc44040
3215e64
3c182ae
88ddb2a
952d7fb
393ed64
588ee55
3951117
f6ba2ee
7104b51
f6f3e9d
2733b6a
439c6ad
8f97cc0
a7c72db
da88da9
01f9cd8
5c321cb
ab0e2bd
77bb4f7
e81e549
1f8fb0b
6304010
de8a1b1
04ee4a7
fcb4f22
059ad32
822eeba
5dbad04
8f65a6c
e705cf5
3069cd7
197d0ce
9f5c7a3
c6e83ed
6e74985
f8866a2
1b14de0
41d85a7
6cd6fcb
b4d0019
5c9d903
6193b2b
4e7e99f
58d567d
a596d3a
f5b6dcb
1844027
a17cef8
ac231c8
fbf0c44
ffc4e27
6dcae08
0023d72
062dd08
440584d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Filtering for "not associated" did not work correctly when either a child of a master item is not associated or when there is no master item for a child.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -445,45 +445,55 @@ protected function getListQuery() | |
} | ||
} | ||
|
||
// Filter on association state | ||
// Filter by association state | ||
$assocStateField = $this->state->get('assocstate'); | ||
|
||
if ($assocStateField !== '') | ||
{ | ||
// not associated | ||
if ($assocStateField === '-1') | ||
{ | ||
$subQuery = $db->getQuery(true) | ||
$languageQuery = $db->getQuery(true) | ||
->select('COUNT(*)') | ||
->from('#__languages'); | ||
$db->setQuery($subQuery); | ||
->from($db->quoteName('#__languages')); | ||
$db->setQuery($languageQuery); | ||
$countLanguages = $db->loadResult(); | ||
|
||
// join over associations where id does not exists or where child does not exists | ||
// get all keys where not all languages are associated | ||
$assocQuery = $db->getQuery(true) | ||
->select($db->quoteName('key')) | ||
->from($db->quoteName('#__associations')) | ||
->group($db->quoteName('key')) | ||
->having('COUNT(*) < ' . $countLanguages); | ||
|
||
// join over associations where id does not exists | ||
$query->where('((' . $db->quoteName('asso.id') . ' IS NULL )' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Convert to prepared statements please and maybe use orWhere, maybe whereIn is also possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HLeithner Here I could not use prepared statement successfully. It probably doesn't work without further ado within "IN". The rewriting to "orWhere" and "whereIn" does not seem possible here, because the enclosing brackets at the beginning of "where" are essential. |
||
// if we are on the childlanguage | ||
. ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') | ||
. ' AND ' . $db->quoteName('asso2.id') . ' < ' . $db->quote($countLanguages) . ' ))'); | ||
// or if we are on the childlanguage and there is no master language | ||
. ' OR ( ' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quote('-1') . ')' | ||
lavipr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// or a child of the master does not exist | ||
. ' OR ( ' . $db->quoteName('asso.key') . ' IN (' . $assocQuery . ') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HLeithner , @SharkyKZ , @alikon, @richard67 Thank you! Now that I've added the getContentLanguages function to count languages, I guess I've removed our previous conversation. I would like to continue it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HLeithner thanks for the hint to bind the variable to the main query! |
||
AND ' . $db->quoteName('asso.parent_id') . ' = ' . $db->quote('0') . ')' | ||
lavipr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
. ')'); | ||
} | ||
|
||
// outdated | ||
if ($assocStateField === '0') | ||
{ | ||
echo "<pre>" . print_r("outdated") . "</pre>"; | ||
// if we are on the masterlanguage | ||
// if we are on the masterlanguage and we check the state of the children | ||
$query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') | ||
. ' AND ' . $db->quoteName('asso2.assocParams') . ' < ' . $db->quoteName('asso.assocParams') . ')' | ||
// if we are on the childlanguage | ||
// if we are on the childlanguage we check its state comparing to its master | ||
. ' OR (' . $db->quoteName('asso.assocParams') . ' < ' . $db->quoteName('asso2.assocParams') | ||
. ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); | ||
} | ||
|
||
// up-to-date | ||
if ($assocStateField === '1') | ||
{ | ||
// if we are on the masterlanguage and we check the state of the children | ||
$query->where('((' . $db->quoteName('asso2.parent_id') . ' = ' . $db->quoteName('asso.id') | ||
. ' AND ' . $db->quoteName('asso2.assocParams') . ' = ' . $db->quoteName('asso.assocParams') . ')' | ||
// if we are on the childlanguage | ||
// if we are on the childlanguage we check its state comparing to its master | ||
. ' OR (' . $db->quoteName('asso.assocParams') . ' = ' . $db->quoteName('asso2.assocParams') | ||
. ' AND ' . $db->quoteName('asso2.id') . ' = ' . $db->quoteName('asso.parent_id') . '))'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert to prepared statements please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HLeithner While rewriting and testing prepared statements, it does not seem possible to use prepared statements here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alikon is it possible that we can't use parepared parameters in having?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this with a similar query and it worked... strange
May test query:
can you please post your code or error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HLeithner Does it also work with PostgreSQL? I can test, but not before weekend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HLeithner , @richard67 , @lavipr
HAVING
clause and it woks even in Postgresqlhere is a working snippet :
COUNT(*)
query without at least a where condition on thepublished
field , but that's meThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be converted to a single query using subquery.
But there's already a method for getting content languages:
Joomla\CMS\Language\LanguageHelper::getContentLanguages()
so why not use it to get language count.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I use now the method for getting content languages and count it.
Maybe my problem here with the prepared statements is not the problem at this point, but when I use $assocQuery in the next step, as it is not working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks Nicola for testing this.
@SharkyKZ using getContentLanguages would make sense because the query is cached
you can use, I think we don't need the installed check and a indexed version for the language count
Also in this helper is a AssociationsHelper::getContentLanguages function that is not used anywhere do we still need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes the $assocQuery will be converted to a string and the bind variable is lost. you have to bind the variable to the main $query.