Skip to content

Commit

Permalink
- Implemented enhancement #014831: hide cronjob is totally useless fo…
Browse files Browse the repository at this point in the history
…r big sites

  Slightly modified version of Georg Franz's contribution.
  • Loading branch information
Bertrand Dunogier committed Aug 4, 2010
1 parent 62f95e7 commit 24210d2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 65 deletions.
122 changes: 57 additions & 65 deletions cronjobs/hide.php
@@ -1,93 +1,85 @@
<?php
//
// Created on: <21-Jan-05 16:00:52 kk>
//
// ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
// SOFTWARE NAME: eZ Publish
// SOFTWARE RELEASE: 4.1.x
// COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2.0 of the GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of version 2.0 of the GNU General
// Public License along with this program; if not, write to the Free
// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
//
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
//

/*! \file
*/
/**
* File containing the hide.php cronjob.
*
* @copyright Copyright (C) 1999-2010 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/gnu_gpl GNU GPL v2
* @version //autogentag//
* @package kernel
*/

$ini = eZINI::instance( 'content.ini' );
$rootNodeIDList = $ini->variable( 'HideSettings','RootNodeList' );
$hideAttributeArray = $ini->variable( 'HideSettings', 'HideDateAttributeList' );
$hideClasses = array_keys( $hideAttributeArray );

$currrentDate = time();

$offset = 0;
$limit = 20;
$limit = 50;

$hiddenNodesParams = array(
'LoadDataMap' => false,
'Limit' => $limit,
'Offset' => $offset,
'SortBy' => array( array( 'published', true ) ) );

$newMemoryUsage = $oldMemoryUsage = 0;
foreach( $rootNodeIDList as $nodeID )
{
$rootNode = eZContentObjectTreeNode::fetch( $nodeID );

while( true )
if ( !$isQuiet )
{
$nodeArray = $rootNode->subTree( array( 'ClassFilterType' => 'include',
'ClassFilterArray' => $hideClasses,
'Offset' => $offset,
'Limit' => $limit ) );
if ( !$nodeArray ||
count( $nodeArray ) == 0 )
{
break;
}

$offset += $limit;
$cli->output( 'Hiding content of node "' . $rootNode->attribute( 'name' ) . '" (' . $nodeID . ')' );
$cli->output();
}
foreach ( $hideAttributeArray as $hideClass => $attributeIdentifier )
{
$offset = 0;
$counter = 0;
$countParams = array( 'ClassFilterType' => 'include',
'ClassFilterArray' => array( $hideClass ),
'Limitation' => array(),
'IgnoreVisibility' => false,
'AttributeFilter' => array( 'and',
array( "{$hideClass}/{$attributeIdentifier}", '<=', $currrentDate ),
array( "{$hideClass}/$attributeIdentifier", '>', 0 ) ) );

foreach ( $nodeArray as $node )
$nodeArrayCount = $rootNode->subTreeCount( $countParams );
if ( $nodeArrayCount > 0 )
{
$dataMap = $node->attribute( 'data_map' );

$dateAttributeName = $hideAttributeArray[$node->attribute( 'class_identifier' )];

if ( !$dateAttributeName )
if ( !$isQuiet )
{
continue;
$cli->output( "Hiding {$nodeArrayCount} node(s) of class {$hideClass}." );
}

$dateAttribute = $dataMap[$dateAttributeName];

if ( $dateAttribute === null || !$dateAttribute->hasContent() )
do
{
continue;
}
$nodeArray = $rootNode->subTree( $hiddenNodesParams );

This comment has been minimized.

Copy link
@glye

glye Jan 10, 2011

Member

BD: This fetch ignores the class/attribute filtering, and fetches all nodes of the subtree. If you run this on node 2 it hides your entire content tree.


$date = $dateAttribute->content();
$retractDate = $date->attribute( 'timestamp' );
if ( $retractDate > 0 && $retractDate < $currrentDate && !$node->attribute( 'is_hidden' ) )
{
eZContentObjectTreeNode::hideSubTree( $node );
if ( !$isQuiet )
foreach ( $nodeArray as $node )
{
$cli->output( 'Hiding node : ' . $node->attribute( 'node_id' ) );
eZContentObjectTreeNode::hideSubTree( $node );
if ( !$isQuiet )
{
$cli->output( 'Hiding node: "' . $node->attribute( 'name' ) . '" (' . $node->attribute( 'node_id' ) . ')' );
}
}
$counter += $limit;

// clear memory after every batch
eZContentObject::clearCache();
} while( is_array( $nodeArray ) and count( $nodeArray ) > 0 );

if ( !$isQuiet )
{
$cli->output();
}
}
}
if ( !$isQuiet )
{
$cli->output();
}
}


?>
?>
Expand Up @@ -5,6 +5,8 @@ Changes from 4.4.0alpha5 to 4.4.0alpha6
- Implemented enhancement #017012: Add session handler & support for anonymous sessions
- Implemented enhancement #016147: prevent makestaticcache script adding new session in ezsession table for each node it caches
- Implemented enhancement #016704: Cookie Domain should be a configuration option
- Implemented enhancement #014831: hide cronjob is totally useless for big sites
Slightly modified version of Georg Franz's contribution.

*Design:

Expand Down

0 comments on commit 24210d2

Please sign in to comment.