Esempio n. 1
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();
     }
 }
 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;
 }
Esempio n. 3
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);
 }
Esempio n. 4
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();
 }