Hello!
I'm trying change resource TV and fields with following code:
$input = array('tv'=>array(),'field'=>array());
$input['tv']['complex_location'] = '79';
$input['tv']['complex_address'] ='Седина 222';
$input['field']['pagetitle'] = 'ЖК Понедель';
$input['field']['parent'] = 11;
$complexResource = $modx->getObject('modResource', 188);
if (!$complexResource) {
$modx->log(modX::LOG_LEVEL_ERROR, '[update_complex] can`t read object');
exit();
}
foreach ($input as $type=>$fields) {
if ($type == 'tv') {
foreach($fields as $TVname=>$TVvalue) {
if (!$complexResource->setTVValue($TVname, $TVvalue)) {
$modx->log(modX::LOG_LEVEL_ERROR, "[update_complex] can`t save tv $TVname with value $TVvalue");
}
}
} else {
$properties = array_merge(array('id'=>188), $fields);
$response = $modx->runProcessor('resource/update', $properties);
if ($response->isError()) {
$modx->log(modX::LOG_LEVEL_ERROR, '[update_complex] update error. Processor response: '.$response->getMessage());
} else {
$modx->log(modX::LOG_LEVEL_ERROR, '[update_complex] resource updated successfully');
}
}
}
but this throw error:
Fatal error: Call to a member function getOption() on a non-object in /path/to/site/core/model/modx/modresource.class.php on line 884
Code in this place is:
public function getAliasPath($alias = '',array $fields = array()) {
if (empty($fields)) $fields = $this->toArray();
$workingContext = $this->xpdo->getContext($fields['context_key']);
if (empty($fields['uri_override']) || empty($fields['uri'])) {
/* auto assign alias if using automatic_alias */
if (empty($alias) && $workingContext->getOption('automatic_alias', false)) {
$alias = $this->cleanAlias($fields['pagetitle']);
} elseif (empty($alias) && isset($fields['id']) && !empty($fields['id'])) {
$alias = $this->cleanAlias($fields['id']);
} else {
$alias = $this->cleanAlias($alias);
}
$fullAlias= $alias;
$isHtml= true;
$extension= '';
$containerSuffix= $workingContext->getOption('container_suffix', ''); //string #884
I founded this article
https://forums.modx.com/?action=thread&thread=77013 and it works. But in source file /core/model/modx/processors/resource/update.class.php written that
* @param string $context_key (optional) The context in which this resource is located. Defaults to web.
and I have NOT to specify this parameter. But in fact, I have to.
Is it mistake in source code developers comment or a bug or something else?