Skip to content

Commit

Permalink
Merge pull request ezsystems#481 from ezsystems/ezp-19650_trashpurge_…
Browse files Browse the repository at this point in the history
…memory_use

Fix EZP-19650: move to trash and trashpurge.php can hit the memory limit
  • Loading branch information
yannickroger committed Apr 10, 2013
2 parents 46bdd1d + 2d2f287 commit 390685b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
40 changes: 27 additions & 13 deletions kernel/classes/ezcontentobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1615,14 +1615,22 @@ function purge()

$db->begin();

$contentobjectAttributes = $this->allContentObjectAttributes( $delID );

foreach ( $contentobjectAttributes as $contentobjectAttribute )
{
$dataType = $contentobjectAttribute->dataType();
if ( !$dataType )
continue;
$dataType->deleteStoredObjectAttribute( $contentobjectAttribute );
$attrOffset = 0;
$attrLimit = 20;
while (
$contentobjectAttributes = $this->allContentObjectAttributes(
$delID, true, array( 'limit' => $attrLimit, 'offset' => $attrOffset )
)
)
{
foreach ( $contentobjectAttributes as $contentobjectAttribute )
{
$dataType = $contentobjectAttribute->dataType();
if ( !$dataType )
continue;
$dataType->deleteStoredObjectAttribute( $contentobjectAttribute );
}
$attrOffset += $attrLimit;
}

eZInformationCollection::removeContentObject( $delID );
Expand Down Expand Up @@ -1872,16 +1880,22 @@ static function cleanupAllInternalDrafts( $userID = false, $timeDuration = 86400
}
}

/*
Fetch all attributes of all versions belongs to a contentObject.
*/
function allContentObjectAttributes( $contentObjectID, $asObject = true )
/**
* Fetches all attributes from any versions of the content object
*
* @param int $contentObjectID
* @param bool $asObject
* @param array|null $limit the limit array passed to
* eZPersistentObject::fetchObjectList
* @return eZContentObjectAttribute[]|array|null
*/
function allContentObjectAttributes( $contentObjectID, $asObject = true, $limit = null )
{
return eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
null,
array("contentobject_id" => $contentObjectID ),
null,
null,
$limit,
$asObject );
}

Expand Down
22 changes: 16 additions & 6 deletions kernel/classes/ezcontentobjecttrashnode.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,23 @@ function storeToTrash()
$db->begin();

$contentObject = $this->attribute( 'object' );
$contentobjectAttributes = $contentObject->allContentObjectAttributes( $contentObject->attribute( 'id' ) );
foreach ( $contentobjectAttributes as $contentobjectAttribute )
$offset = 0;
$limit = 20;
while (
$contentobjectAttributes = $contentObject->allContentObjectAttributes(
$contentObject->attribute( 'id' ), true,
array( 'limit' => $limit, 'offset' => $offset )
)
)
{
$dataType = $contentobjectAttribute->dataType();
if ( !$dataType )
continue;
$dataType->trashStoredObjectAttribute( $contentobjectAttribute );
foreach ( $contentobjectAttributes as $contentobjectAttribute )
{
$dataType = $contentobjectAttribute->dataType();
if ( !$dataType )
continue;
$dataType->trashStoredObjectAttribute( $contentobjectAttribute );
}
$offset += $limit;
}

$db->commit();
Expand Down

0 comments on commit 390685b

Please sign in to comment.