public function jsonDuplicateAction() { if (!isset($this->_permissions['duplicate']) || !$this->_permissions['duplicate']) { throw new Kwf_Exception("Duplicate is not allowed."); } $ids = $this->getRequest()->getParam($this->_primaryKey); $ids = explode(';', $ids); $this->view->data = array('duplicatedIds' => array()); $parentTarget = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('componentId')); foreach ($ids as $id) { $sourceId = $this->_getParam('componentId') . '_' . $id; $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($sourceId); // Switch off observer due to performance - it's not necessary here Kwf_Events_ModelObserver::getInstance()->disable(); $newDetail = Kwf_Util_Component::duplicate($source, $parentTarget); Kwf_Util_Component::afterDuplicate($source, $newDetail); Kwf_Events_ModelObserver::getInstance()->enable(); $newDetailRow = $newDetail->row; $newDetailRow->create_date = date('Y-m-d H:i:s'); $newDetailRow->mails_per_minute = 'normal'; $newDetailRow->start_date = null; $newDetailRow->resume_date = null; $newDetailRow->last_sent_date = null; $newDetailRow->count_sent = null; $newDetailRow->status = null; $newDetailRow->save(); $mailRow = $newDetail->getChildComponent('_mail')->getComponent()->getRow(); $mailRow->subject = trlKwf('Copy of') . ' ' . $mailRow->subject; $mailRow->save(); } }
public function jsonPasteAction() { $session = new Kwf_Session_Namespace('PagesController:copy'); $id = $session->id; if (!$id || !Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true))) { throw new Kwf_Exception_Client(trlKwf('Clipboard is empty')); } $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true)); $target = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('id'), array('ignoreVisible' => true)); $user = Zend_Registry::get('userModel')->getAuthedUser(); $acl = Kwf_Registry::get('acl')->getComponentAcl(); if (!$acl->isAllowed($user, $source) || !$acl->isAllowed($user, $target)) { throw new Kwf_Exception_AccessDenied(); } $progressBar = new Zend_ProgressBar(new Kwf_Util_ProgressBar_Adapter_Cache($this->_getParam('progressNum')), 0, Kwf_Util_Component::getDuplicateProgressSteps($source)); Kwf_Util_MemoryLimit::set(256); Kwf_Events_ModelObserver::getInstance()->disable(); //This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear. $newPage = Kwf_Util_Component::duplicate($source, $target, $progressBar); Kwf_Util_Component::afterDuplicate($source, $newPage); Kwf_Events_ModelObserver::getInstance()->enable(); $progressBar->finish(); $s = new Kwf_Model_Select(); $s->whereEquals('parent_id', $newPage->row->parent_id); $s->order('pos', 'DESC'); $s->limit(1); $lastRow = $newPage->generator->getModel()->getRow($s); $row = $newPage->generator->getModel()->getRow($newPage->row->id); $row->pos = $lastRow ? $lastRow->pos + 1 : 1; $row->visible = false; $row->save(); }
public function testAction() { $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('source'), array('ignoreVisible' => true)); if (!$source) { throw new Kwf_Exception_Client("source not found"); } $parentTarget = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('target'), array('ignoreVisible' => true)); if (!$parentTarget) { throw new Kwf_Exception_Client("target not found"); } Kwf_Events_ModelObserver::getInstance()->disable(); //This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear. echo "counting pages..."; $steps = Kwf_Util_Component::getDuplicateProgressSteps($source); echo " " . $steps . "\n"; $ad = new Zend_ProgressBar_Adapter_Console(); $ad->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT, Zend_ProgressBar_Adapter_Console::ELEMENT_ETA)); $progressBar = new Zend_ProgressBar($ad, 0, $steps); $target = Kwf_Util_Component::duplicate($source, $parentTarget, $progressBar); Kwf_Util_Component::afterDuplicate($source, $target); $progressBar->finish(); exit; }
public function jsonPasteAction() { $session = new Kwf_Session_Namespace('Kwc_Paragraphs:copy'); $id = $session->id; if (!$id || !Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true))) { throw new Kwf_Exception_Client(trlKwf('Clipboard is empty')); } $target = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('componentId'), array('ignoreVisible' => true)); $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true)); $c = $target; while ($c->parent) { if ($c->dbId == $source->dbId) { throw new Kwf_Exception_Client(trlKwf("You can't paste a paragraph into itself.")); } if ($c->isPage) { break; } $c = $c->parent; } $sourceIsParagraphs = is_instance_of($source->componentClass, 'Kwc_Paragraphs_Component'); if ($source->isPage && $sourceIsParagraphs) { //a whole paragraphs component is in clipboard $sources = $source->getChildComponents(array('generator' => 'paragraphs', 'ignoreVisible' => true)); } else { if (!$source->isPage && !is_instance_of($source->parent->componentClass, 'Kwc_Paragraphs_Component')) { //a whole paragraphs component is in clipboard $sources = $source->getChildComponents(array('generator' => 'paragraphs', 'ignoreVisible' => true)); } else { //a single paragraph (paragraphs child) is in clipboard $sources = array($source); } } $classes = Kwc_Abstract::getChildComponentClasses($target->componentClass, 'paragraphs'); Kwf_Events_ModelObserver::getInstance()->disable(); //This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear. $progressBar = new Zend_ProgressBar(new Kwf_Util_ProgressBar_Adapter_Cache($this->_getParam('progressNum')), 0, Kwf_Util_Component::getDuplicateProgressSteps($source)); $newPos = $this->_getParam('pos'); $countDuplicated = 0; $errorMsg = false; foreach ($sources as $s) { $targetCls = false; if (isset($classes[$s->row->component])) { $targetCls = $classes[$s->row->component]; } $sourceCls = $s->componentClass; $sourceCls = strpos($sourceCls, '.') ? substr($sourceCls, 0, strpos($sourceCls, '.')) : $sourceCls; $targetCls = strpos($targetCls, '.') ? substr($targetCls, 0, strpos($targetCls, '.')) : $targetCls; if ($sourceCls != $targetCls) { if (Kwc_Abstract::hasSetting($s->componentClass, 'componentName')) { $name = Kwf_Trl::getInstance()->trlStaticExecute(Kwc_Abstract::getSetting($s->componentClass, 'componentName')); $errorMsg = trlKwf("Can't paste paragraph type '{0}', as it is not avaliable here.", $name); } else { $errorMsg = trlKwf('Source and target paragraphs are not compatible.'); } continue; //skip this one } $newParagraph = Kwf_Util_Component::duplicate($s, $target, $progressBar); $countDuplicated++; $row = $newParagraph->row; $row->pos = $newPos++; $row->visible = false; $row->save(); } Kwf_Util_Component::afterDuplicate($source, $target); $progressBar->finish(); Kwf_Events_ModelObserver::getInstance()->enable(); if (!$countDuplicated && $errorMsg) { //if at least one was duplicated show no error, else show one throw new Kwf_Exception_Client($errorMsg); } }
public function jsonPasteAction() { $this->_validateMaxEntries(); $session = new Kwf_Session_Namespace('Kwc_Abstract_List:copy'); $id = $session->id; if (!$id || !Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true))) { throw new Kwf_Exception_Client(trlKwf('Clipboard is empty')); } $target = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($this->_getParam('componentId'), array('ignoreVisible' => true)); $source = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, array('ignoreVisible' => true)); if ($source->parent->componentClass != $target->componentClass) { throw new Kwf_Exception_Client(trlKwf('Source and target paragraphs are not compatible.')); } Kwf_Events_ModelObserver::getInstance()->disable(); //This would be slow as hell. But luckily we can be sure that for the new (duplicated) components there will be no view cache to clear. $progressBar = null; $newItem = Kwf_Util_Component::duplicate($source, $target, $progressBar); $row = $newItem->row; $target->getChildComponents(array('ignoreVisible' => true)); $row->pos = null; //moves to end of list $row->visible = false; $row->save(); Kwf_Util_Component::afterDuplicate($source, $target); Kwf_Events_ModelObserver::getInstance()->enable(); }