If I am understanding your solution correctly this still does not work. I tried calling the reload after the creation of the Admin Resource Policy but that seemed to have no effect on the situation. I actually just got a hack solution to work which in itself contradicts the idea that the user needs to be reloaded after the policy. There seems to be something happening at the context level because the hack is placed before I ever create the policy in the first place
### THIS DOES NOT WORK (reloading current user permissions after policy before resource) ###
$modx = new modX();
$modx->initialize('mgr');
$modx->setDebug(true);
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
echo '<pre>'; $modx->setLogTarget('ECHO');
$context_key = 'MigrationTest11';
/*
* Set Context
*/
$context = $modx->newObject('modContext');
$context->fromArray(array(
'key' => $context_key,
'description' => ''
), '', true);
$context->save();
// Administrator "Resource Policy"
$access = $modx->newObject('modAccessContext');
$access->fromArray(array(
'target' => $context_key,
'principal_class' => 'modUserGroup',
'principal' => 1,
'authority' => 9999,
'policy' => 1
), '', true);
$access->save();
$modx->user->getAttributes(array(), '', true);
/*
* Resource "_config"
* Build _config container
*/
$resource = $modx->newObject('modResource');
$resource->fromArray(array(
'type' => 'document',
'contentType' => 'text/html',
'pagetitle' => '_config',
'template' => 0,
'isfolder' => 1,
'context_key' => $context_key,
'hidemenu' => 1,
'alias' => 'config'
), '', true);
$resource->save();
### THIS DOES WORK BUT IS A HACK (reloading modx object and initializing mgr again) ###
$modx = new modX();
$modx->initialize('mgr');
$modx->setDebug(true);
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
echo '<pre>'; $modx->setLogTarget('ECHO');
$context_key = 'MigrationTest11';
/*
* Set Context
*/
$context = $modx->newObject('modContext');
$context->fromArray(array(
'key' => $context_key,
'description' => ''
), '', true);
$context->save();
$modx = new modX();
$modx->initialize('mgr');
// Administrator "Resource Policy"
$access = $modx->newObject('modAccessContext');
$access->fromArray(array(
'target' => $context_key,
'principal_class' => 'modUserGroup',
'principal' => 1,
'authority' => 9999,
'policy' => 1
), '', true);
$access->save();
/*
* Resource "_config"
* Build _config container
*/
$resource = $modx->newObject('modResource');
$resource->fromArray(array(
'type' => 'document',
'contentType' => 'text/html',
'pagetitle' => '_config',
'template' => 0,
'isfolder' => 1,
'context_key' => $context_key,
'hidemenu' => 1,
'alias' => 'config'
), '', true);
$resource->save();