/**
  * Switches automatically between a node and solrdata
  *
  * @param eZContentObjectTreeNode|string[] $node
  * @return string
  */
 static function getPathPublisher($node)
 {
     if ( $node instanceof eZContentObjectTreeNode )
         return PublisherFolderTool::getPublisherFolderPathFromArticleNode($node);
     elseif ( is_array($node) && isset($node['publisher_path']) )
         return $node['publisher_path'];
     else
         return '';
 }
    /**
     * @param eZContentObjectTreeNode $node
     * @param string|ApplicationLocalized $application
     * @param boolean $isSolrData
     * @return PublisherFolder
     */
    public static function getPublisherFolder ( $node, $application, $isSolrData = false )
    {
        if( is_string( $application ) )
            $application = CacheApplicationTool::buildLocalizedApplicationByIdentifier($application);

        if ( !($application instanceof ApplicationLocalized) )
            return null;

        $publisherPath = "";

        switch ( true )
        {
            case $isSolrData :
                if ( !is_array($node) || !isset( $node['publisher_path']) )
                    return null;

                $publisherPath = $node['publisher_path'];
                break;
            case ( is_numeric( $node ) && $node > 0 ) :
                $node = eZContentObjectTreeNode::fetch($node);

                if ( !($node instanceof eZContentObjectTreeNode) )
                    return null;

            // No break as we want to use the next step as well
            case ( $node instanceof eZContentObjectTreeNode ) :
            {
                /* @var $node eZContentObjectTreeNode */
                if ( $node->ClassIdentifier != 'publisher_folder' )
                    $publisherPath = PublisherFolderTool::getPublisherFolderPathFromArticleNode($node);
                else
                {
                    $publisherInfo = PublisherFolderTool::getPublisherFolderInfosFromNodeId(
                        $node->attribute('node_id')
                    );
                    $publisherPath = $publisherInfo['path'];
                }
            }
                break;
            case is_string( $node ) :
                $publisherPath = $node;
                break;
        }

        return PublisherFolder::getPublisherFromPath($publisherPath);
//        return $application->getPublisherFolderFromPath($publisherPath);
    }
    /**
     * @param eZContentObjectTreeNode $node
     * @return string[]
     */
    public static function getArticleClusters( $node )
    {
        $publisherFolderPath = PublisherFolderTool::getPublisherFolderPathFromArticleNode($node);

        return PublisherFolderTool::getClustersFromPath($publisherFolderPath);
    }
    /**
     * Manage varnish cache
     * Called from Listener factory
     *
     * @param array $nodeList
     * @return array
     */
    public static function preBanUrl( $nodeList )
    {
        if ( empty($nodeList) )
            return array();

        $db              = eZDB::instance();
        $nodeList        = array_unique( $nodeList );
        $pendingNodeList = array();
        $clustersClear = array( 'cluster_france', 'cluster_mx', 'cluster_cn', 'cluster_us', 'cluster_au' );
        $query           = sprintf(
            "SELECT param_int FROM ezpending_actions 
             WHERE action = '%s' 
             AND param_int in ('%s') 
             LIMIT 1000",
            VarnishControl::PENDING_VARNISH_LABEL,
            implode(', ', $nodeList) 
        );

        foreach( $db->arrayQuery($query) as $row )
            $pendingNodeList[] = $row['param_int'];
        
        $remainingNodeList = array_diff( $nodeList, $pendingNodeList );

        if ( empty($remainingNodeList) )
            return array();
        
        foreach( $remainingNodeList as $nodeId )
        {
            $values = array();
            $timeStamp = time();
            /* @type $clusters array */
            $node = eZContentObjectTreeNode::fetch( $nodeId );

            if ( empty( $node ) )
            {
                continue;
            }
            elseif ( !$node->isMain() )
            {
                $node = $node->object()->mainNode();
            }

            if ( $node->classIdentifier() === 'article' )
            {
                $publisherPath = PublisherFolderTool::getPublisherFolderPathFromArticleNode($node);
            }
            elseif ( $node->classIdentifier() === 'publisher_folder' )
            {
                $publisherPath = PublisherFolderTool::getPublisherFolderPath( $node );
            }
            else
            {
                continue;
            }
            $clusters = PublisherFolderTool::getClustersFromPath($publisherPath);

            if(count($clusters) >5)
            {
                $clusters = $clustersClear;
            }
            foreach ( $clusters as $clusterIdentifier )
            {
                $row = sprintf( "('%s', %d, '%s', %d )", VarnishControl::PENDING_VARNISH_LABEL, $timeStamp, $clusterIdentifier, $nodeId );
                if( !in_array( $row, $values ) )
                {
                    $values[] = $row;
                }
            }

            if( !empty( $values ) )
            {
                $query = "INSERT INTO ezpending_actions (action, created, param, param_int) VALUES " . implode(', ', $values);
                $db->query( $query );
            }
        }

        return array();
    }
                    }
                    else
                    {
                        if( $pdfContentObject->reverseRelatedObjectCount( false, false ) > 0 )
                        {
                            $reverseRelatedObjectlist = $pdfContentObject->reverseRelatedObjectList( false, false );
                            $articleContentObject     = $reverseRelatedObjectlist[0];
                        }
                    }

                    if( $articleContentObject instanceof eZContentObject )
                    {
                        /* @type $articleNode eZContentObjectTreeNode */
                        $articleNode = $articleContentObject->mainNode();
                        $application = NodeTool::getApplicationFromNode($articleNode);
                        $publisherFolderInfo = PublisherFolderTool::getPublisherFolderPathFromArticleNode($articleNode, true);
                        $publisherFolderPath = $publisherFolderInfo['path'];
                        $publisherFolderTranslation = PublisherFolderTool::getPublisherFolderTranslationFromPublisherFolder($publisherFolderInfo['pfid']);
                        
                        if( isset($publisherFolderTranslation['name']) ) {
                             $publisherFolderTranslatioName = $publisherFolderTranslation['name'];
                        } 
                        
                        $articleObjecId = $articleContentObject->ID;
                    }
                }
                //Insert into tracking table
                MMTrackingPdf::addTrack($clusterIdentifier, $userId, $application, $pdfId, $articleObjecId, $date, $publisherFolderPath, $publisherFolderTranslatioName);
            }
        }
        //No tracking