/** * 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(); }