3 declare(strict_types=1);
55 $this->db = $DIC->database();
56 $this->tree = $DIC->repositoryTree();
57 $this->copy_id = $a_copy_id;
66 if (isset(self::$instances[$a_copy_id])) {
67 return self::$instances[$a_copy_id];
75 if (array_key_exists(0, $this->options) && is_array($this->options[0])) {
76 $steps += count($this->options[0]);
78 if (array_key_exists(-1, $this->options) && is_array($this->options[-1])) {
79 $steps += count($this->options[-1]);
88 $ilDB = $DIC->database();
90 $query =
"SELECT * FROM copy_wizard_options " .
91 "WHERE copy_id = " .
$ilDB->quote($a_copy_id,
'integer') .
" ";
93 return !
$res->numRows();
104 $ilDB = $DIC->database();
105 $query =
"SELECT MAX(copy_id) latest FROM copy_wizard_options ";
109 $ilDB->insert(
"copy_wizard_options", array(
110 "copy_id" => array(
"integer", ((
int) $row->latest) + 1),
111 "source_id" => array(
"integer", 0)
113 return ((
int) $row->latest) + 1;
123 $ilDB = $DIC->database();
124 $ilDB->insert(
"copy_wizard_options", array(
125 "copy_id" => array(
"integer", $this->
getCopyId()),
126 "source_id" => array(
"integer", self::OWNER_KEY),
127 "options" => array(
'clob', serialize(array($a_user_id)))
138 $ilDB = $DIC[
'ilDB'];
140 $ilDB->insert(
"copy_wizard_options", array(
141 "copy_id" => array(
"integer", $this->
getCopyId()),
142 "source_id" => array(
"integer", self::ROOT_NODE),
143 "options" => array(
'clob', serialize(array($a_root)))
154 return in_array($a_root, $this->
getOptions(self::ROOT_NODE));
159 $options = $this->
getOptions(self::ROOT_NODE);
160 if (!is_array($options) || !array_key_exists(0, $options)) {
163 return (
int) $options[0];
171 $this->options[self::DISABLE_SOAP] = 1;
173 $this->db->insert(
"copy_wizard_options", array(
174 "copy_id" => array(
"integer", $this->
getCopyId()),
175 "source_id" => array(
"integer", self::DISABLE_SOAP),
176 "options" => array(
'clob', serialize(array(1)))
186 $this->options[self::DISABLE_TREE_COPY] = 1;
188 $this->db->insert(
"copy_wizard_options", array(
189 "copy_id" => array(
"integer", $this->
getCopyId()),
190 "source_id" => array(
"integer", self::DISABLE_TREE_COPY),
191 "options" => array(
'clob', serialize(array(1)))
200 if (isset($this->options[self::DISABLE_TREE_COPY]) && $this->options[self::DISABLE_TREE_COPY]) {
211 if (isset($this->options[self::DISABLE_SOAP]) and $this->options[self::DISABLE_SOAP]) {
222 return in_array($a_user_id, $this->
getOptions(self::OWNER_KEY));
232 $mapping_source = $this->tree->getParentId($a_source_id);
245 $this->tmp_tree = [];
249 $this->db->update(
"copy_wizard_options", array(
250 "options" => array(
'clob', serialize($a_tree_structure))
252 "copy_id" => array(
'integer', $this->
getCopyId()),
253 "source_id" => array(
'integer',
258 $this->db->insert(
'copy_wizard_options', array(
259 'copy_id' => array(
'integer', $this->
getCopyId()),
260 'source_id' => array(
'integer', -1),
261 'options' => array(
'clob', serialize($a_tree_structure))
271 if (isset($tree[0]) and is_array($tree[0])) {
298 if (!isset($this->options[$a_id]) || !is_array($this->options[$a_id])) {
301 $this->options[$a_id] = array_slice($this->options[$a_id], 1);
303 $this->db->update(
'copy_wizard_options', array(
304 'options' => array(
'clob', serialize($this->options[$a_id]))
306 'copy_id' => array(
'integer', $this->
getCopyId()),
307 'source_id' => array(
'integer', $a_id)
315 if ($node[
'type'] ==
'rolf') {
344 if (isset($this->options[$a_source_id]) and is_array($this->options[$a_source_id])) {
345 return $this->options[$a_source_id];
353 public function addEntry(
int $a_source_id, array $a_options): void
355 $query =
"DELETE FROM copy_wizard_options " .
356 "WHERE copy_id = " . $this->db->quote($this->copy_id,
'integer') .
" " .
357 "AND source_id = " . $this->db->quote($a_source_id,
'integer');
359 $this->db->insert(
'copy_wizard_options', array(
360 'copy_id' => array(
'integer', $this->copy_id),
361 'source_id' => array(
'integer', $a_source_id),
362 'options' => array(
'clob', serialize($a_options))
374 $query =
"SELECT * FROM copy_wizard_options " .
375 "WHERE copy_id = " . $this->db->quote($this->copy_id,
'integer') .
" " .
376 "AND source_id = -2 ";
380 $mappings = unserialize((
string) $row->options);
382 $mappings[$a_source_id] = $a_target_id;
384 $query =
"DELETE FROM copy_wizard_options " .
385 "WHERE copy_id = " . $this->db->quote($this->
getCopyId(),
'integer') .
" " .
386 "AND source_id = -2 ";
389 $this->db->insert(
'copy_wizard_options', array(
390 'copy_id' => array(
'integer', $this->
getCopyId()),
391 'source_id' => array(
'integer', -2),
392 'options' => array(
'clob', serialize($mappings))
398 if (isset($this->options[-2]) and is_array($this->options[-2])) {
399 return $this->options[-2];
406 if (isset(self::$instances[$this->copy_id])) {
407 unset(self::$instances[$this->copy_id]);
409 $query =
"DELETE FROM copy_wizard_options " .
410 "WHERE copy_id = " . $this->db->quote($this->copy_id,
'integer');
416 $query =
"SELECT * FROM copy_wizard_options " .
417 "WHERE copy_id = " . $this->db->quote($this->copy_id,
'integer');
422 $this->options[(
int) $row->source_id] = unserialize((
string) $row->options);
433 $this->tmp_tree[] = $this->tree->getNodeData($a_source_id);
434 foreach ($this->tree->getChilds($a_source_id) as $sub_nodes) {
435 $sub_node_ref_id = (
int) $sub_nodes[
'child'];
437 $options = $this->options[$sub_node_ref_id] ?? [];
438 $type = (
int) ($options[
'type'] ?? 0);
439 if (
$type === self::COPY_WIZARD_COPY or
440 $type === self::COPY_WIZARD_LINK) {
fetchFirstNodeById($a_id)
Get first node of stored tree.
saveRoot(int $a_root)
Save root node id.
const COPY_WIZARD_UNDEFINED
fetchFirstNode()
Fetch first node for cloneObject.
checkOwner(int $a_user_id)
check owner
disableSOAP()
Disable soap calls.
dropFirstNodeById(int $a_id)
Drop first node by id.
fetchFirstDependenciesNode()
Fetch first dependencies node.
storeTree(int $a_source_id)
Save tree Stores two copies of the tree structure: id 0 is used for recursive call of cloneObject() i...
saveOwner(int $a_user_id)
Save owner for copy.
readTree(int $a_source_id)
Purge ommitted node recursively private.
getOptions(int $a_source_id)
Get entry by source public.
isSOAPEnabled()
Check if SOAP calls are disabled.
__construct(int $a_copy_id=0)
Private Constructor (Singleton class)
initContainer(int $a_source_id, int $a_target_id)
appendMapping($a_source_id, $a_target_id)
Add mapping of source -> target.
isTreeCopyDisabled()
Check if tree copy is enabled.
static _isFinished(int $a_copy_id)
disableTreeCopy()
Disable copying of tree.
static _allocateCopyId()
Allocate a copy for further entries.
const COPY_WIZARD_LINK_TO_TARGET
addEntry(int $a_source_id, array $a_options)
Add new entry.
dropFirstDependenciesNode()
Drop first node (for cloneDependencies())
isRootNode(int $a_root)
Is root node public.
static _getInstance(int $a_copy_id)
dropFirstNode()
Drop first node (for cloneObject())