View Issue Details

IDProjectCategoryView StatusLast Update
0006287OXID eShop (all versions)4.01. Database handlingpublic2024-02-29 07:35
Reporterleofonic Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Product Version4.9.6 / 5.2.6 
Summary0006287: oxarticle::load doesn't reset long description
DescriptionIf an oxarticle object is reused by calling load() with another oxid, an already fetched long description will not be filled with new data.
Steps To Reproduceexecute this in root directory:

<?php
require_once "bootstrap.php";
$oArticle = oxnew('oxarticle');
//load Trapez ION MADTRIXX
$oArticle->load('05848170643ab0deb9914566391c0c63');
//Long description is from Trapez ION MADTRIXX
var_dump($oArticle->getLongDescription());
//load Klebeband DACRON KITEFIX
$oArticle->load('0584e8b766a4de2177f9ed11d1587f55');
//Long description is from Trapez ION MADTRIXX
var_dump($oArticle->getLongDescription());
TagsArticle
ThemeNot defined
BrowserNot defined
PHP VersionNot defined
Database VersionNot defined

Relationships

has duplicate 0007298 closed Artikel Langbeschreibung wird mit der 1. geladenen Sprache überschrieben 

Activities

michael_keiluweit

2015-12-15 09:14

administrator   ~0011375

Reporter is right. After calling the long description by its getter there is no "good" way to put the value back to "null", therefore the getter would have to load it again.


It's needed to consider how it should be handled correctly:

1. The method "load" has to check if the object was already loaded. This can be done by checking the given parameter oxid if it is different to the stored oxid in the article object. If they aren't equal, the object must be reset like as oxNew('oxarticle') would do.
2. reload / reset function. Makes the same as 1., it's just a clearer way to go and less magic.
3. Define a general rule: Don't use the method load to recycle an object, instantiate an own object instead of use an old one.


A quick hack to force a reload of the long description if the given oxid is different to the last one, is to overwrite the load method and add at the top the following check:
if ($sOXID !== $this->_sOXID) {
    $this->_oLongDesc = null;
}

leofonic

2015-12-15 12:47

reporter   ~0011376

I think you can take away the condition and just use
$this->_oLongDesc = null;
in load() method.

Even if the same oxid is loaded, which would be a rare case anyway, you do not want cached content but content from DB.

"3. Define a general rule: Don't use the method load to recycle an object,"
I would rather define a general rule: method load should reset cached content. Reusing objects makes sense because it uses less memory.

SvenBrunk

2024-02-29 07:35

administrator   ~0016328

We discussed this internally and came to the conclusion that we will not change this at the current time.
Some reasons for this are as follows:
- The load function works fine for most objects except Article as they are much simpler
- It was never intended to be used like this, and it was designed before any object introduced additional relations like oxartextends in the Article class
- If you use this function like this for this kind of optimization reasons, you need to know what you are doing.
- The provided "hack" by Michael is actually not a hack at all. It is the thing you need to do with everything that does not originate from the original table