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('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();
 }
Пример #3
0
 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);
     }
 }