Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Cached and nested snippets not working in EVO 1.2 #1089

Closed
vinelandit opened this issue Dec 9, 2016 · 40 comments
Closed

Cached and nested snippets not working in EVO 1.2 #1089

vinelandit opened this issue Dec 9, 2016 · 40 comments
Assignees
Labels

Comments

@vinelandit
Copy link

a) Snippets called in [!snippetName!] format are not parsed, and just return the literal [[snippetName]] (replacing the [!!] brackets with [[]])

b) Nested snippets in alternating cached/uncached format, i.e. [!outerSnippet? &param='[[innerSnippet]]'!] are not parsed, and nested snippets using uncached format throughout throw a MySQL error.

(Backticks replaced with quotes in sample calls to avoid being marked up)

Example call:

[[Ditto? &documents='[[getVal? &docid='1' &field='featurePanel1']]' &tpl='homePanel' &extenders='summary' &truncLen='180' &truncOffset='90' ]]

Example error (similar error occurs when the inner snippet is called in uncached format, and the whole call unparsed and returned literally when the outer snippet is in uncached format):

« MODX Parse Error »
Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[[getVal?&docid=) AND sc.published=1 AND sc.deleted=0) AND (sc.privateweb=0) GRO' at line 1
SQL > SELECT DISTINCT sc.id FROM 'ajfadmin_modx'.'modx_site_content' sc LEFT JOIN 'ajfadmin_modx'.'modx_document_groups' dg on dg.document = sc.id WHERE (sc.id IN ([[getVal?&docid=) AND sc.published=1 AND sc.deleted=0) AND (sc.privateweb=0) GROUP BY sc.id
Error information
Current Snippet Ditto ... etc.

@modxuser
Copy link

modxuser commented Dec 9, 2016

I am not a back-end Dev, but the question arises - do your custom snippets still use deprecated MYSQL functions, as 1.2 supports MYSQLI

I have just checked my sites that have nested snippets, all of them work as expected. An example: I use "IF" in combination with Ditoo for IDs and other conditionals - all work perfectly OK

@vinelandit
Copy link
Author

Hi modxuser, thanks for your reply. No, the custom snippets in question don't make any database calls.

Can you confirm that switching your cached [[Ditto? ... ]] call for a cached [!Ditto? ... !] call still works?

@Deesen
Copy link
Contributor

Deesen commented Dec 9, 2016

[!Ditto!] still works for me testing the demo-page with blog, see screenshots. But inside ditto-tpl there is a uncached [!Jot!] which will be outputted for me like

uncached1

uncached2

@modxuser
Copy link

modxuser commented Dec 9, 2016

I have since updated my nested "IF" calls with the new built-in modifiers, but changing the Ditto snippet call from cached to uncached doesn't make any difference, it all still works.

@yama
Copy link
Collaborator

yama commented Dec 10, 2016

@vinelandit Thank you for your information, I will fix it later

yama added a commit that referenced this issue Dec 10, 2016
always should be expand [!no-cache!] In the snippet call
yama added a commit that referenced this issue Dec 10, 2016
@Dmi3yy Dmi3yy added the 1.2.1 label Dec 13, 2016
@Dmi3yy
Copy link
Collaborator

Dmi3yy commented Dec 13, 2016

http://take.ms/oPgO7

This all ok
http://take.ms/pi8zW

But if change to [[Ditto not work (((

need normal work:
[[ [[
[! [!
[[ [!
[! [[

@yama
Copy link
Collaborator

yama commented Dec 13, 2016

&year=`[[date_filter? &type=`year`]]`

This call will not work. Because it can not recognize the value nest. As with programming with PHP, you need to use different quotes.

&year="[[date_filter? &type='year']]"
&year='[[date_filter? &type="year"]]'
&year=`[[date_filter? &type="year"]]`

For example, write like these.
By changing the specification like this, it is now possible to include characters such as " = ? & ` " in the value.
But it may be improved further. I will think about it.

@Dmi3yy
Copy link
Collaborator

Dmi3yy commented Dec 13, 2016 via email

@yama
Copy link
Collaborator

yama commented Dec 13, 2016

ok, I will fix it later

@Dmi3yy
Copy link
Collaborator

Dmi3yy commented Dec 14, 2016

with [[ [[ work

but with [! [! still not work

http://take.ms/SWPXS

but i newer used [! [!

i think now all ok and can close

@Dmi3yy Dmi3yy closed this as completed Dec 14, 2016
@MrSwed
Copy link
Contributor

MrSwed commented Dec 15, 2016

@yama
after update get "Nesting level too deep"
Where, on the older version works without problems ..

10 is not too small?

upd. deleted (a wrong determination of the perpetrator .. looking for.. )

@MrSwed
Copy link
Contributor

MrSwed commented Dec 15, 2016

Founded:
Comment like

[[ [[AjaxSearch? &showResults=`0` &showInputForm=`1` &ajaxSearch=`0` &ajaxSearchType=`0` &extract =`0` &landingPage=`33` &moreResultsPage=`33` &liveSearch=`0` &extract=`1` &advSearch=`allwords` &maxWords=`10` &minChars=`10`]]
]]

not work more - give error "Nesting level too deep"

@yama
Copy link
Collaborator

yama commented Dec 15, 2016

10 is not too small?

It's possible, but it is maybe bug. Wait a moment.

@yama
Copy link
Collaborator

yama commented Dec 15, 2016

while($delim==='`' && substr(trim($_tmp),0,1)!=='&' && trim($_tmp)!=='' && 1<substr_count($_tmp,'`')) {
    list($inner, $outer, $_tmp) = explode('`', $_tmp, 3);
    $value .= "`{$inner}`{$outer}";
    $i++;
    if(10<$i) exit('Nesting level too deep');
}

maybe fix

@MrSwed
Copy link
Contributor

MrSwed commented Dec 15, 2016

it's kind of helped ..

@MrSwed
Copy link
Contributor

MrSwed commented Dec 15, 2016

immediately I do not quite understand this block, but in the call the snippet may be missing ` in values, and settings can be & and &

@yama
Copy link
Collaborator

yama commented Dec 15, 2016

[[ [[AjaxSearch? &showResults=`0` &showInputForm=`1` &ajaxSearch=`0` &ajaxSearchType=`0` &extract =`0` &landingPage=`33` &moreResultsPage=`33` &liveSearch=`0` &extract=`1` &advSearch=`allwords` &maxWords=`10` &minChars=`10`]]
]]

Question. How does this work? I thought it was a magical snippet call.

@MrSwed
Copy link
Contributor

MrSwed commented Dec 16, 2016

here is meant commented out
Of course you can not do so personally, I usually do something like
[[AjaxSearch-off ... ]]

@yama
Copy link
Collaborator

yama commented Dec 16, 2016

Comment out? That's an interesting idea.
ok, I will fix it later.

@yama yama reopened this Dec 16, 2016
yama added a commit that referenced this issue Dec 16, 2016
@yama
Copy link
Collaborator

yama commented Dec 16, 2016

7a2d630
ok?

@MrSwed
Copy link
Contributor

MrSwed commented Dec 19, 2016

new trouble:

[[if? &is=`[*articles_ids*]:!empty`
&then=`
<!-- skipped -->
[[Ditto? &documents=`[*articles_ids*]` &tpl=`articlesTpl` &orderBy=`pub_date DESC,createdon desc` &paginate=`0` &display=`all`]]
<!-- skipped -->`
]]

after update MODX get "Illegal value of... "

  1. If call ditto twice like phx ?

  2. may be here (

    if(!preg_match('@^[0-9, ]*$@',$IDs)) exit(sprintf('Illegal value of &amp;documents: %s', $IDs));
    )
    be better somesthing like

  if(!preg_match('@^[0-9, ]*$@',$IDs))   return array();

@yama
Copy link
Collaborator

yama commented Dec 19, 2016

[[if? &is=`[*articles_ids*]:!empty`
    &then=`
        [[Ditto? &documents=`[*articles_ids*]` &orderBy=`editedon asc`]]
]]

Easily rewritten and tried it, but the problem did not happen. Are there other hints?

@yama
Copy link
Collaborator

yama commented Dec 19, 2016

[[if? &is=`[*articles_ids*]:!empty`
    &then=`[[Ditto? &documents=`[*articles_ids*]`]] `
]]

Does this reproduce the problem?

@MrSwed
Copy link
Contributor

MrSwed commented Dec 19, 2016

when I delete accidentally nonessential (skiped) deleted tilde
so that nothing significant has changed
below is full snipped

[[if? &is=`[*articles_ids*]:!empty`
&then=`
<div id="Obzori">
	<hr>
	<div class="items">
[[Ditto? &documents=`[*articles_ids*]` &tpl=`articlesTpl` &orderBy=`pub_date DESC,createdon desc` &paginate=`0` &display=`all`]]
	</div>
</div>
`
&else=`<div id="Obzori"></div>`
]]

the problem temporarily solved the method proposed above (return array() instead exit

@yama
Copy link
Collaborator

yama commented Dec 19, 2016

Is it related to the nesting of snippet calls?

@MrSwed
Copy link
Contributor

MrSwed commented Dec 20, 2016

I think yes, snippet [[If]] should not call nested Ditto, if the condition does not match

@Deesen
Copy link
Contributor

Deesen commented Dec 20, 2016

But snippet-rendering works recursive from inside to outside, means "snippetIn" will always be rendered before snippetOut to provide a result (for example when using &param=[[ultimateParent]] you need a result first).

[[snippetOut? &param=`[[snippetIn]]`]]

To get around this &param must be able to accept a chunk with snippetIn inside, which will only get parsed by snippetOut if true.

[[if? &is=`1:is:1` &then=`@TPL:snippetIn_chunk`]]

@MrSwed
Copy link
Contributor

MrSwed commented Dec 20, 2016

I think in this case it is necessary to solve both ways

  1. Fix Ditto
  2. Fix nested calls

@yama
Copy link
Collaborator

yama commented Dec 20, 2016

foreach($tags as $tag) {
if(strpos($tag,$left)!==false) {
$innerTags = $this->_getTagsFromContent($tag,$left,$right);
$tags = array_merge($innerTags,$tags);
}
}

Maybe these lines are unnecessary. Because nest processing is done in $modx->getParamsFromString() .

@yama
Copy link
Collaborator

yama commented Dec 21, 2016

document.parser.class.inc.zip
Maybe fixed

yama added a commit that referenced this issue Dec 24, 2016
yama added a commit that referenced this issue Dec 24, 2016
@yama
Copy link
Collaborator

yama commented Dec 24, 2016

660163d
Fixed now. Since there are many repair lines, please test carefully.

@yama
Copy link
Collaborator

yama commented Dec 26, 2016

Found new nest pattern

[[if?
    &is=`1:not:2`
    &then='
        [[if? &is=`1:not:3` &then=`
            [[if? 
                &is=`1:is:4` 
                &then=`aaa`
                &else=`bbb`
            ]]
        `]]
    '
    &else=`ccc`
]]

Not work

@Dmi3yy
Copy link
Collaborator

Dmi3yy commented Dec 26, 2016 via email

@yama
Copy link
Collaborator

yama commented Dec 26, 2016

It's work.
But, remove "&else=`ccc`” will malfunction

@Dmi3yy
Copy link
Collaborator

Dmi3yy commented Dec 26, 2016 via email

@yama
Copy link
Collaborator

yama commented Dec 26, 2016

In fact, a broken character string "aaa`]]`]] "is output. I think this is a malfunction of parser.

@Dmi3yy Dmi3yy added 1.2.2 and removed 1.2.1 labels Dec 26, 2016
@Deesen
Copy link
Contributor

Deesen commented Jan 1, 2017

What is the issue? For me it seems to be working correct. I get result "bbb" for

[[if?
	&is=`1:not:2`
	&then='
		[[if? &is=`1:not:3` &then=`
			[[if? 
				&is=`1:is:4` 
				&then=`aaa`
				&else=`bbb`
			]]
		`]]
	'
	&else=`ccc`
]]

@Dmi3yy
Copy link
Collaborator

Dmi3yy commented Mar 13, 2017

before update
[[Ditto? &tpl=chunk]] and in chunk multiTV with @code. work correct
http://take.ms/PPvzI

after update to last version on git not work

@yama
Copy link
Collaborator

yama commented Mar 23, 2017

[[if?
    &is=`1:not:2`
    &then='
        [[if? &is=`1:not:3` &then=`
            [[if? 
                &is=`1:is:4` 
                &then=`aaa`
                &else=`bbb`
            ]]
        `]]
    '
    &else=`ccc`
]]

Is this a code that does not work?

@Dmi3yy
Copy link
Collaborator

Dmi3yy commented Mar 23, 2017

Tested all ok
[!if? &is=1:not:2 &then=
[!if? &is=1:not:3
&then= [!if? &is=1:not:4 &then=
[!if? &is=1:is:4
&then=aaa
&else=yes
!] &else=bbb !]
!] &else=ccc`
!]

[[if? &is=1:not:2
&then= [[if? &is=1:not:3 &then=
[[if? &is=1:not:4
&then= [[if? &is=1:is:4 &then=aaa &else=yes ]]
&else=bbb
]] ]]
&else=ccc
]]

[!if? &is=1:not:2
&then= [[if? &is=1:not:3 &then=
[!if? &is=1:not:4
&then= [[if? &is=1:is:4 &then=aaa &else=yes ]]
&else=bbb
!] ]]
&else=ccc
!]

[[if? &is=1:not:2
&then= [!if? &is=1:not:3 &then=
[[if? &is=1:not:4
&then= [!if? &is=1:is:4 &then=aaa &else=yes !]
&else=bbb
]] !]
&else=ccc
]]

[[if? &is=1:not:2
&then= [!if? &is=1:not:3 &then=
[!if? &is=1:not:4
&then= [[if? &is=1:is:4 &then=aaa &else=yes ]]
&else=bbb
!] !]
&else=ccc
]]

[!if? &is=1:not:2
&then= [[if? &is=1:not:3 &then=
[[if? &is=1:not:4
&then= [!if? &is=1:is:4 &then=aaa &else=yes !]
&else=bbb
]] ]]
&else=ccc
!]
`
on old parser
yes
yes
yes
aaa
yes
aaa

on new parser

yes
yes
yes
yes
yes
yes

@Dmi3yy Dmi3yy closed this as completed Mar 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants