public function afterDuplicate($rootSource, $rootTarget) { parent::afterDuplicate($rootSource, $rootTarget); foreach ($this->_duplicated as $d) { //modify duplicated links so they point to duplicated page //only IF link points to page below $rootSource $source = Kwf_Component_Data_Root::getInstance()->getComponentById($d['source'], array('ignoreVisible' => true)); $sourceLinkedData = $source->getLinkedData(); if (!$sourceLinkedData) { continue; } $linkTargetIsBelowRootSource = false; $data = $sourceLinkedData; do { if ($data->componentId == $rootSource->componentId) { $linkTargetIsBelowRootSource = true; break; } } while ($data = $data->parent); unset($data); if ($linkTargetIsBelowRootSource) { $target = Kwf_Component_Data_Root::getInstance()->getComponentById($d['target'], array('ignoreVisible' => true)); $targetRow = $target->getComponent()->getRow(); $this->_modifyOwnRowAfterDuplicate($targetRow, $sourceLinkedData); $targetRow->save(); } } $this->_duplicated = array(); }
public function afterDuplicate($rootSource, $rootTarget) { parent::afterDuplicate($rootSource, $rootTarget); $prefix = $this->_prefix; $column = "{$prefix}_id"; foreach ($this->_duplicated as $d) { //modify duplicated links so they point to duplicated page //only IF link points to page below $rootSource $source = Kwf_Component_Data_Root::getInstance()->getComponentById($d['source'], array('ignoreVisible' => true)); $sourceRow = $source->getComponent()->getRow(); $linkTargetIsBelowRootSource = false; foreach (Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($prefix . '_' . $sourceRow->{$column}, array('ignoreVisible' => true)) as $sourceLinkTarget) { do { if ($sourceLinkTarget->componentId == $rootSource->componentId) { $linkTargetIsBelowRootSource = true; break; } } while ($sourceLinkTarget = $sourceLinkTarget->parent); } if ($linkTargetIsBelowRootSource) { //get duplicated link target id from duplicate log $sql = "SELECT target_component_id FROM kwc_log_duplicate WHERE source_component_id = ? ORDER BY id DESC LIMIT 1"; $q = Kwf_Registry::get('db')->query($sql, $prefix . '_' . $sourceRow->{$column}); $q = $q->fetchAll(); if (!$q) { continue; } $linkTargetId = $q[0]['target_component_id']; $target = Kwf_Component_Data_Root::getInstance()->getComponentById($d['target'], array('ignoreVisible' => true)); $targetRow = $target->getComponent()->getRow(); if (substr($linkTargetId, 0, 5) != $prefix . '_') { throw new Kwf_Exception('invalid target_component_id'); } $targetRow->{$column} = substr($linkTargetId, 5); $targetRow->save(); } } $this->_duplicated = array(); }
public function componentToString($data) { $ret = parent::componentToString($data); $punycode = new Kwf_Util_Punycode(); return $punycode->decode($ret); }