Project

General

Profile

Task #92346 » copyPreset.php

example script for duplicating an impexp preset - Rémy DANIEL, 2020-10-02 23:04

 
<?php

class T3dUtility
{
/**
* Save a preset record
*
* @param int $uid
* @param int $newPid
* @param string $type
* @return int Created preset ID
* @throws \Exception
*/
public function copyPreset($uid, $newPid, $type)
{
$preset = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'tx_impexp_presets', 'uid=' . (int)$uid);
if (!$preset) {
throw new \Exception('Unable to load the preset ' . $uid);
}
$data = unserialize($preset['preset_data']);
if (!$data) {
throw new \Exception('Unable to deserialize data of the preset ' . $uid);
}

$data['pagetree']['id'] = $newPid;
$data['pagetree']['maxNumber'] = 100;
$data['filename'] = "export_{$type}_{$newPid}.t3d";
$data['preset']['title'] = "Export $type";
$data['maxFileSize'] = 1000000;
$data['softrefCfg'] = [];

unset($preset['uid']);
$preset['title'] = "Export $type";
$preset['item_uid'] = $newPid;
$preset['preset_data'] = serialize($data);

$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_impexp_presets', $preset);

return $GLOBALS['TYPO3_DB']->sql_insert_id();
}
}
(6-6/6)