Maybe you're able to pull out something from the following method I'm using in a script of mine, it uses the resource create processor as Bob suggested
/**
* Recursively adds resources to a specified context
*
* @param $resources An array of resources to create
*
* @return bool
*/
public function createResources(array $resources = array(), $context = '') {
if ( !empty($context) ) {
foreach ($resources as $resource) {
if ( !empty($resource['class_key']) ) {
$classkey = $resource['class_key'];
} else {
$classkey = 'modResource';
}
$resource['context_key'] = $context;
$resource['alias'] = !empty($resource['alias']) ? $resource['alias'] : $this->modx->call('modResource', 'filterPathSegment', array(&$this->modx, $resource['pagetitle']));
// extract child resources
$children = isset($resource['children']) ? $resource['children'] : array();
unset($resource['children']);
// get resource object for the following child resources and resource field checks (we need the parent id and the fields)
$resobj = $this->modx->getObject($classkey, array('pagetitle' => $resource['pagetitle'], 'context_key' => $resource['context_key']));
if ( !$resobj ) {
$response = $this->modx->runProcessor('resource/create', $resource);
if ( !$response->isError() ) {
$this->log('info', 'Successfully created new resource ' . $resource['pagetitle'], __METHOD__, __LINE__);
$resarr = $response->getObject();
$this->log('info', '$resobj ' . print_r($resobj, 1), __METHOD__, __LINE__, 'FILE', $this->config['debug']);
} else {
$this->log('error', 'Failed to create new resource ' . $resource['pagetitle'] . ', Errors: ' . implode(', ', $response->getAllErrors()), __METHOD__, __LINE__);
}
} else {
$this->log('info', 'Resource with pagetitle ' . $resource['pagetitle'] . ' already exists, skipping...', __METHOD__, __LINE__);
// initialize the update variable
$update = false;
// check if any existing resource field values need an update
foreach ($resource as $field => $value) {
if ( $value != $resobj->get($field) ) {
$this->log('info', 'Existing resource field "' . $field . '" has not the same value as the config resource field: ' . $resobj->get($field) . ' !== ' . $value . ', updating resource object', __METHOD__, __LINE__);
$resobj->set($field, $value);
$update = true;
}
}
// updated exting resource fields
if ( $update ) {
$response = $this->modx->runProcessor('resource/update', $resobj->toArray());
if ( !$response->isError() ) {
// we do not get back any details about the created access policy from the processor, so we just give the filename back
$this->log('info', 'Successfully updated resource ' . $resobj->get('pagetitle'), __METHOD__, __LINE__);
// once an update is done all changes are taken over, no need to do this for every field
continue;
} else {
$this->log('error', 'Failed to update resource ' . $resobj->get('pagetitle') . ', Errors: ' . implode(', ', $response->getAllErrors()), __METHOD__, __LINE__);
}
}
// convert resource object to array for the following child resources check (we need the parent id)
$resarr = $resobj->toArray();
}
// recursively create child resources
if ( !empty($children) && isset($resarr['id']) ) {
foreach ($children as $index => $child) {
$children[$index]['parent'] = $resarr['id'];
}
$this->createResources($children, $context);
}
}
}
}
this method takes an array of resources + a context key (where to create those resouce) like this:
$resources = array(
'pagetitle' => 'Parent Resource',
'published' => 1,
'hidemenu' => 0,
'children' => array(
array(
'pagetitle' => 'Child Resource 1',
'published' => 1,
'hidemenu' => 0,
),
array(
'pagetitle' => 'Child Resource 2',
'published' => 1,
'hidemenu' => 0,
),
array(
'pagetitle' => 'Child Resource 3',
'published' => 1,
'hidemenu' => 0,
),
),
);
if you can convert your CSV data to an array in this form, it should be very easy, you can specify any resource fields + values in the resource arrays, not just the shown ones...
you need to adapt the method above a bit to run it isolated as it's pulled from a class, e.g. all the $this-> stuff will not work like that...