Example #1
0
 public function testChangeParent()
 {
     $page = $this->_root->getComponentById(3);
     $model = $this->_root->getGenerator('page')->getModel();
     $m = Kwf_Component_Cache::getInstance()->getModel();
     // ist ein ParentContent-Komponente, zeigt 1-menu an
     $html = $page->render(true, true);
     $this->assertEquals(2, substr_count($html, '<li'));
     $this->assertEquals(2, substr_count($html, 'f1'));
     $this->assertEquals(2, substr_count($html, 'f4'));
     Kwf_Component_Data_Root::reset();
     // Um sicherzugehen, dass 1-menu nicht mehr existiert, 1 und 2 löschen
     $row = $model->getRow(3);
     $row->parent_id = 'root';
     $row->save();
     $row = $model->getRow(2);
     $row->delete();
     $row = $model->getRow(1);
     $row->delete();
     $this->_process();
     $html = $page->render(true, true);
     $this->assertEquals(2, substr_count($html, '<li'));
     $this->assertEquals(2, substr_count($html, 'f3'));
     $this->assertEquals(2, substr_count($html, 'f4'));
 }
Example #2
0
 public function testDirectory1()
 {
     $root = $this->_root;
     $dir = $root->getChildComponent('_dir');
     $list = $root->getChildComponent('_list');
     $dirModel = $dir->getComponent()->getChildModel();
     $cacheModel = Kwf_Component_Cache::getInstance()->getModel();
     $this->assertEquals('0 ', $dir->render());
     $this->assertEquals('0 ', $list->render());
     $row = $dirModel->createRow(array('id' => 1, 'component_id' => 'root_dir', 'content' => 'd1'));
     $row->save();
     $row = $dirModel->createRow(array('id' => 2, 'component_id' => 'root_dir', 'content' => 'd2'));
     $row->save();
     $this->_process();
     $this->assertEquals('2 d1d2', $dir->render());
     $this->assertEquals('2 d1d2', $list->render());
     // Bei Partial_Id darf im eigene Directory nur eine Row gelöscht werden
     $row = $dirModel->getRow(1);
     $row->content = 'foo';
     $row->save();
     $this->_process();
     $select = $cacheModel->select()->whereEquals('component_id', 'root_list-view')->whereEquals('type', 'partial');
     $rows = $cacheModel->getRows($select);
     $this->assertEquals(2, $rows->count());
     $this->assertEquals(1, $rows->current()->value);
     $this->assertEquals(true, $rows->current()->deleted);
     $rows->next();
     $this->assertEquals(2, $rows->current()->value);
     $this->assertEquals(false, $rows->current()->deleted);
     $this->assertEquals('2 food2', $dir->render());
     $this->assertEquals('2 food2', $list->render());
 }
Example #3
0
 public function testFeed()
 {
     Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF);
     $feed = Kwf_Component_Data_Root::getInstance()->getChildComponent('_feed');
     $xml = $feed->getComponent()->getXml();
     $rows = Kwf_Component_Cache::getInstance()->getModel()->getRows();
     $row = $rows->current();
     $feedRow = Kwf_Model_Abstract::getInstance('Kwc_Basic_Feed_Model')->getRows()->current();
     // XML prüfen
     $this->assertEquals('<?xml', substr($xml, 0, 5));
     $this->assertTrue(strpos($xml, '<rss') !== false);
     $this->assertTrue(strpos($xml, 'testtitle') !== false);
     $this->assertTrue(strpos($xml, 'testdescription') !== false);
     $this->assertTrue(strpos($xml, 'testlink') !== false);
     // Cache-Eintrag prüfen
     $this->assertEquals($xml, $feed->getComponent()->getXml());
     $this->assertEquals(1, count($rows));
     $this->assertEquals($xml, $row->content);
     // Cache-Eintrag ändern um festzustellen, ob eh Cache verwendet wird
     $feedRow->description = 'foo';
     $feedRow->save();
     $this->assertEquals($row->content, $feed->getComponent()->getXml());
     // Cache löschen
     $this->_process();
     $xml = $feed->getComponent()->getXml();
     $this->assertEquals('<?xml', substr($xml, 0, 5));
     $this->assertTrue(strpos($xml, '<rss') !== false);
 }
 protected function _clearCache($options)
 {
     if (!Kwf_Config::getValue('debug.componentCache.clearOnClearCache')) {
         $this->_output("skipped: (won't delete, use clear-view-cache to clear)\n");
         return;
     }
     Kwf_Component_Cache::getInstance()->deleteViewCache(new Kwf_Model_Select());
 }
Example #5
0
 public function testCacheClearing()
 {
     // check empty
     $cache = Kwf_Component_Cache::getInstance();
     $cacheModel = Kwf_Component_Cache::getInstance()->getModel();
     $this->assertNull($cache->load($this->_root));
     $this->_root->render(true);
     $this->assertNotNull($cache->load($this->_root));
 }
 public function indexAction()
 {
     Zend_Registry::set('db', false);
     Kwf_Test_SeparateDb::setDbFromCookie();
     // setzt es nur wenn es das cookie wirklich gibt
     //FnF models setzen damit tests nicht in echte tabellen schreiben
     Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF);
     Kwf_Component_Cache_Memory::setInstance(new Kwf_Component_Cache_MemoryBlackHole());
     /*
     if (class_exists('APCIterator')) {
         $prefix = Kwf_Cache::getUniquePrefix();
         apc_delete_file(new APCIterator('user', '#^'.$prefix.'#'));
     } else {
         apc_clear_cache('user');
     }
     */
     Kwf_Component_Data_Root::setComponentClass($this->_getParam('root'));
     Zend_Registry::set('testRootComponentClass', $this->_getParam('root'));
     $root = Kwf_Component_Data_Root::getInstance();
     $root->setFilename('kwf/kwctest/' . $this->_getParam('root'));
     $url = $this->_getParam('url');
     $urlParts = explode('/', $url);
     if (is_array($urlParts) && $urlParts[0] == 'media') {
         if (sizeof($urlParts) != 7) {
             throw new Kwf_Exception_NotFound();
         }
         $class = $urlParts[1];
         $id = $urlParts[2];
         $type = $urlParts[3];
         $checksum = $urlParts[4];
         // time() wäre der 5er, wird aber nur wegen browsercache benötigt
         $filename = $urlParts[6];
         if ($checksum != Kwf_Media::getChecksum($class, $id, $type, $filename)) {
             throw new Kwf_Exception_AccessDenied('Access to file not allowed.');
         }
         Kwf_Media_Output::output(Kwf_Media::getOutput($class, $id, $type));
     }
     if ($url == 'kwf/util/kwc/render') {
         if (isset($_REQUEST['url'])) {
             $_REQUEST['url'] = str_replace('/' . $root->filename, '', $_REQUEST['url']);
         }
         Kwf_Util_Component::dispatchRender();
     }
     $domain = 'http://' . Zend_Registry::get('config')->server->domain;
     $data = $root->getPageByUrl($domain . Kwf_Setup::getBaseUrl() . '/' . $url, null);
     if (!$data) {
         throw new Kwf_Exception_NotFound();
     }
     $root->setCurrentPage($data);
     $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender');
     $contentSender = new $contentSender($data);
     $contentSender->sendContent(true);
     Kwf_Benchmark::shutDown();
     Kwf_Benchmark::output();
     exit;
 }
 public function getXml()
 {
     $cache = Kwf_Component_Cache::getInstance();
     if (!($xml = $cache->load($this->getData()))) {
         $xml = $this->_getFeedXml();
         $cache->save($this->getData(), $xml);
         Kwf_Component_Cache::getInstance()->writeBuffer();
     }
     return $xml;
 }
 public function renderMaster($component)
 {
     static $benchmarkEnabled;
     if (!isset($benchmarkEnabled)) {
         $benchmarkEnabled = Kwf_Benchmark::isEnabled();
     }
     $content = false;
     if ($this->_enableCache) {
         $content = Kwf_Component_Cache::getInstance()->load($component->componentId, $this->_getRendererName(), 'fullPage');
         $this->_minLifetime = null;
     }
     Kwf_Benchmark::checkpoint('load fullPage cache');
     $statType = null;
     if (!$content) {
         if ($benchmarkEnabled) {
             $startTime = microtime(true);
         }
         if (!$this->_enableCache || ($content = Kwf_Component_Cache::getInstance()->load($component, $this->_getRendererName(), 'page')) === null) {
             $masterHelper = new Kwf_Component_View_Helper_Master();
             $masterHelper->setRenderer($this);
             $content = $masterHelper->master($component);
             if ($this->_enableCache) {
                 Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'page', '', '', null);
                 $statType = 'miss';
             } else {
                 $statType = 'noviewcache';
             }
         } else {
             $statType = 'hit';
         }
         if ($statType) {
             Kwf_Benchmark::count("rendered {$statType}", $component->componentId . ': page');
         }
         Kwf_Benchmark::countLog('render-' . $statType);
         if ($benchmarkEnabled) {
             Kwf_Benchmark::subCheckpoint($component->componentId . ' page', microtime(true) - $startTime);
         }
         Kwf_Benchmark::checkpoint('render page');
         $pass1Cacheable = true;
         $content = $this->_renderPass1($content, $pass1Cacheable);
         Kwf_Benchmark::checkpoint('render pass 1');
         if ($this->_enableCache && $pass1Cacheable) {
             Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'fullPage', '', '', $this->_minLifetime);
         }
         Kwf_Benchmark::count("rendered miss", $component->componentId . ': fullPage');
         Kwf_Benchmark::countLog('fullpage-miss');
     } else {
         Kwf_Benchmark::count("rendered hit", $component->componentId . ': fullPage');
         Kwf_Benchmark::countLog('fullpage-hit');
     }
     $content = $this->_renderPass2($content);
     Kwf_Benchmark::checkpoint('render pass 2');
     Kwf_Component_Cache::getInstance()->writeBuffer();
     return $content;
 }
 public function onRowUpdatesFinished(Kwf_Events_Event_Row_UpdatesFinished $event)
 {
     if ($this->_updates) {
         Kwf_Component_Cache::getInstance()->deleteViewCache($this->_updates);
         $this->_updates = array();
     }
     if ($this->_pageParentChanges) {
         Kwf_Component_Cache::getInstance()->handlePageParentChanges($this->_pageParentChanges);
         $this->_pageParentChanges = array();
     }
 }
 public function getXml()
 {
     $cache = Kwf_Component_Cache::getInstance();
     if (!($xml = $cache->load($this->getData()))) {
         $xml = $this->_getFeedXml();
         $directory = $this->getData()->parent->getComponent()->getItemDirectory();
         $cache->save($this->getData(), $xml, 'component', 'page', null, $directory->componentId, null);
         Kwf_Component_Cache::getInstance()->writeBuffer();
     }
     return $xml;
 }
 public function tearDown()
 {
     Kwf_Events_ModelObserver::getInstance()->setSkipFnF(true);
     Kwf_Component_Data_Root::reset();
     Kwf_Component_Cache::clearInstance();
     Kwf_Model_Abstract::clearInstances();
     Kwf_Events_Dispatcher::clearCache();
     Kwf_Events_Subscriber::clearInstances();
     Kwf_Component_PagesMetaModel::clearInstance();
     Kwf_Trl::getInstance()->unsetTrlElements();
 }
Example #12
0
 public function onRowInsert($row)
 {
     parent::onRowInsert($row);
     if ($row instanceof Kwc_Posts_Directory_Row) {
         $userDetails = Kwf_Component_Data_Root::getInstance()->getComponentsByClass('Kwc_User_Detail_Component', array('id' => '_' . $row->user_id));
         foreach ($userDetails as $detail) {
             p($detail->componentId);
             Kwf_Component_Cache::getInstance()->remove($detail->getRecursiveChildComponents(array('componentClass' => $this->_class)));
         }
     }
 }
 public function onRowUpdatesFinished(Kwf_Events_Event_Row_UpdatesFinished $event)
 {
     if (count($this->_orExpr->getExpressions())) {
         $select = new Kwf_Model_Select();
         $select->where($this->_orExpr);
         $rows = Kwf_Component_Cache::getInstance()->getModel('url')->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select);
         foreach ($rows as $row) {
             $cacheId = 'url-' . $row['url'];
             Kwf_Cache_Simple::delete($cacheId);
         }
     }
 }
 protected function _clearCache($options)
 {
     if (!Kwf_Config::getValue('debug.componentCache.clearOnClearCache')) {
         $this->_output("skipped: (won't delete, use clear-view-cache to clear)\n");
         return;
     }
     if (!Kwf_Setup::hasDb()) {
         $this->_output("skipped: (no db configured)\n");
         return;
     }
     Kwf_Component_Cache::getInstance()->deleteViewCache(array());
 }
 public function testC4()
 {
     $this->_setup('Kwf_Component_Output_C4_Component');
     $this->_root->render();
     $model = Kwf_Component_Cache::getInstance()->getModel('cache');
     $row = $model->getRows()->current();
     $content = $row->content;
     $this->_root->render();
     $this->assertEquals($content, $row->content);
     sleep(3);
     $this->_root->render();
     $this->assertNotEquals($content, $row->content);
 }
