public static function build(\Closure $legacyKernelClosure)
 {
     try {
         $searchEngine = $legacyKernelClosure()->runCallback(function () {
             return \eZSearch::getEngine();
         });
     } catch (\Exception $e) {
         $searchEngine = new NullSearchEngine();
     }
     return $searchEngine;
 }
 public static function fetchContentSearch($searchText, $subTreeArray, $offset, $limit, $searchTimestamp, $publishDate, $sectionID, $classID, $classAttributeID, $ignoreVisibility, $limitation, $sortArray)
 {
     $searchArray = eZSearch::buildSearchArray();
     $parameters = array();
     if ($classID !== false) {
         $parameters['SearchContentClassID'] = $classID;
     }
     if ($classAttributeID !== false) {
         $parameters['SearchContentClassAttributeID'] = $classAttributeID;
     }
     if ($sectionID !== false) {
         $parameters['SearchSectionID'] = $sectionID;
     }
     if ($publishDate !== false) {
         $parameters['SearchDate'] = $publishDate;
     }
     if ($sortArray !== false) {
         $parameters['SortArray'] = $sortArray;
     }
     $parameters['SearchLimit'] = $limit;
     $parameters['SearchOffset'] = $offset;
     $parameters['IgnoreVisibility'] = $ignoreVisibility;
     $parameters['Limitation'] = $limitation;
     if ($subTreeArray !== false) {
         $parameters['SearchSubTreeArray'] = $subTreeArray;
     }
     if ($searchTimestamp) {
         $parameters['SearchTimestamp'] = $searchTimestamp;
     }
     $searchResult = eZSearch::search($searchText, $parameters, $searchArray);
     return array('result' => $searchResult);
 }
