Bug #31139

better condition in versionOL of t3lib_tstemplate

Added by Stefan Froemken over 1 year ago. Updated about 1 year ago.

Status:Resolved Start date:2011-10-20
Priority:Should have Due date:
Assignee:- % Done:

100%

Category:Backend API
Target version:4.5.12
TYPO3 Version:4.5 Complexity:easy
PHP Version:5.3
Votes: 0

Description

Hello Core-Team,

in current TYPO3 4.5.7 you have following method in class.t3lib_tstemplate.php:

function versionOL(&$row) {
    if (is_object($GLOBALS['TSFE'])) { // Frontend:
        $GLOBALS['TSFE']->sys_page->versionOL('sys_template', $row);
    } else { // Backend:
        t3lib_BEfunc::workspaceOL('sys_template', $row);
    }
}

You only need to set something:
$GLOBALS['TSFE']->register['hello'] = 1;
or play with cObj in BE Mode and $GLOBALS['TSFE'] get's a value.

In this case is_object($GLOBALS['TSFE']) returns true, because it is of class stdClass now.

So...to prevent calling $GLOBALS['TSFE']->sys_page->versionOL in BE-Mode it's better to modify the condition that way:

function versionOL(&$row) {
    if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE']) && get_class($GLOBALS['TSFE']) == 'tslib_fe') { // Frontend:
        $GLOBALS['TSFE']->sys_page->versionOL('sys_template', $row);
    } else { // Backend:
        t3lib_BEfunc::workspaceOL('sys_template', $row);
    }
}

Stefan


Related issues

related to Core - Bug #36981: Regression of "better condition in versionOL of t3lib_tst... Resolved 2012-05-09
duplicated by Core - Bug #25144: Incorrect check for fe / be context in class.t3lib_tstemp... Resolved 2011-02-23

Associated revisions

Revision a49c4a49
Added by Mario Rimann about 1 year ago

[BUGFIX] Better condition in versionOL of t3lib_tstemplate

Changes the condition to determine whether we're in the
frontend or in the backend.

Change-Id: I989359e25c6f05e3075b2a2403a5ba2487b45c90
Related: #25144
Resolves: #31139
Releases: 4.5
Reviewed-on: http://review.typo3.org/7043
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Oliver Klee
Reviewed-by: Markus Klein
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter

Revision 4163ef3b
Added by Andy Grunwald about 1 year ago

[BUGFIX] Regression of "better condition in versionOL of t3lib_tstemplate"

versionOL in t3lib_tstemplate can cause a fatal error for
scripts like eID that run in frontend mode, but without a full
blown frontend environment.

The patch replaces the frontend check with a more specific test
for the required methods.

Change-Id: Ib3f9ebf355ee820e5144dd484d9a3a5e7708ebd4
Related: #31139, #25144
Resolves: #36981
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/11096
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog

Revision d1267992
Added by Andy Grunwald about 1 year ago

[BUGFIX] Regression of "better condition in versionOL of t3lib_tstemplate"

versionOL in t3lib_tstemplate can cause a fatal error for
scripts like eID that run in frontend mode, but without a full
blown frontend environment.

The patch replaces the frontend check with a more specific test
for the required methods.

Change-Id: I9c9cdfd494044a23def97db90ec3adf528e86f39
Related: #31139, #25144
Resolves: #36981
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/11099
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog

Revision b85d5cda
Added by Andy Grunwald about 1 year ago

[BUGFIX] Regression of "better condition in versionOL of t3lib_tstemplate"

versionOL in t3lib_tstemplate can cause a fatal error for
scripts like eID that run in frontend mode, but without a full
blown frontend environment.

The patch replaces the frontend check with a more specific test
for the required methods.

Change-Id: I9920cf185883d35c2121077b62e34c76ace72a94
Related: #31139, #25144
Resolves: #36981
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/11098
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog

Revision 1125e3dd
Added by Andy Grunwald about 1 year ago

[BUGFIX] Regression of "better condition in versionOL of t3lib_tstemplate"

versionOL in t3lib_tstemplate can cause a fatal error for
scripts like eID that run in frontend mode, but without a full
blown frontend environment.

The patch replaces the frontend check with a more specific test
for the required methods.

Change-Id: If7712903b96922ea3da51218d3ed5ff2496168f8
Related: #31139, #25144
Resolves: #36981
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/11097
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog

Revision 5e54ece3
Added by Andy Grunwald 11 months ago

[BUGFIX] Regression of "better condition in versionOL of t3lib_tstemplate"

versionOL in t3lib_tstemplate can cause a fatal error for
scripts like eID that run in frontend mode, but without a full
blown frontend environment.

The patch replaces the frontend check with a more specific test
for the required methods.

Change-Id: Ib3f9ebf355ee820e5144dd484d9a3a5e7708ebd4
Related: #31139, #25144
Resolves: #36981
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/11096
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog

History

Updated by Benjamin Mack over 1 year ago

Hey,

how about

if ($GLOBALS['TSFE'] && $GLOBALS['TSFE']->sys_page) {
...
}

?

Updated by Stefan Froemken over 1 year ago

Your version works, too. But I don't know if this is the more better/best version.

Updated by Steffen Ritter over 1 year ago

  • Status changed from New to Accepted
  • Complexity set to easy

Stefan Froemken wrote:

Your version works, too. But I don't know if this is the more better/best version.

As Benni's shorter and has one check less, it is better. Furthermore you may have tslib_fe class with sys_page ==null.

Would you mind to push a change to Gerrit?

Updated by Markus Klein over 1 year ago

I disagree.
Benni's version will cause a warning when sys_page does not exist.
Please stick to thorough checking with isset().

Updated by Gerrit Code Review over 1 year ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch TYPO3_4-5 has been pushed to the review server.
It is available at http://review.typo3.org/7043

Updated by Mario Rimann over 1 year ago

I checked and the condition is built way different in 4.6 and 4.7 -> so I pushed the patch only for 4.5

Updated by Gerrit Code Review over 1 year ago

Patch set 2 for branch TYPO3_4-5 has been pushed to the review server.
It is available at http://review.typo3.org/7043

Updated by Gerrit Code Review over 1 year ago

Patch set 3 for branch TYPO3_4-5 has been pushed to the review server.
It is available at http://review.typo3.org/7043

Updated by Gerrit Code Review over 1 year ago

Patch set 4 for branch TYPO3_4-5 has been pushed to the review server.
It is available at http://review.typo3.org/7043

Updated by Ernesto Baschny over 1 year ago

  • Target version changed from 4.5.8 to 4.5.12

Updated by Gerrit Code Review about 1 year ago

Patch set 5 for branch TYPO3_4-5 has been pushed to the review server.
It is available at http://review.typo3.org/7043

Updated by Mario Rimann about 1 year ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Updated by Stefano Cecere about 1 year ago

i found that this change i causing fatal errors.

(i checked (and another user found it , too) with yag extension
see http://forge.typo3.org/issues/36487 for full error report

the problem is

    function versionOL(&$row) {
        if (TYPO3_MODE === 'FE') { // Frontend:
            $GLOBALS['TSFE']->sys_page->versionOL('sys_template', $row);
        } else { // Backend:
            t3lib_BEfunc::workspaceOL('sys_template', $row);
        }
    }

which i have to revert to:

    function versionOL(&$row) {
        if (is_object($GLOBALS['TSFE'])) { // Frontend:
            $GLOBALS['TSFE']->sys_page->versionOL('sys_template', $row);
        } else { // Backend:
            t3lib_BEfunc::workspaceOL('sys_template', $row);
        }
    }

(i tried to XCLASS versionOL with the working one, but it seems not possible.. old versionOL() is always called :(

what do you think?

Updated by Stefano Cecere about 1 year ago

sorry.. i think the problem is somewhere else..

versionOL gets called from t3lib_TStemplate->runThroughTemplates( ) but the sys_page is not fully instantiated...
the problem seems to be in pt_extbase

sorry for this false alarm

Updated by Andy Grunwald about 1 year ago

Hey all,

the comitted changed cause a Fatal error in the frontend if you use an eID and you work with the tstemplate class.
Why? It is quite easy. eID has the TYPO3_MODE FE but has no full blown up Frontend (e.g. $GLOBALS['TSFE'] / $GLOBALS['TSFE']->sys_page).

In our case we create via direct_mail api new mailings via an eid.
Direct mail calls this method to get the correct charset for this page.
So, with the new patch we got

Fatal error: Call to a member function versionOL() on a non-object in /var/www/dasgastroportal.dus.wmdb.de/typo3_src-4.5.15/t3lib/class.t3lib_tstemplate.php 
on line 753

In my opinion, this is a regression.

I will provide a patch.
See Bug #36981 "Regression of "better condition in versionOL of t3lib_tstemplate" (#31139)" for more information.

Also available in: Atom PDF