示例#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'));
 }
示例#2
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);
 }
示例#3
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());
 }
 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());
 }
示例#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 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;
 }
示例#10
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)));
         }
     }
 }
示例#11
0
 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);
 }
示例#14
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'));
 }
示例#15
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'));
 }
示例#16
0
 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);
     }
 }
示例#18
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));
     }
 }
示例#20
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 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;
 }
示例#22
0
 public function renderComponent($component, &$hasDynamicParts = false)
 {
     static $benchmarkEnabled;
     if (!isset($benchmarkEnabled)) {
         $benchmarkEnabled = Kwf_Benchmark::isEnabled();
     }
     $content = false;
     if ($this->_enableCache && $component->isPage) {
         //use fullPage cache only for pages
         $content = Kwf_Component_Cache::getInstance()->load($component->componentId, $this->_getRendererName(), 'fullPage');
         $this->_minLifetime = null;
     }
     Kwf_Benchmark::checkpoint('load fullPage cache');
     $statType = null;
     if (!$content) {
         $helper = new Kwf_Component_View_Helper_Component();
         $helper->setRenderer($this);
         $content = $helper->component($component);
         $pass1Cacheable = true;
         $content = $this->_renderPass1($content, $pass1Cacheable);
         Kwf_Benchmark::checkpoint('render pass 1');
         if (strpos($content, '<kwc2 ') === false) {
             //if there are no components that need second render cycle start HtmlParser now
             //and cache result in fullPage cache
             if ($this->_renderFormat == self::RENDER_HTML && $this->_htmlStyles) {
                 $p = new Kwc_Mail_HtmlParser($this->_htmlStyles);
                 $content = $p->parse($content);
                 Kwf_Benchmark::checkpoint('html parser (in fullPage)');
             }
         }
         if ($this->_enableCache && $pass1Cacheable && $component->isPage) {
             Kwf_Component_Cache::getInstance()->save($component, $content, $this->_getRendererName(), 'fullPage', '', '', $this->_minLifetime);
         }
     }
     $hasPass2Placeholders = strpos($content, '<kwc2 ') !== false;
     $content = $this->_renderPass2($content);
     Kwf_Benchmark::checkpoint('render pass 2');
     //if there where components that needed second render cycle the HtmlParser wasn't started yet
     //do that now (should be avoided as it's slow)
     if ((!$component->isPage || $hasPass2Placeholders) && $this->_renderFormat == self::RENDER_HTML && $this->_htmlStyles) {
         $p = new Kwc_Mail_HtmlParser($this->_htmlStyles);
         $content = $p->parse($content);
         Kwf_Benchmark::checkpoint('html parser');
     }
     Kwf_Component_Cache::getInstance()->writeBuffer();
     return $content;
 }
 public function postDispatch()
 {
     Kwf_Events_ModelObserver::getInstance()->process();
     Kwf_Component_Cache::getInstance()->writeBuffer();
 }
示例#24
0
 private static function _deleteViewCache(Kwf_Model_Select $s)
 {
     $countDeleted = Kwf_Component_Cache::getInstance()->deleteViewCache($s);
     echo "deleted " . $countDeleted . " view cache entries\n";
 }
示例#25
0
 private function _getViewCacheCount()
 {
     $s = new Kwf_Model_Select();
     $s->whereEquals('deleted', false);
     return Kwf_Component_Cache::getInstance()->getModel()->countRows($s);
 }