Example #3
0
 /**
  * Returns search results based on given post params
  *
  * @param mixed $args Only used if post parameter is not set
  *              0 => SearchStr
  *              1 => SearchOffset
  *              2 => SearchLimit (10 by default, max 50)
  * @return array
  */
 public static function search($args)
 {
     $http = eZHTTPTool::instance();
     if ($http->hasPostVariable('SearchStr')) {
         $searchStr = trim($http->postVariable('SearchStr'));
     } else {
         if (isset($args[0])) {
             $searchStr = trim($args[0]);
         }
     }
     if ($http->hasPostVariable('SearchOffset')) {
         $searchOffset = (int) $http->postVariable('SearchOffset');
     } else {
         if (isset($args[1])) {
             $searchOffset = (int) $args[1];
         } else {
             $searchOffset = 0;
         }
     }
     if ($http->hasPostVariable('SearchLimit')) {
         $searchLimit = (int) $http->postVariable('SearchLimit');
     } else {
         if (isset($args[2])) {
             $searchLimit = (int) $args[2];
         } else {
             $searchLimit = 10;
         }
     }
     // Do not allow to search for more then x items at a time
     $ini = eZINI::instance();
     $maximumSearchLimit = (int) $ini->variable('SearchSettings', 'MaximumSearchLimit');
     if ($searchLimit > $maximumSearchLimit) {
         $searchLimit = $maximumSearchLimit;
     }
     // Prepare node encoding parameters
     $encodeParams = array();
     if (self::hasPostValue($http, 'EncodingLoadImages')) {
         $encodeParams['loadImages'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFetchChildrenCount')) {
         $encodeParams['fetchChildrenCount'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFetchSection')) {
         $encodeParams['fetchSection'] = true;
     }
     if (self::hasPostValue($http, 'EncodingFormatDate')) {
         $encodeParams['formatDate'] = $http->postVariable('EncodingFormatDate');
     }
     // Prepare search parameters
     $params = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SortArray' => array('published', 0), 'SortBy' => array('published' => 'desc'));
     if (self::hasPostValue($http, 'SearchContentClassAttributeID')) {
         $params['SearchContentClassAttributeID'] = self::makePostArray($http, 'SearchContentClassAttributeID');
     } else {
         if (self::hasPostValue($http, 'SearchContentClassID')) {
             $params['SearchContentClassID'] = self::makePostArray($http, 'SearchContentClassID');
         } else {
             if (self::hasPostValue($http, 'SearchContentClassIdentifier')) {
                 $params['SearchContentClassID'] = eZContentClass::classIDByIdentifier(self::makePostArray($http, 'SearchContentClassIdentifier'));
             }
         }
     }
     if (self::hasPostValue($http, 'SearchSubTreeArray')) {
         $params['SearchSubTreeArray'] = self::makePostArray($http, 'SearchSubTreeArray');
     }
     if (self::hasPostValue($http, 'SearchSectionID')) {
         $params['SearchSectionID'] = self::makePostArray($http, 'SearchSectionID');
     }
     if (self::hasPostValue($http, 'SearchDate')) {
         $params['SearchDate'] = (int) $http->postVariable('SearchDate');
     } else {
         if (self::hasPostValue($http, 'SearchTimestamp')) {
             $params['SearchTimestamp'] = self::makePostArray($http, 'SearchTimestamp');
             if (!isset($params['SearchTimestamp'][1])) {
                 $params['SearchTimestamp'] = $params['SearchTimestamp'][0];
             }
         }
     }
     if (self::hasPostValue($http, 'EnableSpellCheck') || self::hasPostValue($http, 'enable-spellcheck', '0')) {
         $params['SpellCheck'] = array(true);
     }
     if (self::hasPostValue($http, 'GetFacets') || self::hasPostValue($http, 'show-facets', '0')) {
         $params['facet'] = eZFunctionHandler::execute('ezfind', 'getDefaultSearchFacets', array());
     }
     $result = array('SearchOffset' => $searchOffset, 'SearchLimit' => $searchLimit, 'SearchResultCount' => 0, 'SearchCount' => 0, 'SearchResult' => array(), 'SearchString' => $searchStr, 'SearchExtras' => array());
     // Possibility to keep track of callback reference for use in js callback function
     if ($http->hasPostVariable('CallbackID')) {
         $result['CallbackID'] = $http->postVariable('CallbackID');
     }
     // Only search if there is something to search for
     if ($searchStr) {
         $searchList = eZSearch::search($searchStr, $params);
         $result['SearchResultCount'] = $searchList['SearchResult'] !== false ? count($searchList['SearchResult']) : 0;
         $result['SearchCount'] = (int) $searchList['SearchCount'];
         $result['SearchResult'] = ezjscAjaxContent::nodeEncode($searchList['SearchResult'], $encodeParams, false);
         // ezfind stuff
         if (isset($searchList['SearchExtras']) && $searchList['SearchExtras'] instanceof ezfSearchResultInfo) {
             if (isset($params['SpellCheck'])) {
                 $result['SearchExtras']['spellcheck'] = $searchList['SearchExtras']->attribute('spellcheck');
             }
             if (isset($params['facet'])) {
                 $facetInfo = array();
                 $retrievedFacets = $searchList['SearchExtras']->attribute('facet_fields');
                 $baseSearchUrl = "/content/search/";
                 eZURI::transformURI($baseSearchUrl, false, 'full');
                 foreach ($params['facet'] as $key => $defaultFacet) {
                     $facetData = $retrievedFacets[$key];
                     $facetInfo[$key] = array('name' => $defaultFacet['name'], 'list' => array());
                     if ($facetData !== null) {
                         foreach ($facetData['nameList'] as $key2 => $facetName) {
                             if ($key2 != '') {
                                 $tmp = array('value' => $facetName);
                                 $tmp['url'] = $baseSearchUrl . '?SearchText=' . $searchStr . '&filter[]=' . $facetData['queryLimit'][$key2] . '&activeFacets[' . $defaultFacet['field'] . ':' . $defaultFacet['name'] . ']=' . $facetName;
                                 $tmp['count'] = $facetData['countList'][$key2];
                                 $facetInfo[$key]['list'][] = $tmp;
                             }
                         }
                     }
                 }
                 $result['SearchExtras']['facets'] = $facetInfo;
             }
         }
         //$searchList['SearchExtras'] instanceof ezfSearchResultInfo
     }
     // $searchStr
     return $result;
 }
 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);
         }
     }
 }
    /**
     * Archives the current object and removes assigned nodes
     *
     * 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 $nodeID
     */
    function removeThis( $nodeID = null )
    {
        $delID = $this->ID;

        // Who deletes which content should be logged.
        eZAudit::writeAudit( 'content-delete', array( 'Object ID' => $delID, 'Content Name' => $this->attribute( 'name' ),
                                                      'Comment' => 'Setted archived status for the current object: eZContentObject::remove()' ) );

        $nodes = $this->attribute( 'assigned_nodes' );

        if ( $nodeID === null or count( $nodes ) <= 1 )
        {
            $db = eZDB::instance();
            $db->begin();
            $mainNodeKey = false;
            foreach ( $nodes as $key => $node )
            {
                if ( $node->attribute( 'main_node_id' ) == $node->attribute( 'node_id' ) )
                {
                    $mainNodeKey = $key;
                }
                else
                {
                    $node->removeThis();
                }
            }

            if ( $mainNodeKey !== false )
            {
                $nodes[$mainNodeKey]->removeNodeFromTree( true );
            }


            $this->setAttribute( 'status', eZContentObject::STATUS_ARCHIVED );
            eZSearch::removeObjectById( $delID );
            $this->store();
            eZContentObject::fixReverseRelations( $delID, 'trash' );
            // Delete stored attribute from other tables
            $db->commit();

        }
        else if ( $nodeID !== null )
        {
            $node = eZContentObjectTreeNode::fetch( $nodeID , false );
            if ( is_object( $node ) )
            {
                if ( $node->attribute( 'main_node_id' ) == $nodeID )
                {
                    $db = eZDB::instance();
                    $db->begin();
                    foreach ( $additionalNodes as $additionalNode )
                    {
                        if ( $additionalNode->attribute( 'node_id' ) != $node->attribute( 'main_node_id' ) )
                        {
                            $additionalNode->remove();
                        }
                    }

                    $node->removeNodeFromTree( true );
                    $this->setAttribute( 'status', eZContentObject::STATUS_ARCHIVED );
                    eZSearch::removeObjectById( $delID );
                    $this->store();
                    eZContentObject::fixReverseRelations( $delID, 'trash' );
                    $db->commit();
                }
                else
                {
                    eZContentObjectTreeNode::removeNode( $nodeID );
                }
            }
        }
        else
        {
            eZContentObjectTreeNode::removeNode( $nodeID );
        }
    }
    }

    $pathIdentificationString = $node->attribute('path_identification_string');

    if ( $node->IsHidden )
    {
        $cli->warning ( " Already hidden : [" . $nodeId . "] " . $pathIdentificationString . " : " . $node->getName() );
        continue;
    }

    $validCalculatorsNodeId[] = $nodeId;
    $possibleReplies[] = $nodeId . " " . $pathIdentificationString . " : " . $node->getName();
}