Example #16
0
 public function testMove()
 {
     $root = $this->_init('Kwf_Component_Cache_PageMove_Root_Component');
     $c2 = $root->getComponentById('2');
     $c2->render();
     $model = Kwf_Model_Abstract::getInstance('Kwf_Component_Cache_PageMove_Root_PagesModel');
     $row = $model->getRow(2);
     $row->parent_id = 3;
     $row->save();
     $this->_process();
     Kwf_Events_Dispatcher::fireEvent(new Kwf_Component_Event_Component_RecursiveContentChanged('Kwc_Basic_Empty_Component', Kwf_Component_Data_Root::getInstance()->getComponentById(3)));
     $this->_process();
     $this->assertNull(Kwf_Component_Cache::getInstance()->load('2'));
 }
Example #17
0
 public function testExceptionBeforeAfterFullPageDelete()
 {
     Kwf_Component_Cache::setInstance(new Kwf_Component_Cache_Mysql_Cache4());
     $row = Kwf_Model_Abstract::getInstance('Kwf_Component_Cache_Mysql_Root_Model')->getRow('root');
     $this->assertEquals('master foo', $this->_root->render(null, true));
     $row->value = 'bar';
     $row->save();
     try {
         $this->_process();
     } catch (Kwf_Exception $e) {
     }
     $this->assertEquals('master bar', $this->_root->render(null, true));
     $row->value = 'bar2';
     $row->save();
     $this->_process();
     $this->assertEquals('master bar2', $this->_root->render(null, true));
 }
Example #18
0
 public function testMove()
 {
     $root = $this->_root;
     $this->assertEquals(3, substr_count($root->render(), 'f1'));
     $this->assertEquals(2, substr_count($root->render(), 'f1/f2'));
     $this->assertEquals(1, substr_count($root->render(), 'f1/f2/f3'));
     $this->assertEquals(1, substr_count($root->render(), 'f4'));
     $cache = Kwf_Component_Cache::getInstance();
     $model = Kwf_Model_Abstract::getInstance('Kwf_Component_Cache_ComponentLink_Root_Model');
     $row = $model->getRow(2);
     $row->parent_id = 4;
     $row->save();
     $this->_process();
     $this->assertEquals(1, substr_count($root->render(), 'f1'));
     $this->assertEquals(2, substr_count($root->render(), 'f4/f2'));
     $this->assertEquals(1, substr_count($root->render(), 'f4/f2/f3'));
     $this->assertEquals(1, substr_count($root->render(), 'f3'));
 }
 public function getControllerClass(Zend_Controller_Request_Abstract $request)
 {
     $module = $request->getModuleName();
     if ($module == 'component' && $request->getControllerName() == 'component' || $module == 'component_test' && $request->getControllerName() == 'component_test') {
         if ($module == 'component_test') {
             //FnF models setzen damit tests nicht in echte tabellen schreiben
             Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF);
             Kwf_Test_SeparateDb::setDbFromCookie();
             // setzt es nur wenn es das cookie wirklich gibt
             if (!Kwf_Loader::isValidClass($request->getParam('root'))) {
                 throw new Kwf_Exception_NotFound("Invalid root component");
             }
             Kwf_Component_Data_Root::setComponentClass($request->getParam('root'));
             $root = Kwf_Component_Data_Root::getInstance();
             $root->setFilename('kwf/kwctest/' . $request->getParam('root'));
             Kwf_Registry::get('acl')->getComponentAcl()->allowComponent('guest', null);
             //hick hack, für Kwf_Component_Abstract_Admin::getControllerUrl
             Zend_Registry::set('testRootComponentClass', $request->getParam('root'));
         }
         $class = $request->getParam('class');
         $controller = $request->getParam('componentController');
         $controller .= 'Controller';
         if ($controller == 'IndexController') {
             $controller = 'Controller';
         }
         if (($pos = strpos($class, '!')) !== false) {
             $controller = substr($class, $pos + 1) . 'Controller';
             $class = substr($class, 0, $pos);
         }
         if (!in_array($class, Kwc_Abstract::getComponentClasses())) {
             //unknown component class
             return false;
         }
         $className = Kwc_Admin::getComponentClass($class, $controller);
         if (!$className) {
             return false;
         }
         class_exists($className);
         //trigger autoloader
     } else {
         $className = parent::getControllerClass($request);
     }
     return $className;
 }
 public function testC4()
 {
     $this->_setup('Kwf_Component_Output_C4_Component');
     $model = Kwf_Component_Cache::getInstance()->getModel('cache');
     $value = $this->_renderer->renderMaster($this->_root);
     $this->assertRegExp('#c4 #s', $value);
     //page, master, 1 component, 1 fullPage
     $this->assertEquals(4, $model->countRows());
     $s = new Kwf_Model_Select();
     $s->whereEquals('type', 'component');
     $row = $model->getRows($s)->current();
     $this->assertTrue($row->expire > time() + 1);
     $this->assertTrue($row->expire < time() + 5);
     $s = new Kwf_Model_Select();
     $s->whereEquals('type', 'fullPage');
     $row = $model->getRows($s)->current();
     $this->assertTrue($row->expire > time() + 1);
     $this->assertTrue($row->expire < time() + 5);
 }
 public function jsonClearViewCacheAction()
 {
     $select = new Kwf_Model_Select();
     if ($this->_getParam('dbId')) {
         $select->where(new Kwf_Model_Select_Expr_Like('db_id', $this->_getParam('dbId')));
     }
     if ($this->_getParam('id')) {
         $select->where(new Kwf_Model_Select_Expr_Like('component_id', $this->_getParam('id')));
     }
     if ($this->_getParam('expandedId')) {
         $select->where(new Kwf_Model_Select_Expr_Like('expanded_component_id', $this->_getParam('expandedId')));
     }
     if ($this->_getParam('class')) {
         $c = $this->_getParam('class');
         if (strpos($c, '%') === false) {
             $whereClass = array($c);
             foreach (Kwc_Abstract::getComponentClasses() as $cls) {
                 if (in_array($c, Kwc_Abstract::getSetting($cls, 'parentClasses'))) {
                     $whereClass[] = $cls;
                 }
             }
             $select->whereEquals('component_class', $whereClass);
         } else {
             $select->where(new Kwf_Model_Select_Expr_Like('component_class', $this->_getParam('class')));
         }
     }
     if ($this->_getParam('type')) {
         $select->where(new Kwf_Model_Select_Expr_Like('type', $this->_getParam('type')));
     }
     $select->whereEquals('deleted', false);
     $model = Kwf_Component_Cache::getInstance()->getModel();
     $this->view->entries = $model->countRows($select);
     if (!$this->view->entries) {
         throw new Kwf_Exception_Client("No active view cache entries found; nothing to do.");
     }
     if ($this->_getParam('force')) {
         Kwf_Component_Cache::getInstance()->deleteViewCache($select);
     }
 }
Example #22
0
 public function testWriteCache()
 {
     $p = $this->_root;
     $cache = Kwf_Component_Cache::getInstance();
     $cacheModel = $cache->getModel();
     $select = $cacheModel->select()->whereEquals('deleted', false);
     // Cache wird geschrieben
     $this->assertNull($cache->load($this->_root));
     $this->assertEquals(0, $cacheModel->getRows($select)->count());
     $p->render();
     $this->assertNotNull($cache->load($this->_root));
     $this->assertEquals(2, $cacheModel->getRows($select)->count());
     // Row, die nicht zum aktuellen Paragraphs gehört, speichern, Cache darf nicht gelöscht werden
     $p->getComponent()->getChildModel()->getRow(11)->save();
     $this->_process();
     $this->assertNotNull($cache->load($this->_root));
     $this->assertEquals(2, $cacheModel->getRows($select)->count());
     // Eigene Row speichern, Cache muss gelöscht werden
     $p->getComponent()->getChildModel()->getRow(2)->save();
     $this->_process();
     $this->assertNull($cache->load($this->_root));
     $this->assertEquals(1, $cacheModel->getRows($select)->count());
 }
 public function jsonClearViewCacheAction()
 {
     $update = array();
     if ($this->_getParam('dbId')) {
         $update['db_id'] = $this->_getParam('dbId');
     }
     if ($this->_getParam('id')) {
         $update['component_id'] = $this->_getParam('id');
     }
     if ($this->_getParam('expandedId')) {
         $update['expanded_component_id'] = $this->_getParam('expandedId');
     }
     if ($this->_getParam('class')) {
         $c = $this->_getParam('class');
         if (strpos($c, '%') === false) {
             $whereClass = array($c);
             foreach (Kwc_Abstract::getComponentClasses() as $cls) {
                 if (in_array($c, Kwc_Abstract::getSetting($cls, 'parentClasses'))) {
                     $whereClass[] = $cls;
                 }
             }
             $update['component_class'] = $whereClass;
         } else {
             $update['component_class'] = $this->_getParam('class');
         }
     }
     if ($this->_getParam('type')) {
         $update['type'] = $this->_getParam('type');
     }
     $this->view->entries = Kwf_Component_Cache::getInstance()->countViewCacheEntries(array($update));
     if (!$this->view->entries) {
         throw new Kwf_Exception_Client("No active view cache entries found; nothing to do.");
     }
     if ($this->_getParam('force')) {
         Kwf_Component_Cache::getInstance()->deleteViewCache(array($update));
     }
 }
Example #24
0
 public function getTemplateVars()
 {
     $ret = Kwc_Abstract::getTemplateVars();
     $this->_checkWasProcessed();
     $ret['isPosted'] = $this->_posted;
     $ret['showSuccess'] = false;
     $ret['errors'] = Kwf_Form::formatValidationErrors($this->getErrors());
     if ($this->isSaved()) {
         if (!$ret['errors'] && $this->getSuccessComponent()) {
             $ret['showSuccess'] = true;
         }
     }
     if ($ret['showSuccess']) {
         $ret['success'] = $this->getSuccessComponent();
     } else {
         foreach ($this->getData()->getChildComponents(array('generator' => 'child')) as $c) {
             if ($c->id != 'success') {
                 $ret[$c->id] = $c;
             }
         }
     }
     if (!$ret['showSuccess']) {
         $values = $this->getForm()->load(null, $this->_postData);
         $ret['form'] = $this->getForm()->getTemplateVars($values, '', $this->getData()->componentId . '_');
         $dec = $this->_getSetting('decorator');
         if ($dec && is_string($dec)) {
             $dec = new $dec();
             $ret['form'] = $dec->processItem($ret['form'], $this->getErrors());
         }
         $ret['formName'] = $this->getData()->componentId;
         $ret['buttonClass'] = $this->_getSetting('buttonClass');
         $ret['formId'] = $this->getForm()->getId();
         if ($ret['formId']) {
             $ret['formIdHash'] = Kwf_Util_Hash::hash($ret['formId']);
         }
         $page = $this->getData()->getPage();
         if (!$page) {
             throw new Kwf_Exception('Form must have an url so it must be on a page but is on "' . $this->getData()->componentId . '". (If component is a box it must not be unique)');
         }
         $cachedContent = Kwf_Component_Cache::getInstance()->load($page->componentId, 'componentLink');
         if ($cachedContent) {
             $targetPage = unserialize($cachedContent);
             $ret['action'] = $targetPage[0];
         } else {
             $ret['action'] = $this->getData()->url;
         }
         if (isset($_SERVER["QUERY_STRING"])) {
             $ret['action'] .= '?' . $_SERVER["QUERY_STRING"];
         }
         $ret['method'] = $this->_getSetting('method');
     }
     $ret['isUpload'] = false;
     foreach (new RecursiveIteratorIterator(new Kwf_Collection_Iterator_RecursiveFormFields($this->getForm()->fields)) as $f) {
         if ($f instanceof Kwf_Form_Field_File) {
             $ret['isUpload'] = true;
             break;
         }
     }
     $ret['message'] = null;
     $cacheId = 'kwcFormCu-' . get_class($this);
     $controllerUrl = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if (!$controllerUrl) {
         $controllerUrl = Kwc_Admin::getInstance(get_class($this))->getControllerUrl('FrontendForm');
         Kwf_Cache_SimpleStatic::add($cacheId, $controllerUrl);
     }
     $hideForValue = array();
     foreach ($this->_form->getHideForValue() as $v) {
         $hideForValue[] = array('field' => $v['field']->getFieldName(), 'value' => $v['value'], 'hide' => $v['hide']->getFieldName());
     }
     $baseParams = $this->_getBaseParams();
     $baseParams['componentId'] = $this->getData()->componentId;
     $fieldConfig = array();
     $iterator = new RecursiveIteratorIterator(new Kwf_Collection_Iterator_RecursiveFormFields($this->_form->fields), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $field) {
         if ($field->getFieldName()) {
             $fieldConfig[$field->getFieldName()] = (object) $field->getFrontendMetaData();
         }
     }
     $errorStyle = $this->_getSetting('errorStyle');
     if (!$errorStyle) {
         $errorStyle = Kwf_Config::getValue('kwc.form.errorStyle');
     }
     $ret['config'] = array('controllerUrl' => $controllerUrl, 'useAjaxRequest' => $this->_getSetting('useAjaxRequest'), 'hideFormOnSuccess' => $this->_getSetting('hideFormOnSuccess'), 'componentId' => $this->getData()->componentId, 'hideForValue' => $hideForValue, 'fieldConfig' => (object) $fieldConfig, 'errorStyle' => $errorStyle, 'baseParams' => $baseParams);
     $ret['uniquePrefix'] = Kwf_Config::getValue('application.uniquePrefix');
     if ($ret['uniquePrefix']) {
         $ret['uniquePrefix'] .= '-';
     }
     return $ret;
 }
 public function postDispatch()
 {
     Kwf_Events_ModelObserver::getInstance()->process();
     Kwf_Component_Cache::getInstance()->writeBuffer();
 }
 public function indexAction()
 {
     Kwf_Util_MemoryLimit::set(512);
     $select = new Kwf_Model_Select();
     if ($this->_getParam('all')) {
     }
     if ($this->_getParam('dbId')) {
         $select->where(new Kwf_Model_Select_Expr_Like('db_id', $this->_getParam('dbId')));
     }
     if ($this->_getParam('id')) {
         $select->where(new Kwf_Model_Select_Expr_Like('component_id', $this->_getParam('id')));
     }
     if ($this->_getParam('expandedId')) {
         $select->where(new Kwf_Model_Select_Expr_Like('expanded_component_id', $this->_getParam('expandedId')));
     }
     if ($this->_getParam('type')) {
         $select->where(new Kwf_Model_Select_Expr_Like('type', $this->_getParam('type')));
     }
     if ($this->_getParam('class')) {
         $c = $this->_getParam('class');
         if (strpos($c, '%') === false) {
             $whereClass = array($c);
             foreach (Kwc_Abstract::getComponentClasses() as $cls) {
                 if (in_array($c, Kwc_Abstract::getSetting($cls, 'parentClasses'))) {
                     $whereClass[] = $cls;
                 }
             }
             $select->whereEquals('component_class', $whereClass);
         } else {
             $select->where(new Kwf_Model_Select_Expr_Like('component_class', $this->_getParam('class')));
         }
     }
     if (!$this->_getParam('all') && !$this->_getParam('dbId') && !$this->_getParam('id') && !$this->_getParam('expandedId') && !$this->_getParam('type') && !$this->_getParam('class')) {
         throw new Kwf_Exception_Client("required parameter: --all, --id, --dbId, --expandedId, --type or --class");
     }
     $select->whereEquals('deleted', false);
     $model = Kwf_Component_Cache::getInstance()->getModel();
     $entries = $model->countRows($select);
     if (!$entries) {
         echo "No active view cache entries found; nothing to do.\n";
         exit;
     }
     if (!$this->_getParam('force')) {
         echo "Will delete {$entries} view cache entries. Continue? [Y/n]\n";
         $stdin = fopen('php://stdin', 'r');
         $input = trim(strtolower(fgets($stdin, 2)));
         fclose($stdin);
         if (!($input == '' || $input == 'j' || $input == 'y')) {
             exit(1);
         }
     }
     echo "Deleting view cache...\n";
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     Kwf_Component_Cache::getInstance()->deleteViewCache($select, $c);
     echo "done\n";
     if ($this->_getParam('clear')) {
         echo "Clearing table...";
         $model->deleteRows($select);
         echo "done\n";
     }
     exit;
 }
Example #27
0
 private function _getViewCacheCount()
 {
     $s = new Kwf_Model_Select();
     $s->whereEquals('deleted', false);
     return Kwf_Component_Cache::getInstance()->getModel()->countRows($s);
 }
Example #28
0
 private static function _deleteViewCache(Kwf_Model_Select $s)
 {
     $countDeleted = Kwf_Component_Cache::getInstance()->deleteViewCache($s);
     echo "deleted " . $countDeleted . " view cache entries\n";
 }
 public function jsonDataAction()
 {
     parent::jsonDataAction();
     Kwf_Component_Cache::getInstance()->writeBuffer();
 }
 public function onRowUpdatesFinished(Kwf_Events_Event_Row_UpdatesFinished $event)
 {
     if ($this->_updates) {
         $or = array();
         foreach ($this->_updates as $key => $values) {
             if ($key === 'component_id') {
                 $or[] = new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equal('component_id', array_unique($values)), new Kwf_Model_Select_Expr_Equal('type', 'component')));
             } else {
                 if ($key === 'master-component_id') {
                     $or[] = new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equal('component_id', array_unique($values)), new Kwf_Model_Select_Expr_Equal('type', 'master')));
                 } else {
                     $and = array();
                     foreach ($values as $k => $v) {
                         if (substr($v, -1) == '%') {
                             $v = substr($v, 0, -1);
                             $and[] = new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equal($k, $v), new Kwf_Model_Select_Expr_Like($k, $v . '-%'), new Kwf_Model_Select_Expr_Like($k, $v . '_%')));
                         } else {
                             if (strpos($v, '%') !== false) {
                                 $and[] = new Kwf_Model_Select_Expr_Like($k, $v);
                             } else {
                                 $and[] = new Kwf_Model_Select_Expr_Equal($k, $v);
                             }
                         }
                     }
                     $or[] = new Kwf_Model_Select_Expr_And($and);
                 }
             }
         }
         $select = new Kwf_Model_Select();
         $select->where($or[0]);
         unset($or[0]);
         foreach ($or as $i) {
             $s = new Kwf_Model_Select();
             $s->where($i);
             $select->union($s);
         }
         Kwf_Component_Cache::getInstance()->deleteViewCache($select);
         $this->_updates = array();
     }
     foreach ($this->_pageParentChanges as $changes) {
         $oldParentId = $changes['oldParentId'];
         $newParentId = $changes['newParentId'];
         $componentId = $changes['componentId'];
         $length = strlen($oldParentId);
         $like = $oldParentId . '_' . $componentId;
         $model = Kwf_Component_Cache::getInstance()->getModel();
         while ($model instanceof Kwf_Model_Proxy) {
             $model = $model->getProxyModel();
         }
         if ($model instanceof Kwf_Model_Db) {
             $db = Kwf_Registry::get('db');
             $newParentId = $db->quote($newParentId);
             $where[] = 'expanded_component_id = ' . $db->quote($like);
             $where[] = 'expanded_component_id LIKE ' . str_replace('_', '\\_', $db->quote($like . '-%'));
             $where[] = 'expanded_component_id LIKE ' . str_replace('_', '\\_', $db->quote($like . '_%'));
             $sql = "UPDATE cache_component\n                    SET expanded_component_id=CONCAT(\n                        {$newParentId}, SUBSTRING(expanded_component_id, {$length})\n                    )\n                    WHERE " . implode(' OR ', $where);
             $model->executeSql($sql);
             $this->_log("expanded_component_id={$like}%->{$newParentId}");
         } else {
             $model = Kwf_Component_Cache::getInstance()->getModel();
             $select = $model->select()->where(new Kwf_Model_Select_Expr_Like('expanded_component_id', $like . '%'));
             foreach ($model->getRows($select) as $row) {
                 $oldExpandedId = $row->expanded_component_id;
                 $newExpandedId = $newParentId . substr($oldExpandedId, $length);
                 $row->expanded_component_id = $newExpandedId;
                 $row->save();
                 $this->_log("expanded_component_id={$oldExpandedId}->{$newExpandedId}");
             }
         }
     }
     $this->_pageParentChanges = array();
 }