? Success

User tests: Successful: Unsuccessful:

avatar whbean
whbean
12 May 2014

The Hathor template manager fails to display the 'Templates' tab if the site contains a template without xml data (in my case ja_purity). The problem occurs because this file tries to access $this->xmldata->get('version') without checking whether it is null. My proposed fix tests for the case of null xmldata and creates a new object with the required fields. In the case where the xmldata exists, the change creates a cloned object and ensures that the required fields aren't null.

Further down in the code, we access $xmldata, the new object, rather than $item->xmldata.

avatar whbean whbean - open - 12 May 2014
avatar whbean
whbean - comment - 12 May 2014

Tracker item 33726

avatar whbean whbean - change - 13 May 2014
Title
Update default.php to gracefully handle templates with no xml data
Update default.php to gracefully handle templates with no xml data
avatar elkuku
elkuku - comment - 13 May 2014

Ah well, there's another thingy beside the code logic...
We usually use colon notation for control structures in PHP template files like this:

<?php if (condition) : ?>
    // Do something
<?php else : ?>
    // Do something else
<?php endif; ?>

There is no coding standard that would actually enforce this rule, but since the rest of the file already has this notation, I think this should be changed.

Thanks for your patience :wink:

avatar whbean
whbean - comment - 13 May 2014

I understand the importance of style and am happy to make any changes
but I'm afraid I'm not sure what you are asking.

I assume that you are talking about the code block:

<?php
$xmldata = new JRegistry;
if (!$item->xmldata){
$xmldata->set("version", "--");
$xmldata->set("creationDate", "--");
}else{
$xmldata->loadObject($item->xmldata);
if (!$xmldata->get('version')){
$xmldata->set("version", '--');
}
if (!$xmldata->get('creationDate')){
$xmldata->set("creationDate", '--');
}
}
?>

Are you suggesting that I change it like this?

<?php $xmldata = new JRegistry; ?>
<?php if (!$item->xmldata) : ?>
<?php $xmldata->set("version", "--"); ?>
<?php $xmldata->set("creationDate", "--"); ?>
<?php else : ?>
<?php $xmldata->loadObject($item->xmldata); ?>
<?php if (!$xmldata->get('version')) : ?>
<?php $xmldata->set("version", '--'); ?>
<?php endif; ?>
<?php if (!$xmldata->get('creationDate')) : ?>
<?php $xmldata->set("creationDate", '--'); ?>
<?php endif; ?>
<?php endif; ?>

If so, I'll make the change. If not, perhaps you could enlighten me :)

Bill

On 5/12/2014 11:58 PM, Nikolai Plath wrote:

Ah well, there's another thingy beside the code logic...
We usually use colon notation for control structures in PHP template
files like this:

|<?php if (condition) : ?>
// Do something
<?php else : ?>
// Do something else
<?php endif; ?>
|

There is no coding standard that would actually enforce this rule, but
since the rest of the file already has this notation, I think this
should be changed.

Thanks for your patience :wink:


Reply to this email directly or view it on GitHub
#3589 (comment).

No virus found in this message.
Checked by AVG - www.avg.com http://www.avg.com
Version: 2014.0.4577 / Virus Database: 3931/7483 - Release Date: 05/12/14

avatar elkuku
elkuku - comment - 13 May 2014

Yes that would be it, but I think we all agree that it looks like hell...

The best solution would be not to mix that much PHP logic in template files.

The second best solution, IMHO, would be to use just one pair of PHP tags to surround the whole block

<?php
       $xmldata = new JRegistry;
       if (!$item->xmldata) :
            $xmldata->set("version", "--");
            $xmldata->set("creationDate", "--");
       else :
            $xmldata->loadObject($item->xmldata);
            if (!$xmldata->get('version')) :
                 $xmldata->set("version", '--');
            endif;

            if (!$xmldata->get('creationDate')):
                 $xmldata->set("creationDate", '--');
            endif;
        endif;
?>

What do you think?

avatar whbean
whbean - comment - 13 May 2014

Well, your second-best solution looks like the code that I've already
committed. That would be ok with me, I'm just trying to protect other
people who have migrated sites from 1.5 to 1.6 to 1.7 to 2.5 from the
frustration that I experienced when the template manager failed.

The alternative approach would be to put the code into
administrator/components/com_templates/models/templates.php around line
65. That would solve the problem for all templates but it's much harder
to know what the side effects might be.

Bill Bean

On 5/13/2014 2:03 PM, Nikolai Plath wrote:

Yes that would be it, but I think we all agree that it looks like hell...

The best solution would be not to mix that much PHP logic in template
files.

The second best solution, IMHO, would be to use just one pair of PHP
tags to surround the whole block

|<?php
$xmldata = new JRegistry;
if (!$item->xmldata) :
$xmldata->set("version", "--");
$xmldata->set("creationDate", "--");
else :
$xmldata->loadObject($item->xmldata);
if (!$xmldata->get('version')) :
$xmldata->set("version", '--');
endif;

         if (!$xmldata->get('creationDate')):
              $xmldata->set("creationDate", '--');
         endif;
     endif;

?>
|

What do you think?

Reply to this email directly or view it on GitHub
#3589 (comment).

No virus found in this message.
Checked by AVG - www.avg.com http://www.avg.com
Version: 2014.0.4577 / Virus Database: 3950/7486 - Release Date: 05/13/14

avatar zero-24
zero-24 - comment - 16 May 2014

@whbean same issue is here:
https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_templates/views/template/tmpl/default_description.php

If you access the Template Manager: Customise Template -> Template Description

avatar whbean
whbean - comment - 16 May 2014

Yes, that is much the same problem, although in your case it is the
description field, which was not involved in the one that I found. We
could fix this by surrounding the reference to xmldata->description with
an if statement. Note that modifying
administrator/components/com_templates/models/templates.php around line
65 would not fix this problem since the description file bypasses the
code in TemplatesModelTemplates::getItems.

I am unclear on where this process stands. Do I need to do something more?

Bill Bean

On 5/16/2014 2:29 PM, zero-24 wrote:

@whbean https://github.com/whbean same issue is here:
https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_templates/views/template/tmpl/default_description.php

If you access the Template Manager: Customise Template -> Template
Description


Reply to this email directly or view it on GitHub
#3589 (comment).

No virus found in this message.
Checked by AVG - www.avg.com http://www.avg.com
Version: 2014.0.4577 / Virus Database: 3950/7504 - Release Date: 05/16/14

avatar brianteeman brianteeman - change - 21 Aug 2014
Status New Pending
avatar nicksavov nicksavov - change - 21 Aug 2014
Title
Update default.php to gracefully handle templates with no xml data
Update default.php to gracefully handle templates with no xml data
Labels Removed: ?
avatar brianteeman brianteeman - change - 8 Sep 2014
Category Templates (admin)
avatar nicksavov nicksavov - change - 16 Oct 2014
Labels Added: ?
avatar brianteeman brianteeman - change - 1 Jan 2015
Labels Removed: ?
avatar Kubik-Rubik
Kubik-Rubik - comment - 6 Aug 2015

Thank you for your contribution, @whbean. I've just tested it in the current staging version and no errors occured. The fields for the values were just blank. Since this is not a bug, I'll close this PR now. Feel free to do a new PR if you still have a problem!

avatar Kubik-Rubik Kubik-Rubik - change - 6 Aug 2015
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2015-08-06 11:28:28
Closed_By Kubik-Rubik
avatar Kubik-Rubik Kubik-Rubik - close - 6 Aug 2015

Add a Comment

Login with GitHub to post a comment