Project

General

Profile

Actions

Bug #31139

closed

better condition in versionOL of t3lib_tstemplate

Added by Stefan Froemken over 12 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Backend API
Target version:
Start date:
2011-10-20
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
4.5
PHP Version:
5.3
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

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 2 (0 open2 closed)

Related to TYPO3 Core - Bug #36981: Regression of "better condition in versionOL of t3lib_tstemplate" (#31139)ClosedAndy Grunwald2012-05-09

Actions
Has duplicate TYPO3 Core - Bug #25144: Incorrect check for fe / be context in class.t3lib_tstemplate.phpClosed2011-02-23

Actions
Actions #1

Updated by Benni Mack over 12 years ago

Hey,

how about

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

?

Actions #2

Updated by Stefan Froemken over 12 years ago

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

Actions #3

Updated by Steffen Ritter over 12 years 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?

Actions #4

Updated by Markus Klein over 12 years ago

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

Actions #5

Updated by Gerrit Code Review over 12 years 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

Actions #6

Updated by Mario Rimann over 12 years 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

Actions #7

Updated by Gerrit Code Review over 12 years 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

Actions #8

Updated by Gerrit Code Review over 12 years 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

Actions #9

Updated by Gerrit Code Review over 12 years 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

Actions #10

Updated by Ernesto Baschny over 12 years ago

  • Target version changed from 4.5.8 to 4.5.12
Actions #11

Updated by Gerrit Code Review about 12 years 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

Actions #12

Updated by Mario Rimann about 12 years ago

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

Updated by Stefano Cecere about 12 years 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?

Actions #14

Updated by Stefano Cecere about 12 years 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

Actions #15

Updated by Andy Grunwald almost 12 years 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.

Actions #16

Updated by Riccardo De Contardi over 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF