Example #1
0
 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();
     Kwc_FulltextSearch_MetaModel::clearInstance();
     Kwf_Trl::getInstance()->unsetTrlElements();
 }
Example #2
0
 public function onComponentRecursiveAddedOrRemoved(Kwf_Component_Event_Component_RecursiveAbstract $ev)
 {
     $m = Kwc_FulltextSearch_MetaModel::getInstance();
     if ($page = $ev->component->getPage()) {
         $row = $m->getRow($page->componentId);
         if (!$row) {
             $row = $m->createRow();
             $row->page_id = $page->componentId;
         }
         $row->changed_date = date('Y-m-d H:i:s');
         $row->changed_recursive = true;
         $row->save();
     }
 }
Example #3
0
 protected function _init($componentClass)
 {
     Kwf_Component_Data_Root::setComponentClass($componentClass);
     Zend_Session::$_unitTestEnabled = true;
     $this->_root = Kwf_Component_Data_Root::getInstance();
     $this->_root->setFilename('kwf/kwctest/' . $componentClass);
     if (function_exists('apc_clear_cache')) {
         apc_clear_cache('user');
     }
     Kwf_Component_Cache_Memory::getInstance()->_clean();
     Kwf_Cache_Simple::resetZendCache();
     Kwc_FulltextSearch_MetaModel::setInstance(new Kwf_Model_FnF(array('primaryKey' => 'page_id')));
     Kwf_Assets_Package_Default::clearInstances();
     Kwf_Component_LogDuplicateModel::setInstance(new Kwf_Model_FnF(array()));
     Kwf_Media_MemoryCache::getInstance()->clean();
     return $this->_root;
 }
Example #4
0
 public function testChangePageType2()
 {
     $r = Kwf_Model_Abstract::getInstance('Kwf_Component_Fulltext_BasicHtml_PagesModel')->getRow('2');
     $r->component = 'empty';
     $r->save();
     $this->_process();
     $row = Kwc_FulltextSearch_MetaModel::getInstance()->getRow(array('equals' => array('page_id' => '2')));
     $this->assertNotNull($row);
     $age = time() - strtotime($row->changed_date);
     $this->assertTrue($age >= 0 && $age < 5);
     $this->assertTrue($row->changed_recursive);
 }
Example #5
0
 public static function setInstance($instance)
 {
     self::$_instance = $instance;
 }
 public function checkContentsSubrootAction()
 {
     Kwf_Util_MemoryLimit::set(256);
     $subroot = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('subroot'));
     if (!$subroot) {
         $subroot = Kwf_Component_Data_Root::getInstance();
     }
     $documents = Kwf_Util_Fulltext_Backend_Abstract::getInstance()->getAllDocuments($subroot);
     if ($this->_getParam('debug')) {
         echo "count: " . count($documents) . "\n";
     }
     $i = 0;
     $stats = array('indexedPages' => 0, 'diffPages' => 0);
     foreach ($documents as $componentId => $doc) {
         if ($this->_getParam('debug')) {
             echo "checking: {$i}: {$componentId}\n";
         }
         $page = Kwf_Component_Data_Root::getInstance()->getComponentById($componentId);
         if (!$page) {
             continue;
         }
         if (Kwc_Abstract::getFlag($page->componentClass, 'skipFulltext')) {
             $page = null;
         }
         if (!$page) {
             continue;
         }
         //should not happen
         if (Kwc_Abstract::getFlag($page->componentClass, 'skipFulltextRecursive')) {
             $page = null;
         }
         if (!$page) {
             continue;
         }
         //should not happen
         $newDoc = Kwf_Util_Fulltext_Backend_Abstract::getInstance()->getFulltextContentForPage($page);
         if (!$newDoc) {
             //this can happen (if there is no content)
             Kwf_Util_Fulltext_Backend_Abstract::getInstance()->deleteDocument($subroot, $componentId);
             $row = Kwc_FulltextSearch_MetaModel::getInstance()->getRow($componentId);
             if ($row) {
                 $row->delete();
             }
             continue;
         }
         if (trim($newDoc['content']) != trim($doc['content'])) {
             $stats['diffPages']++;
             if (Kwf_Util_Fulltext_Backend_Abstract::getInstance()->indexPage($page)) {
                 $stats['indexedPages']++;
             }
             if (!$this->_getParam('silent')) {
                 echo "DIFF: {$componentId}\n";
             }
         }
         unset($page);
         if ($i++ % 10) {
             Kwf_Component_Data_Root::getInstance()->freeMemory();
         }
         //if ($this->_getParam('debug')) echo "memory_usage ".(memory_get_usage()/(1024*1024))."MB\n";
     }
     if (!$this->_getParam('silent')) {
         echo "pages with diff: {$stats['diffPages']}\n";
         echo "indexed pages: {$stats['indexedPages']}\n";
     }
     exit;
 }
Example #7
0
 protected function _afterIndex(Kwf_Component_Data $page)
 {
     $m = Kwc_FulltextSearch_MetaModel::getInstance();
     $row = $m->getRow($page->componentId);
     if (!$row) {
         $row = $m->createRow();
         $row->page_id = $page->componentId;
     }
     $row->indexed_date = date('Y-m-d H:i:s');
     $row->save();
 }