public static function build(\Closure $legacyKernelClosure)
 {
     try {
         $searchEngine = $legacyKernelClosure()->runCallback(function () {
             return \eZSearch::getEngine();
         });
     } catch (\Exception $e) {
         $searchEngine = new NullSearchEngine();
     }
     return $searchEngine;
 }
예제 #2
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;
    }
 /**
  * Set the always available flag for a content object
  *
  * @param int $objectID
  * @param int $newAlwaysAvailable
  * @return array An array with operation status, always true
  */
 public static function updateAlwaysAvailable($objectID, $newAlwaysAvailable)
 {
     $object = eZContentObject::fetch($objectID);
     $change = false;
     if ($object->isAlwaysAvailable() & $newAlwaysAvailable == false) {
         $object->setAlwaysAvailableLanguageID(false);
         $change = true;
     } else {
         if (!$object->isAlwaysAvailable() & $newAlwaysAvailable == true) {
             $object->setAlwaysAvailableLanguageID($object->attribute('initial_language_id'));
             $change = true;
         }
     }
     if ($change) {
         eZContentCacheManager::clearContentCacheIfNeeded($objectID);
         if (!eZSearch::getEngine() instanceof eZSearchEngine) {
             eZContentOperationCollection::registerSearchObject($objectID);
         }
     }
     return array('status' => true);
 }
예제 #4
0
/**
 * 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";
}
예제 #5
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) {
<?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");
}
 /**
  * Removes nodes
  *
  * This function does not check about permissions, this is the responsibility of the caller!
  *
  * @param array $removeNodeIdList Array of Node ID to remove
  *
  * @return array An array with operation status, always true
  */
 public static function removeNodes(array $removeNodeIdList)
 {
     $mainNodeChanged = array();
     $nodeAssignmentIdList = array();
     $objectIdList = array();
     $db = eZDB::instance();
     $db->begin();
     foreach ($removeNodeIdList as $nodeId) {
         $node = eZContentObjectTreeNode::fetch($nodeId);
         $objectId = $node->attribute('contentobject_id');
         foreach (eZNodeAssignment::fetchForObject($objectId, eZContentObject::fetch($objectId)->attribute('current_version'), 0, false) as $nodeAssignmentKey => $nodeAssignment) {
             if ($nodeAssignment['parent_node'] == $node->attribute('parent_node_id')) {
                 $nodeAssignmentIdList[$nodeAssignment['id']] = 1;
             }
         }
         if ($nodeId == $node->attribute('main_node_id')) {
             $mainNodeChanged[$objectId] = 1;
         }
         $node->removeThis();
         if (!isset($objectIdList[$objectId])) {
             $objectIdList[$objectId] = eZContentObject::fetch($objectId);
         }
     }
     // Give other search engines that the default one a chance to reindex
     // when removing locations.
     if (!eZSearch::getEngine() instanceof eZSearchEngine) {
         foreach ($objectIdList as $objectId => $object) {
             eZContentOperationCollection::registerSearchObject($objectId, $object->attribute('current_version'));
         }
     }
     eZNodeAssignment::purgeByID(array_keys($nodeAssignmentIdList));
     foreach (array_keys($mainNodeChanged) as $objectId) {
         $allNodes = $objectIdList[$objectId]->assignedNodes();
         // Registering node that will be promoted as 'main'
         $mainNodeChanged[$objectId] = $allNodes[0];
         eZContentObjectTreeNode::updateMainNodeID($allNodes[0]->attribute('node_id'), $objectId, false, $allNodes[0]->attribute('parent_node_id'));
     }
     $db->commit();
     //call appropriate method from search engine
     eZSearch::removeNodes($removeNodeIdList);
     $userClassIdList = eZUser::contentClassIDs();
     foreach ($objectIdList as $objectId => $object) {
         eZContentCacheManager::clearObjectViewCacheIfNeeded($objectId);
         // clear user policy cache if this was a user object
         if (in_array($object->attribute('contentclass_id'), $userClassIdList)) {
             eZUser::purgeUserCacheByUserId($object->attribute('id'));
         }
     }
     // we don't clear template block cache here since it's cleared in eZContentObjectTreeNode::removeNode()
     return array('status' => true);
 }