function testDuplicate() { $GLOBALS['strCopyOf'] = 'Copy of '; // create test channel $doChannel = OA_Dal::factoryDO('channel'); $doChannel->acls_updated = '2007-04-03 19:29:54'; $channelId = DataGenerator::generateOne($doChannel, true); // create test acls $doAcls = OA_Dal::factoryDO('acls_channel'); $doAcls->channelid = $channelId; $doAcls->type = 'Client:Ip'; $doAcls->comparison = '=='; $doAcls->data = '127.0.0.1'; $doAcls->executionorder = 1; $doAcls->insert(); $doAcls = OA_Dal::factoryDO('acls_channel'); $doAcls->channelid = $channelId; $doAcls->type = 'Client:Domain'; $doAcls->comparison = '=='; $doAcls->data = 'example.com'; $doAcls->executionorder = 2; $doAcls->insert(); // duplicate $newChannelId = OA_Dal::staticDuplicate('channel', $channelId); // retrieve original and duplicate channel $doChannel = OA_Dal::staticGetDO('channel', $channelId); $doNewChannel = OA_Dal::staticGetDO('channel', $newChannelId); // assert they are not equal including primary keys - name column should not match $this->assertNotEqualDataObjects($this->stripKeys($doChannel), $this->stripKeys($doNewChannel)); // assert they are equal excluding primary keys $doChannel->name = $doNewChannel->name = null; $this->assertEqualDataObjects($this->stripKeys($doChannel), $this->stripKeys($doNewChannel)); // retrieve acls for original and duplicate channel $doAcls = OA_Dal::factoryDO('acls_channel'); $doAcls->channelid = $channelId; $doAcls->orderBy('executionorder'); if ($doAcls->find()) { while ($doAcls->fetch()) { $aAcls[] = clone $doAcls; } } $doNewAcls = OA_Dal::factoryDO('acls_channel'); $doNewAcls->channelid = $newChannelId; $doNewAcls->orderBy('executionorder'); if ($doNewAcls->find()) { while ($doNewAcls->fetch()) { $aNewAcls[] = clone $doNewAcls; } } // iterate through acls ensuring they were properly copied if ($this->assertEqual(count($aAcls), count($aNewAcls))) { for ($x = 0; $x < count($aAcls); $x++) { $this->assertNotEqual($aAcls[$x]->channelid, $aNewAcls[$x]->channelid); $this->assertEqualDataObjects($this->stripKeys($aAcls[$x]), $this->stripKeys($aNewAcls[$x])); } } }
function duplicate($channelId) { // Populate $this with channel data $this->get($channelId); // Prepare a new name for the channel $this->name = $GLOBALS['strCopyOf'] . ' ' . $this->name; // Duplicate channel $this->channelid = null; $newChannelId = $this->insert(); // Duplicate channel's acls $result = OA_Dal::staticDuplicate('acls_channel', $channelId, $newChannelId); return $newChannelId; }
OA_Permission::enforceAccessToObject('channel', $channelid); $affiliateid = (int) $affiliateid; $channelid = (int) $channelid; if (empty($returnurl)) { $returnurl = 'channel-edit.php'; } // Security check if (isset($channelid) && $channelid != '') { if (isset($duplicate) && $duplicate == 'true') { //get channel old channel name $doChannel = OA_Dal::factoryDO('channel'); if ($doChannel->get($channelid)) { $oldName = $doChannel->name; } // Duplicate the channel $newChannelId = OA_Dal::staticDuplicate('channel', $channelid); //get new name $doChannel = OA_Dal::factoryDO('channel'); if ($doChannel->get($newChannelId)) { $newName = $doChannel->name; } // Queue confirmation message $translation = new OX_Translation(); $oldChannelParams = !$affiliateid ? "channelid={$channelid}" : "affiliateid={$affiliateid}&channelid={$channelid}"; $newChannelParams = !$affiliateid ? "?channelid={$newChannelId}" : "?affiliateid={$affiliateid}&channelid={$newChannelId}"; $translated_message = $translation->translate($GLOBALS['strChannelHasBeenDuplicated'], array(MAX::constructURL(MAX_URL_ADMIN, "channel-edit.php?" . $oldChannelParams), htmlspecialchars($oldName), MAX::constructURL(MAX_URL_ADMIN, "channel-edit.php?" . $newChannelParams), htmlspecialchars($newName))); OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0); Header("Location: " . $returnurl . $newChannelParams); exit; } }