示例#26
0
 private function _cacheSave($componentId, $type, $value, $content)
 {
     $m = Kwf_Component_Cache::getInstance()->getModel('includes');
     $s = $m->select()->whereEquals('component_id', $componentId)->whereEquals('type', $type);
     $existingTargetIds = array();
     foreach ($m->export(Kwf_Model_Abstract::FORMAT_ARRAY, $s, array('columns' => array('target_id'))) as $i) {
         $existingTargetIds[] = $i['target_id'];
     }
     $newTargetIds = array();
     if ($this->_includedComponents) {
         $data = array();
         foreach ($this->_includedComponents as $includedComponentId) {
             $cmp = Kwf_Component_Data_Root::getInstance()->getComponentById($componentId, array('ignoreVisible' => true));
             $targetCmp = Kwf_Component_Data_Root::getInstance()->getComponentById($includedComponentId, array('ignoreVisible' => true));
             if ($cmp->getPage() !== $targetCmp->getPage()) {
                 if (!in_array($includedComponentId, $existingTargetIds)) {
                     $c = array('target_id' => $includedComponentId, 'type' => $type, 'component_id' => $componentId);
                     $data[] = $c;
                 }
                 $newTargetIds[] = $includedComponentId;
             }
         }
         $m->import(Kwf_Model_Abstract::FORMAT_ARRAY, $data);
     }
     $this->_includedComponents = array();
     $diffTargetIds = array_diff($existingTargetIds, $newTargetIds);
     if ($diffTargetIds) {
         //delete not anymore included
         $m = Kwf_Component_Cache::getInstance()->getModel('includes');
         $s = $m->select()->whereEquals('component_id', $componentId)->whereEquals('type', $type)->whereEquals('target_id', $diffTargetIds);
         $m->deleteRows($s);
     }
     //save rendered contents into view cache
     $cacheContent = $content;
     $component = Kwf_Component_Data_Root::getInstance()->getComponentById($componentId, array('ignoreVisible' => true));
     if (!$component) {
         throw new Kwf_Exception("Can't find component '{$componentId}' for rendering");
     }
     $settings = $this->_getHelper($type)->getViewCacheSettings($componentId);
     if (!$settings['enabled']) {
         //something is very wrong
         throw new Kwf_Exception('$isCacheable should be false if the view cache is disabled for this helper');
         $cacheContent = Kwf_Component_Cache::NO_CACHE;
     }
     // Content-Cache
     Kwf_Component_Cache::getInstance()->save($component, $cacheContent, $this->_getRendererName(), $type, $value, isset($settings['cacheTag']) ? $settings['cacheTag'] : '', isset($settings['lifetime']) ? $settings['lifetime'] : null);
     if ($settings['lifetime']) {
         if (is_null($this->_minLifetime)) {
             $this->_minLifetime = $settings['lifetime'];
         } else {
             $this->_minLifetime = min($this->_minLifetime, $settings['lifetime']);
         }
     }
 }
示例#27
0
 private function _fetchIncludesTree($componentIds, &$checkedIds = array())
 {
     $ret = array();
     $ids = array();
     foreach ($componentIds as $componentId) {
         $i = (string) $componentId;
         if (!isset($checkedIds[$i])) {
             $checkedIds[$i] = true;
             $ids[] = $i;
         }
         while (strrpos($i, '-') && strrpos($i, '-') > strrpos($i, '_')) {
             $i = substr($i, 0, strrpos($i, '-'));
             if (!isset($checkedIds[$i])) {
                 $checkedIds[$i] = true;
                 $ids[] = $i;
             }
         }
         $ret[$i] = true;
     }
     if (!$ids) {
         return $ret;
     }
     $s = new Kwf_Model_Select();
     $s->whereEquals('target_id', $ids);
     $imports = Kwf_Component_Cache::getInstance()->getModel('includes')->export(Kwf_Model_Abstract::FORMAT_ARRAY, $s, array('columns' => array('component_id')));
     $childIds = array();
     foreach ($imports as $row) {
         $childIds[] = $row['component_id'];
     }
     $childIds = array_unique($childIds);
     foreach ($this->_fetchIncludesTree($childIds, $checkedIds) as $i => $nop) {
         if (!isset($ret[$i])) {
             $ret[$i] = true;
         }
     }
     return $ret;
 }
 public function jsonDataAction()
 {
     parent::jsonDataAction();
     Kwf_Component_Cache::getInstance()->writeBuffer();
 }
示例#29
0
 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();
 }
示例#30
0
 public function handlePageParentChanges(array $pageParentChanges)
 {
     foreach ($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}");
             }
         }
     }
 }