public function onComponentRecursiveRemoved(Kwf_Component_Event_Component_RecursiveAbstract $ev)
 {
     $m = Kwf_Component_PagesMetaModel::getInstance();
     if ($page = $ev->component->getPage()) {
         $row = $m->getRow($page->componentId);
         if ($row) {
             $row->deleteRecursive();
         }
     }
 }
 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();
 }
 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();
     Kwf_Component_PagesMetaModel::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();
     Kwf_Events_Subscriber::clearInstances();
     return $this->_root;
 }
 protected function _afterIndex(Kwf_Component_Data $page)
 {
     $m = Kwf_Component_PagesMetaModel::getInstance();
     $row = $m->getRow($page->componentId);
     if (!$row) {
         $row = $m->createRow();
     }
     $row->updateFromPage($page);
     $row->fulltext_indexed_date = date('Y-m-d H:i:s');
     $row->save();
 }
 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();
     }
     $i = 0;
     $stats = array('indexedPages' => 0, 'diffPages' => 0);
     $pagesMetaModel = Kwf_Component_PagesMetaModel::getInstance();
     $select = new Kwf_Model_Select();
     $select->whereEquals('deleted', false);
     $select->whereEquals('fulltext_skip', false);
     $select->whereEquals('subroot_component_id', $subroot->componentId);
     $it = new Kwf_Model_Iterator_Packages(new Kwf_Model_Iterator_Rows($pagesMetaModel, $select));
     if ($this->_getParam('debug')) {
         $it = new Kwf_Iterator_ConsoleProgressBar($it);
     }
     foreach ($it as $row) {
         $componentId = $row->page_id;
         $page = Kwf_Component_Data_Root::getInstance()->getComponentById($componentId);
         if (!$this->_getParam('skip-diff')) {
             $docContent = Kwf_Util_Fulltext_Backend_Abstract::getInstance()->getDocumentContent($page);
         } else {
             $docContent = '';
         }
         $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 = $pagesMetaModel->getRow($componentId);
             if ($row) {
                 $row->delete();
             }
             continue;
         }
         if (trim($newDoc['content']) != trim($docContent)) {
             $stats['diffPages']++;
             if (Kwf_Util_Fulltext_Backend_Abstract::getInstance()->indexPage($page)) {
                 $stats['indexedPages']++;
             }
             if (!$this->_getParam('silent') && !$this->_getParam('skip-diff')) {
                 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('debug')) {
         if (!$this->_getParam('skip-diff')) {
             echo "pages with diff: {$stats['diffPages']}\n";
         }
         echo "indexed pages: {$stats['indexedPages']}\n";
     }
     exit;
 }
 private function _processRecursive(Kwf_Component_Data $page)
 {
     if (memory_get_usage() > 128 * 1024 * 1024) {
         if ($this->_getParam('debug')) {
             echo "Collect garbage...\n";
         }
         Kwf_Component_Data_Root::getInstance()->freeMemory();
     }
     if ($this->_getParam('debug')) {
         echo "processing changed_recursive {$page->componentId}\n";
     }
     $childPages = $page->getChildPseudoPages(array('pageGenerator' => false), array('pseudoPage' => false, 'unique' => false));
     $ret = array();
     foreach ($childPages as $p) {
         $m = Kwf_Component_PagesMetaModel::getInstance();
         $r = $m->getRow($p->componentId);
         if (!$r) {
             $r = $m->createRow();
         }
         $r->updateFromPage($p);
         $r->changed_date = date('Y-m-d H:i:s');
         $r->save();
         $this->_processRecursive($p);
     }
 }
Example #8
0
 public function testChangePageType2()
 {
     $r = Kwf_Model_Abstract::getInstance('Kwf_Component_Fulltext_BasicHtml_PagesModel')->getRow('2');
     $r->component = 'empty';
     $r->save();
     $this->_process();
     $row = Kwf_Component_PagesMetaModel::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);
 }