在ezpublish中以编程方式删除图像

时间:2015-06-13 17:44:58

标签: php ezpublish

我在ezPublish中有一个具有图像属性的对象。 这个属性有一个图像作为值,我想在PHP中以编程方式删除它。 (图像值而不是属性本身)

任何想法怎么做?

2 个答案:

答案 0 :(得分:2)

对于2013年10月15日之前的eZ Publish(Legacy)版本或git tag,' v2014.03.1'包括eZ Publish 4.7' deleteStoredObjectAttribute'方法 - 需要 - 在以下提交之前,在eZ Publish Legacy的版本中传递非null的第二个参数值:

请参阅:https://github.com/ezsystems/ezpublish-legacy/commit/61aaa002c00ccfb86b3e02856b319f54b3405ef8

这包括eZ Publish 4.7以及问题作者的具体用例。这就是为什么这个答案比其他答案更准确。

如果没有第二个非null参数,别名图像文件将从文件系统中删除但是......图像别名信息(别名引用,元数据等)仍然存在内容对象属性内容(数据库存储) XML)。

如果没有第二个非参数,图像将显示为仍然部分存在于内容对象中,但图像预览(IE:图像路径的使用,系统的元数据)将显示损坏的图像,从而表示原始内容对象属性内容的损坏/不完整副本。

为了获得最大的向后兼容性,最好始终传递非空的第二个参数,因为超过10/15/2013的eZ Publish Legacy版本甚至不会以任何方式使用第二个参数。

以下是删除内容对象图像属性内容所需的源代码的完整示例(并从磁盘中删除相关的元数据和图像文件),这是几乎任何版本的eZ Publish Legacy的最佳方式。< / p>

// The following two variables are filled with dummy values.
// You will need to change the contents of these variables to match
// your actual use case identifiers (Content Object ID / Class Attribute Identifier)
$objectID = 42;
$objectImageAttributeIdentifier = 'profile_image';

$object = eZContentObject::fetch( $objectID );

$objectID = $object->attribute( 'id' );
$objectCurrentVersion = $object->attribute( 'current_version' );
$objectDataMap = $object->attribute( 'data_map' );

if ( isset( $objectDataMap[ $objectImageAttributeIdentifier ] ) )
{
    $objectImageAttribute = $objectDataMap[ $objectImageAttributeIdentifier ];

    if ( $objectImageAttribute->attribute( 'has_content' ) )
    {
        $objectImageDataType = $objectImageAttribute->dataType();
        $objectImageDataType->deleteStoredObjectAttribute( $objectImageAttribute, $objectCurrentVersion );

        eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
    }
}

答案 1 :(得分:1)

根据eZImageType::customObjectAttributeHTTPAction(),您应该使用eZImageType::deleteStoredObjectAttribute()

该方法的实现显示了它是如何在内部完成的。该方法不会删除属性本身,只删除外部数据(图像,别名,将xml设置为空)。