static function cloneProfile(Profile $prof) { $plugprof = new self(); if ($plugprof->getFromDB($prof->input['_old_id'])) { $input = ToolBox::addslashes_deep($plugprof->fields); $input['id'] = $prof->getID(); $plugprof->add($input); } }
/** * if profile cloned * * @param $prof Profile object **/ static function cloneProfile(Profile $prof) { global $DB; $plugprof = new self(); $crit = array('profiles_id' => $prof->input['_old_id']); foreach ($DB->request($plugprof->getTable(), $crit) as $data) { $input = ToolBox::addslashes_deep($data); unset($input['id']); $input['profiles_id'] = $prof->getID(); $plugprof->add($input); } }
static function cloneItem(array $param) { // Sanity check if (!isset($param['itemtype']) || !isset($param['id']) || !isset($param['name']) || !array_key_exists($param['itemtype'], self::$clone_types) || empty($param['name']) || !($item = getItemForItemtype($param['itemtype']))) { return false; } // Read original and prepare clone $item->check($param['id'], 'r'); $input = ToolBox::addslashes_deep($item->fields); $input['name'] = $param['name']; $input['_add'] = 1; $input['_old_id'] = $input['id']; unset($input['id']); if ($item->isEntityAssign()) { $input['entities_id'] = $_SESSION['glpiactive_entity']; } // Manage NULL fields in original foreach ($input as $k => $v) { if (is_null($input[$k])) { $input[$k] = "NULL"; } } // Specific to itemtype - before clone if (method_exists(self::$clone_types[$param['itemtype']], 'preClone')) { $input = call_user_func(array(self::$clone_types[$param['itemtype']], 'preClone'), $item, $input); } // Clone $clone = clone $item; $clone->check(-1, 'w', $input); $new = $clone->add($input); // Specific to itemtype - after clone if (method_exists(self::$clone_types[$param['itemtype']], 'postClone')) { call_user_func(array(self::$clone_types[$param['itemtype']], 'postClone'), $clone, $param['id']); } Plugin::doHook('item_clone', $clone); // History if ($clone->dohistory) { $changes[0] = '0'; $changes[1] = ''; $changes[2] = addslashes(sprintf(__('%1$s %2$s'), __('Clone of', 'behaviors'), $item->getNameID(0, true))); Log::history($clone->getID(), $clone->getType(), $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE); } }