$questionHandler = new QuestionInteractiveCli();
$question = "Hide which nodes";

$response = $questionHandler->askQuestionMultipleChoices($question, $possibleReplies, 'validateReplyMultiple', true);

foreach ( $response as $indexToHide )
{
    $nodeId = $validCalculatorsNodeId[$indexToHide];
    $node   = eZContentObjectTreeNode::fetch($nodeId);

    eZContentObjectTreeNode::hideSubTree( $node );
    eZSearch::updateNodeVisibility( $node->NodeID, 'hide' );

    $pathIdentificationString = $node->attribute('path_identification_string');
    $cli->warning ( " Hiding : [" . $nodeId . "] " . $pathIdentificationString . " : " . $node->getName() );
}
    } else {
        $subTreeList = array($http->variable('SubTreeArray'));
    }
    foreach ($subTreeList as $subTreeItem) {
        // as form input is generally a string, is_int cannot be used for checking the value type
        if (is_numeric($subTreeItem) && $subTreeItem > 0) {
            $subTreeArray[] = $subTreeItem;
        }
    }
}
$Module->setTitle("Search for: {$searchText}");
$classArray = eZContentClass::fetchList(eZContentClass::VERSION_STATUS_DEFINED, true, false, array('name' => 'asc'));
$sectionArray = eZSection::fetchList();
$searchArray = eZSearch::buildSearchArray();
if ($useSearchCode) {
    $searchResult = eZSearch::search($searchText, array('SearchSectionID' => $searchSectionID, 'SearchContentClassID' => $searchContentClassID, 'SearchContentClassAttributeID' => $searchContentClassAttributeID, 'SearchSubTreeArray' => $subTreeArray, 'SearchDate' => $searchDate, 'SearchTimestamp' => $searchTimestamp, 'SearchLimit' => $pageLimit, 'SearchOffset' => $Offset), $searchArray);
    if (strlen(trim($searchText)) == 0 && count($searchArray) > 0) {
        $searchText = 'search by additional parameter';
    }
}
$viewParameters = array('offset' => $Offset);
$searchData = false;
$tpl->setVariable("search_data", $searchData);
$tpl->setVariable('search_contentclass_id', $searchContentClassID);
$tpl->setVariable('search_contentclass_attribute_id', $searchContentClassAttributeID);
$tpl->setVariable('search_section_id', $searchSectionID);
$tpl->setVariable('search_date', $searchDate);
$tpl->setVariable('search_timestamp', $searchTimestamp);
$tpl->setVariable('search_sub_tree', $subTreeArray);
$tpl->setVariable('search_text', $searchText);
$tpl->setVariable('search_page_limit', $searchPageLimit);
<?php

