Server : Apache System : Linux indy02.toastserver.com 3.10.0-962.3.2.lve1.5.85.el7.x86_64 #1 SMP Thu Apr 18 15:18:36 UTC 2024 x86_64 User : palandch ( 1163) PHP Version : 7.1.33 Disable Function : NONE Directory : /home/palandch/www/core/model/modx/processors/security/resourcegroup/ |
<?php /** * Update documents in a resource group * * @var modX $modx * @var array $scriptProperties * @var modProcessor $this * * @package modx * @subpackage processors.security.resourcegroup */ if (!$modx->hasPermission('resourcegroup_resource_edit')) return $modx->error->failure($modx->lexicon('permission_denied')); $modx->lexicon->load('resource','access'); /* format data */ $scriptProperties['resource'] = substr(strrchr($scriptProperties['resource'],'_'),1); $scriptProperties['resourceGroup'] = substr(strrchr($scriptProperties['resourceGroup'],'_'),1); if (empty($scriptProperties['resource']) || empty($scriptProperties['resourceGroup'])) return $modx->error->failure('Invalid data.'); /* @var modResource $resource */ $resource = $modx->getObject('modResource',$scriptProperties['resource']); if ($resource == null) return $modx->error->failure($modx->lexicon('resource_err_nfs',array('id' => $scriptProperties['resource']))); /* @var modResourceGroup $resourceGroup */ $resourceGroup = $modx->getObject('modResourceGroup',$scriptProperties['resourceGroup']); if ($resourceGroup == null) return $modx->error->failure($modx->lexicon('resource_group_err_ns')); /* check to make sure already isnt in group */ $alreadyExists = $modx->getObject('modResourceGroupResource',array( 'document' => $resource->get('id'), 'document_group' => $resourceGroup->get('id'), )); if ($alreadyExists) return $modx->error->failure($modx->lexicon('resource_group_resource_err_ae')); /* create resource group -> resource pairing */ /** @var $resourceGroupResource modResourceGroupResource */ $resourceGroupResource = $modx->newObject('modResourceGroupResource'); $resourceGroupResource->set('document',$resource->get('id')); $resourceGroupResource->set('document_group',$resourceGroup->get('id')); if ($resourceGroupResource->save() == false) { return $modx->error->failure($modx->lexicon('resource_group_resource_err_create')); } else { $modx->invokeEvent('OnResourceAddToResourceGroup',array( 'mode' => 'resource-group-tree-drag', 'resource' => &$resource, 'resourceGroup' => &$resourceGroup, )); } return $modx->error->success('',$resourceGroupResource);