modxcms / revolution

MODX Revolution - Content Management Framework
https://modx.com/
GNU General Public License v2.0
1.35k stars 528 forks source link

modResource->setTVValue($pk,$value) Fails on a Cached Resource #5294

Open wshawn opened 12 years ago

wshawn commented 12 years ago

wshawn created Redmine issue ID 5294

If the Resource itself is cached, this function never seems to fire.

Implementation:

$resourceObj = (!empty($resourceId)) ? $modx->getObject('modResource', $resourceId) : $modx->resource;
$resourceObj->setTVValue('myTV', $myValue);
wshawn commented 12 years ago

wshawn submitted:

The snippet is being called uncached.

modxbot commented 12 years ago

okyanet submitted:

Looks like this issue is still affecting 2.2: http://forums.modx.com/thread/?thread=73758&page=1

gadgetto commented 11 years ago

gadgetto submitted:

Still same problem here (MODx Revo 2.2.4-pl):

http://forums.modx.com/thread/77491/can-anyone-plz-tell-me-why-this-snippet-pair-only-works-once-using-gettvvalue-and-settvvalue-methods

and:

http://tracker.modx.com/issues/8360

ilyautkin commented 5 years ago

Method getTVValue returns value from resource cache (if exists). This is expected behavior. Also as method get returns field of resource, saved in cache (if exists).

For getting data from database use xPDO:

// value from cache
$myValue = $modx->resource->getTVValue('myTV');

// request to database
$tvValue = $modx->getObject('modTemplateVarResource', [
    'tmplvarid' => 3, 'contentid' => $modx->resource->id
]);

if ($tvValue) {
    $myValue = $tvValue->value;
}

// saving
$myValue++;
$modx->resource->setTVValue('myTV', $myValue);