/**
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
 * @license For full copyright and license information view LICENSE file distributed with this source code.
 * @version 2014.07.0
 */
if (!$isQuiet) {
    $cli->output("Starting solr index optimization");
}
// check that solr is enabled and used
$eZSolr = eZSearch::getEngine();
if (!$eZSolr instanceof eZSolr) {
    $script->shutdown(1, 'The current search engine plugin is not eZSolr');
}
$eZSolr->optimize(false);
if (!$isQuiet) {
    $cli->output("Done");
}
 static function move($nodeID, $newParentNodeID)
 {
     $result = false;
     if (!is_numeric($nodeID) || !is_numeric($newParentNodeID)) {
         return false;
     }
     $node = eZContentObjectTreeNode::fetch($nodeID);
     if (!$node) {
         return false;
     }
     $object = $node->object();
     if (!$object) {
         return false;
     }
     $objectID = $object->attribute('id');
     $oldParentNode = $node->fetchParent();
     $oldParentObject = $oldParentNode->object();
     // clear user policy cache if this is a user object
     if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) {
         eZUser::purgeUserCacheByUserId($object->attribute('id'));
     }
     // clear cache for old placement.
     // If child count exceeds threshold, do nothing here, and instead clear all view cache at the end.
     $childCountInThresholdRange = eZContentCache::inCleanupThresholdRange($node->childrenCount(false));
     if ($childCountInThresholdRange) {
         eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     }
     $db = eZDB::instance();
     $db->begin();
     $node->move($newParentNodeID);
     $newNode = eZContentObjectTreeNode::fetchNode($objectID, $newParentNodeID);
     if ($newNode) {
         $newNode->updateSubTreePath(true, true);
         if ($newNode->attribute('main_node_id') == $newNode->attribute('node_id')) {
             // If the main node is moved we need to check if the section ID must change
             $newParentNode = $newNode->fetchParent();
             $newParentObject = $newParentNode->object();
             if ($object->attribute('section_id') != $newParentObject->attribute('section_id')) {
                 eZContentObjectTreeNode::assignSectionToSubTree($newNode->attribute('main_node_id'), $newParentObject->attribute('section_id'), $oldParentObject->attribute('section_id'));
             }
         }
         // modify assignment
         $curVersion = $object->attribute('current_version');
         $nodeAssignment = eZNodeAssignment::fetch($objectID, $curVersion, $oldParentNode->attribute('node_id'));
         if ($nodeAssignment) {
             $nodeAssignment->setAttribute('parent_node', $newParentNodeID);
             $nodeAssignment->setAttribute('op_code', eZNodeAssignment::OP_CODE_MOVE);
             $nodeAssignment->store();
             // update search index specifying we are doing a move operation
             $nodeIDList = array($nodeID);
             eZSearch::removeNodeAssignment($node->attribute('main_node_id'), $newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList);
             eZSearch::addNodeAssignment($newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList, true);
         }
         $result = true;
     } else {
         eZDebug::writeError("Node {$nodeID} was moved to {$newParentNodeID} but fetching the new node failed");
     }
     $db->commit();
     // clear cache for new placement.
     // If child count exceeds threshold, clear all view cache instead.
     if ($childCountInThresholdRange) {
         eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     } else {
         eZContentCacheManager::clearAllContentCache();
     }
     return $result;
 }
             $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 {
Example #11
0
$nodeID = $module->actionParameter( 'NodeID' );
$languageCode = $module->actionParameter( 'LanguageCode' );

$viewMode = 'full';
if ( !$module->hasActionParameter( 'ViewMode' ) )
{
    $viewMode = $module->actionParameter( 'ViewMode' );
}

if ( $module->isCurrentAction( 'IndexObject' )
     || $module->isCurrentAction( 'IndexSubtree' )) {
    eZContentOperationCollection::registerSearchObject( $objectID );
}

if ( $module->isCurrentAction( 'IndexSubtree' ) ) {
    $pendingAction = new eZPendingActions(
        array(
            'action' => eZSolr::PENDING_ACTION_INDEX_SUBTREE,
            'created' => time(),
            'param' => $nodeID
        )
    );
    $pendingAction->store();
}

if ( $module->isCurrentAction( 'RemoveObject' ) ) {
    $object = eZContentObject::fetch($objectID);
    eZSearch::removeObject($object, true);
}

return $module->redirect( 'content', 'view', array( $viewMode, $nodeID, $languageCode ) );
    static function move( $nodeID, $newParentNodeID )
    {
        $result = false;

        if ( !is_numeric( $nodeID ) || !is_numeric( $newParentNodeID ) )
            return false;

        $node = eZContentObjectTreeNode::fetch( $nodeID );
        if ( !$node )
            return false;

        $object = $node->object();
        if ( !$object )
            return false;

        $objectID = $object->attribute( 'id' );
        $oldParentNode = $node->fetchParent();
        $oldParentObject = $oldParentNode->object();

        // clear user policy cache if this is a user object
        if ( in_array( $object->attribute( 'contentclass_id' ), eZUser::contentClassIDs() ) )
        {
            eZUser::purgeUserCacheByUserId( $object->attribute( 'id' ) );
        }

        // clear cache for old placement.
        eZContentCacheManager::clearContentCacheIfNeeded( $objectID );

        $db = eZDB::instance();
        $db->begin();

        $node->move( $newParentNodeID );

        $newNode = eZContentObjectTreeNode::fetchNode( $objectID, $newParentNodeID );

        if ( $newNode )
        {
            $newNode->updateSubTreePath( true, true );
            if ( $newNode->attribute( 'main_node_id' ) == $newNode->attribute( 'node_id' ) )
            {
                // If the main node is moved we need to check if the section ID must change
                $newParentNode = $newNode->fetchParent();
                $newParentObject = $newParentNode->object();
                if ( $object->attribute( 'section_id' ) != $newParentObject->attribute( 'section_id' ) )
                {

                    eZContentObjectTreeNode::assignSectionToSubTree( $newNode->attribute( 'main_node_id' ),
                                                                     $newParentObject->attribute( 'section_id' ),
                                                                     $oldParentObject->attribute( 'section_id' ) );
                }
            }

            // modify assignment
            $curVersion     = $object->attribute( 'current_version' );
            $nodeAssignment = eZNodeAssignment::fetch( $objectID, $curVersion, $oldParentNode->attribute( 'node_id' ) );

            if ( $nodeAssignment )
            {
                $nodeAssignment->setAttribute( 'parent_node', $newParentNodeID );
                $nodeAssignment->setAttribute( 'op_code', eZNodeAssignment::OP_CODE_MOVE );
                $nodeAssignment->store();

                // update search index
                $nodeIDList = array( $nodeID );
                eZSearch::removeNodeAssignment( $node->attribute( 'main_node_id' ), $newNode->attribute( 'main_node_id' ), $object->attribute( 'id' ), $nodeIDList );
                eZSearch::addNodeAssignment( $newNode->attribute( 'main_node_id' ), $object->attribute( 'id' ), $nodeIDList );
            }

            $result = true;
        }
        else
        {
            eZDebug::writeError( "Node $nodeID was moved to $newParentNodeID but fetching the new node failed" );
        }

        $db->commit();

        // clear cache for new placement.
        eZContentCacheManager::clearContentCacheIfNeeded( $objectID );

        return $result;
    }
    /**
     * @param eZContentObject $contentObject
     * @param bool|null $parentIsInvisible Only defined as boolean true|false if we are recursively going in a child
     */
    public static function updateGlobalLimitation ( $contentObject, $parentIsInvisible = null )
    {
        /* @type $contentMainNode eZContentObjectTreeNode */
        $db              = eZDB::instance();
        $contentObjectID = $contentObject->attribute('id');
        $contentMainNode = $contentObject->mainNode();

        if ( !($contentMainNode instanceof eZContentObjectTreeNode) )
            return;

        /* @type $dm eZContentObjectAttribute[] */
        $contentDepth         = $contentMainNode->attribute('depth');
        $merckINI             = eZINI::instance('merck.ini');
        $onlineDateAttribute  = $merckINI->variable("ArticleVisibility","OnlineDate");
        $offlineDateAttribute = $merckINI->variable("ArticleVisibility","OfflineDate");
        $dm                   = $contentObject->attribute("data_map");

        if ( !is_array($dm) )
            return;

        /* @type $onlineDateContent eZDateTime */
        /* @type $offlineDateContent eZDateTime */
        $onlineDateContent    = $dm[$onlineDateAttribute]->content();
        $onlineDate           = $onlineDateContent->timeStamp();
        $offlineDateContent   = $dm[$offlineDateAttribute]->content();
        $offlineDate          = $offlineDateContent->timeStamp();
        $visibility           = MMEventManager::visibilityDates($contentObject);
        $isInvisible          = !$visibility;

        // We have a parent article, we check its visibility
        if ( !$isInvisible && $parentIsInvisible === null && $contentDepth > 4 )
        {
            $parentNode  = $contentMainNode->fetchParent();
            $isInvisible = self::isGloballyLimited( $parentNode->attribute('contentobject_id') );
        }
        elseif ( !$isInvisible )
        {
            if ( $parentIsInvisible !== null && $parentIsInvisible === true )
                $isInvisible = true;
        }

        $db->beginQuery();

        $visibilityChange = self::updateGlobalLimitationEntry( $contentObjectID, $offlineDate, $onlineDate, $visibility, $isInvisible);

        if ( $visibilityChange && $visibility && !$isInvisible )
        {
            eZSearch::updateNodeVisibility($contentObject->mainNodeID(), 'show');
        }
        elseif ( $visibilityChange && ( !$visibility || $isInvisible ) )
        {
            eZSearch::updateNodeVisibility($contentObject->mainNodeID(), 'hide');
        }

        if ( $visibilityChange )
            self::spreadGlobalLimitationChange( $contentMainNode, $isInvisible );

        $db->commitQuery();
    }
    /**
     * @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;
    }
 /**
  * Update a contentobject's state
  *
  * @param int $objectID
  * @param int $selectedStateIDList
  *
  * @return array An array with operation status, always true
  */
 public static function updateObjectState($objectID, $selectedStateIDList)
 {
     $object = eZContentObject::fetch($objectID);
     // we don't need to re-assign states the object currently already has assigned
     $currentStateIDArray = $object->attribute('state_id_array');
     $selectedStateIDList = array_diff($selectedStateIDList, $currentStateIDArray);
     // filter out any states the current user is not allowed to assign
     $canAssignStateIDList = $object->attribute('allowed_assign_state_id_list');
     $selectedStateIDList = array_intersect($selectedStateIDList, $canAssignStateIDList);
     foreach ($selectedStateIDList as $selectedStateID) {
         $state = eZContentObjectState::fetchById($selectedStateID);
         $object->assignState($state);
     }
     //call appropriate method from search engine
     eZSearch::updateObjectState($objectID, $selectedStateIDList);
     eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     return array('status' => true);
 }
Example #16
0
<?php

/**
 * File containing the indexcontent.php cronjob
 *
 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 * @version //autogentag//
 * @package kernel
 */
$cli->output("Starting processing pending search engine modifications");
$contentObjects = array();
$db = eZDB::instance();
$offset = 0;
$limit = 50;
$searchEngine = eZSearch::getEngine();
if (!$searchEngine instanceof ezpSearchEngine) {
    $cli->error("The configured search engine does not implement the ezpSearchEngine interface or can't be found.");
    $script->shutdown(1);
}
$needRemoveWithUpdate = $searchEngine->needRemoveWithUpdate();
while (true) {
    $entries = $db->arrayQuery("SELECT param FROM ezpending_actions WHERE action = 'index_object' GROUP BY param ORDER BY min(created)", array('limit' => $limit, 'offset' => $offset));
    if (is_array($entries) && count($entries) != 0) {
        foreach ($entries as $entry) {
            $objectID = (int) $entry['param'];
            $cli->output("\tIndexing object ID #{$objectID}");
            $db->begin();
            $object = eZContentObject::fetch($objectID);
            $removeFromPendingActions = true;
            if ($object) {
Example #17
0
    /**
     * Notifies search engine about an swap node operation
     *
     * @since 4.1
     * @param int $nodeID
     * @param int $selectedNodeID
     * @param array $nodeIdList
     * @return false|mixed False in case method is undefined, otherwise return the result of the search engine call
     */
    public static function swapNode( $nodeID, $selectedNodeID, $nodeIdList = array() )
    {
        $searchEngine = eZSearch::getEngine();

        if ( $searchEngine instanceof ezpSearchEngine && method_exists( $searchEngine, 'swapNode' ) )
        {
            return $searchEngine->swapNode( $nodeID, $selectedNodeID, $nodeIdList = array() );
        }

        return false;
    }
/**
 * Aligns articles published under given publisher folder
 * @param eZContentObject $publisherObject
 */
function alignArticle( $publisherObject, $checkModified = false, $checkLocations = false, $checkLanguages = false, $checkHidden = false, $timingDelay = 0, $forceLast = 0, $sleepTime = 1 )
{
	echo "Starting treatment of publisher folder : " . $publisherObject->name() . "\n";
	echo "Fetching solr informations\n";
	$eZSolr        = eZSearch::getEngine();
	$offset        = 0;
    $forced        = 0;
	$limit         = 200;
	$publisherNode = $publisherObject->mainNode();
	$doCheck       = $checkModified || $checkLocations || $checkLanguages || $checkHidden;
	$solrInfos     = fetchSolrPublisherFolder ( $publisherNode, $checkModified, $checkLocations, $checkLanguages, $checkHidden, $sleepTime );
	
	echo "Solr count : " . count($solrInfos) . "\n";

	while ( true )
	{
		$params = array(
				'Offset'           => $offset,
				'Limit'            => $limit,
				'ClassFilterType'  => 'include',
				'ClassFilterArray' => array( 'article' ),
				'LoadDataMap'      => false,
				'AsObject'         => false,
				'MainNodeOnly'     => true,
		);
        
        if ($forceLast > 0)
            $params['SortBy'] = array ( array('published', false ) );

		$nodeList = $publisherNode->subtree( $params );
		echo "\neZ Offset : $offset\n";

		if ( count( $nodeList ) == 0 )
		{
			break;
		}
	
		foreach ( $nodeList as $mainNode )
		{
			$nodeId = $mainNode['node_id'];
			$objectId = $mainNode['contentobject_id'];
			$toUpdate = false;

            if ( $forceLast > 0 && $forced < $forceLast )
                $toUpdate = true;
			elseif ( isset($solrInfos[$nodeId]) )
			{
				if ( $doCheck )
				{
					if ( $checkLanguages )
					{
						$eZLanguages = eZContentObject::fetch($objectId)->languages();
						$toUpdate = compareLanguages( array_keys($eZLanguages), $solrInfos[$nodeId]['languages'] );
						
						showInvalidTranslations(array_keys($eZLanguages), $solrInfos[$nodeId]['languages'], $objectId);
					}

					if (!$toUpdate && $checkModified)
						$toUpdate = compareDates($mainNode['modified'], $solrInfos[$nodeId]['modified'], $timingDelay);

					if (!$toUpdate && $checkLocations)
						$toUpdate = compareLocations($objectId, $solrInfos[$nodeId]['locations']);

                    if (!$toUpdate && $checkHidden)
                        $toUpdate = compareHidden($objectId, $solrInfos[$nodeId]['hiddenCount'], $solrInfos[$nodeId]['notHiddenCount']);
				}

				unset($solrInfos[$nodeId]);
			}
			else
				$toUpdate = true;

			if ( $toUpdate )
			{
				$return = $eZSolr->addObject( eZContentObject::fetch($objectId), false );

				echo ( !$return ? '!' . $objectId . '!' : '+' );
			}
			else
				echo '-';
            
            $forced++;
		}
	
		$offset += $limit;

		eZContentObject::clearCache();
        
        if ( $sleepTime > 0 )
            sleep ($sleepTime);
	}
	
	echo "\nArticles in solr but unknown from eZPublish : " . count($solrInfos) . " articles\n";
}
Example #19
0
    $keyArray = array(array('section', $searchSectionID), array('section_identifier', $section->attribute('identifier')));
    $res->setKeys($keyArray);
}
$viewParameters = array('offset' => $Offset);
$searchData = false;
$tpl->setVariable("search_data", $searchData);
$tpl->setVariable("search_section_id", $searchSectionID);
$tpl->setVariable("search_subtree_array", $subTreeArray);
$tpl->setVariable('search_timestamp', $searchTimestamp);
$tpl->setVariable("search_text", $searchText);
$tpl->setVariable('search_page_limit', $searchPageLimit);
$tpl->setVariable("view_parameters", $viewParameters);
$tpl->setVariable('use_template_search', !$useSearchCode);
if ($http->hasVariable('Mode') && $http->variable('Mode') == 'browse') {
    if (!isset($searchResult)) {
        $searchResult = eZSearch::search($searchText, array("SearchType" => $searchType, "SearchSectionID" => $searchSectionID, "SearchSubTreeArray" => $subTreeArray, 'SearchTimestamp' => $searchTimestamp, "SearchLimit" => $pageLimit, "SearchOffset" => $Offset));
    }
    $sys = eZSys::instance();
    $searchResult['RequestedURI'] = "content/search";
    //    $searchResult['RequestedURISuffix'] = $sys->serverVariable( "QUERY_STRING" );
    $searchResult['RequestedURISuffix'] = 'SearchText=' . urlencode($searchText) . ($searchTimestamp > 0 ? '&SearchTimestamp=' . $searchTimestamp : '') . '&BrowsePageLimit=' . $pageLimit . '&Mode=browse';
    return $Module->run('browse', array(), array("NodeList" => $searchResult, "Offset" => $Offset, "NodeID" => isset($subTreeArray[0]) && $subTreeArray[0] != 1 ? $subTreeArray[0] : null));
}
// --- Compatibility code start ---
if ($useSearchCode) {
    $tpl->setVariable("offset", $Offset);
    $tpl->setVariable("page_limit", $pageLimit);
    $tpl->setVariable("search_text_enc", urlencode($searchText));
    $tpl->setVariable("search_result", $searchResult["SearchResult"]);
    $tpl->setVariable("search_count", $searchResult["SearchCount"]);
    $tpl->setVariable("stop_word_array", $searchResult["StopWordArray"]);
Example #20
0
 /**
  * Change node`s visibility
  *
  * @private
  * @param eZContentObject $object
  * @param bool $visibility
  * @return void
  */
 private function updateVisibility($object, $visibility = true)
 {
     $action = $visibility ? 'show' : 'hide';
     $nodeAssigments = eZPersistentObject::fetchObjectList(eZNodeAssignment::definition(), null, array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version')), null, null, true);
     foreach ($nodeAssigments as $nodeAssigment) {
         $node = $nodeAssigment->attribute('node');
         if ($node instanceof eZContentObjectTreeNode === false) {
             continue;
         }
         if ((bool) (!$node->attribute('is_hidden')) === (bool) $visibility) {
             continue;
         }
         if ($action == 'show') {
             eZContentObjectTreeNode::unhideSubTree($node);
         } else {
             eZContentObjectTreeNode::hideSubTree($node);
         }
         eZSearch::updateNodeVisibility($node->attribute('node_id'), $action);
     }
 }