/** * Registers the object in search engine. * * @note Transaction unsafe. If you call several transaction unsafe methods you must enclose * the calls within a db transaction; thus within db->begin and db->commit. * * @param int $objectID Id of the object. */ public static function registerSearchObject($objectID) { $objectID = (int) $objectID; eZDebug::createAccumulatorGroup('search_total', 'Search Total'); $ini = eZINI::instance('site.ini'); $insertPendingAction = false; $object = null; switch ($ini->variable('SearchSettings', 'DelayedIndexing')) { case 'enabled': $insertPendingAction = true; break; case 'classbased': $classList = $ini->variable('SearchSettings', 'DelayedIndexingClassList'); $object = eZContentObject::fetch($objectID); if (is_array($classList) && in_array($object->attribute('class_identifier'), $classList)) { $insertPendingAction = true; } } if ($insertPendingAction) { eZDB::instance()->query("INSERT INTO ezpending_actions( action, param ) VALUES ( 'index_object', '{$objectID}' )"); return; } if ($object === null) { $object = eZContentObject::fetch($objectID); } // Register the object in the search engine. $needCommit = eZSearch::needCommit(); if (eZSearch::needRemoveWithUpdate()) { eZDebug::accumulatorStart('remove_object', 'search_total', 'remove object'); eZSearch::removeObject($object, $needCommit); eZDebug::accumulatorStop('remove_object'); } eZDebug::accumulatorStart('add_object', 'search_total', 'add object'); if (!eZSearch::addObject($object, $needCommit)) { eZDebug::writeError("Failed adding object ID {$object->attribute('id')} in the search engine", __METHOD__); } eZDebug::accumulatorStop('add_object'); }
$newValue = normalizeValue($newValue, $currentValue, $attribute); if ($newValue != $currentValue) { if ($createNewVersion) { $params = array('attributes' => array($attributeIdentifier => $newValue)); $result = eZContentFunctions::updateAndPublishObject($object, $params); if (!$result) { $data['status'] = 'error'; $data['message'] = "Error creating new object version"; $data['header'] = "HTTP/1.1 400 Bad Request"; } else { $data['status'] = 'success'; } } else { $attribute->fromString($newValue); $attribute->store(); eZSearch::addObject($object); eZContentCacheManager::clearObjectViewCacheIfNeeded($object->attribute('id')); $data['status'] = 'success'; } } } else { $data['status'] = 'error'; $data['message'] = "Attribute not found"; $data['header'] = "HTTP/1.1 404 Not Found"; } } else { $data['status'] = 'error'; $data['message'] = "Attribute not found"; $data['header'] = "HTTP/1.1 404 Not Found"; } } else {
function removeNodeFromTree($moveToTrash = true) { $nodeID = $this->attribute('node_id'); $object = $this->object(); $assignedNodes = $object->attribute('assigned_nodes'); if ($nodeID == $this->attribute('main_node_id')) { if (count($assignedNodes) > 1) { $newMainNode = false; foreach ($assignedNodes as $assignedNode) { $assignedNodeID = $assignedNode->attribute('node_id'); if ($assignedNodeID == $nodeID) { continue; } $newMainNode = $assignedNode; break; } // We need to change the main node ID before we remove the current node $db = eZDB::instance(); $db->begin(); eZContentObjectTreeNode::updateMainNodeID($newMainNode->attribute('node_id'), $object->attribute('id'), $object->attribute('current_version'), $newMainNode->attribute('parent_node_id')); $this->removeThis(); eZSearch::addObject($object); $db->commit(); } else { // This is the last assignment so we remove the object too $db = eZDB::instance(); $db->begin(); $this->removeThis(); if ($moveToTrash) { // saving information about this node in ..trash_node table $trashNode = eZContentObjectTrashNode::createFromNode($this); $db = eZDB::instance(); $db->begin(); $trashNode->storeToTrash(); $db->commit(); $object->removeThis(); } else { $object->purge(); } $db->commit(); } } else { $this->removeThis(); if (count($assignedNodes) > 1) { eZSearch::addObject($object); } } }
/** * @param eZContentObjectTreenode $node * @param array $row * @return array */ protected static function nodeHasForbiddenWords( &$node, &$row ) { /* @type $clustersToHide array */ $clustersToHide = eZINI::instance( 'merck.ini' )->variable( 'PublishSettings', 'clustersToHide' ); $returnArray = array(); foreach ($clustersToHide as $cluster) { /* @type $languageList array */ $clusterIni = eZINI::fetchFromFile( "./extension/$cluster/settings/site.ini" ); $languageList = $clusterIni->variable('RegionalSettings', 'SiteLanguageList'); foreach( $languageList as $locale ) { /* @type $nodeDatamap eZContentObjectAttribute[] */ $nodeDatamap = $node->object()->fetchDataMap(false, $locale); if( !$nodeDatamap ) continue; if( $nodeDatamap['forbidden_article']->attribute('data_int') == 1 ) { // node is marked from publisher as containing some forbidden words = we hide $returnArray[$cluster] = array( 'toHide' => true, 'toDelete' => true, 'comment' => 'marked by publisher', ); break; } $forbiddenWordsArray = self::getForbiddenWordsArray($cluster); if(empty($forbiddenWordsArray)) { $returnArray[$cluster] = array( 'toHide' => false, 'toDelete' => true, 'comment' => 'no forbidden words on cluster', ); continue; } $lgExplode = explode('-', $locale); $languageFilter = $lgExplode[0] . '-*'; $params = array( 'indent' => 'on', 'qt' => 'standard', 'q' => '*:*', 'start' => 0, 'stop' => 0, 'fq' => implode(' AND ', array( 'meta_node_id_si:'.$node->attribute('node_id'), 'meta_language_code_ms:'.$languageFilter, 'meta_installation_id_ms:'.eZSolr::installationID() )), ); $isInSolrResult = SolrTool::rawSearch($params, 'php', false); if( !$isInSolrResult['response']['numFound'] ) { // the node is not in solr. We postpone its check if( $row['created'] < time() - 3600 * 4 ) { // the node was added more than 4 hours ago. It should be in solr. We ask for a reindex eZSearch::addObject( $node->object() ); $returnArray[$cluster] = array( 'toHide' => true, 'toDelete' => false, 'comment' => 'not indexed in solr yet', ); break; } if( $row['created'] < time() - 3600 * 48 ) { eZLog::write( sprintf( "%s\t Node %s still not in solr after 48h", date('Y-m-d H:i:s'), $node->attribute('node_id') ), 'updatevisibility.log' ); $returnArray[$cluster] = array( 'toHide' => true, 'toDelete' => true, 'comment' => 'node is taking too long to be indexed', ); break; } } $params['q'] = implode(' ', $forbiddenWordsArray); $solrResults = SolrTool::rawSearch($params, 'php', false); if( !$solrResults['response']['numFound'] ) { // content has forbidden words => we hide $returnArray[$cluster] = array( 'toHide' => true, 'toDelete' => true, 'comment' => 'has forbidden words', ); break; } } if ( !isset($returnArray[$cluster]) ) { $returnArray[$cluster] = array( 'toHide' => false, 'toDelete' => true, 'comment' => 'default case' ); } } return $returnArray; }