public function testUpdateAndPublishObject()
 {
     // create content object first
     $object = new ezpObject("folder", 2);
     $object->title = __FUNCTION__ . '::' . __LINE__ . '::' . time();
     $object->publish();
     $contentObjectID = $object->attribute('id');
     if ($object instanceof eZContentObject) {
         $now = date('Y/m/d H:i:s', time());
         $sectionID = 3;
         $remoteID = md5($now);
         $attributeList = array('name' => 'name ' . $now, 'short_name' => 'short_name ' . $now, 'short_description' => 'short_description' . $now, 'description' => 'description' . $now, 'show_children' => false);
         $params = array();
         $params['attributes'] = $attributeList;
         $params['remote_id'] = $remoteID;
         $params['section_id'] = $sectionID;
         $result = eZContentFunctions::updateAndPublishObject($object, $params);
         $this->assertTrue($result);
         $object = eZContentObject::fetch($contentObjectID);
         $this->assertEquals($object->attribute('section_id'), $sectionID);
         $this->assertEquals($object->attribute('remote_id'), $remoteID);
         $dataMap = $object->dataMap();
         $this->assertEquals($attributeList['name'], $dataMap['name']->content());
         $this->assertEquals($attributeList['short_name'], $dataMap['short_name']->content());
         $this->assertEquals($attributeList['short_description'], $dataMap['short_description']->content());
         $this->assertEquals($attributeList['description'], $dataMap['description']->content());
         $this->assertEquals($attributeList['show_children'], (bool) $dataMap['show_children']->content());
     }
 }
 private function updateContentObject(eZContentObject $eZContentObject)
 {
     $mainNodeID = $eZContentObject->mainNodeID();
     $parentNodeID = eZContentObjectTreeNode::getParentNodeId($mainNodeID);
     $classIdentifier = $eZContentObject->ClassIdentifier;
     $remoteID = $eZContentObject->RemoteID;
     if (!eZContentClass::fetchByIdentifier($classIdentifier)) {
         throw new Exception("La classe" . $classIdentifier . "non esiste in questa installazione");
     }
     $params = array();
     $params['class_identifier'] = $classIdentifier;
     $params['remote_id'] = $remoteID;
     $params['parent_node_id'] = $parentNodeID;
     $params['attributes'] = $this->getAttributesStringArray($eZContentObject);
     $result = eZContentFunctions::updateAndPublishObject($eZContentObject, $params);
     return $result;
 }
 public static function attribute_edit()
 {
     $http = eZHTTPTool::instance();
     $objectId = $http->postVariable('objectId', 0);
     $attributeId = $http->postVariable('attributeId', 0);
     $version = $http->postVariable('version', 0);
     $content = $http->postVariable('content', '');
     $object = eZContentObject::fetch($objectId);
     if ($object instanceof eZContentObject && $object->attribute('can_edit')) {
         $attribute = eZContentObjectAttribute::fetch($attributeId, $version);
         if ($attribute instanceof eZContentObjectAttribute && $attribute->attribute('contentobject_id') == $objectId) {
             $params['attributes'] = array($attribute->attribute('contentclass_attribute_identifier') => $content);
             eZContentFunctions::updateAndPublishObject($object, $params);
             $object = eZContentObject::fetch($objectId);
             return $object->attribute('name');
         }
     }
     throw new Exception("Error");
 }
/**
 * Creates a country object and returns it. 
 * Uses both eZContentFunctions::createAndPublishObject and eZContentFunctions::updateAndPublishObject 
 * because eZContentFunctions::createAndPublishObject doesn't take language code into consideration in this version of eZ Publish
 * @param string $countryCode
 * @param string $clusterIdentifier
 * @param string $language
 * @return eZContentObject
 */
function createCountry( $countryCode, $clusterIdentifier, $language )
{
    $countryCode = strtoupper( $countryCode );
    $countriesNode = eZContentObjectTreeNode::fetchByURLPath( 'countries' );
    $options = array(
        'parent_node_id' => $countriesNode->NodeID,
        'class_identifier' => 'country',
        'remote_id' => 'country_' . $clusterIdentifier,
        'attributes' => array(
            'name' => $countryCode,
        )
    );
    $country = eZContentFunctions::createAndPublishObject( $options );
    eZContentFunctions::updateAndPublishObject( $country, array(
        'language' => $language
    ) );

    return $country;
}
    }
    return $newValue;
}
if ($object instanceof eZContentObject) {
    if ($object->attribute('can_edit')) {
        /** @var eZContentObjectAttribute[] $attributes */
        $attributes = $object->fetchAttributesByIdentifier(array($attributeIdentifier));
        if (is_array($attributes) && count($attributes) > 0) {
            $attribute = array_shift($attributes);
            if ($attribute instanceof eZContentObjectAttribute) {
                $currentValue = $attribute->toString();
                $newValue = normalizeValue($newValue, $currentValue, $attribute);
                if ($newValue != $currentValue) {
                    if ($createNewVersion) {
                        $params = array('attributes' => array($attributeIdentifier => $newValue));
                        $result = eZContentFunctions::updateAndPublishObject($object, $params);
                        if (!$result) {
                            $data['status'] = 'error';
                            $data['message'] = "Error creating new object version";
                            $data['header'] = "HTTP/1.1 400 Bad Request";
                        } else {
                            $data['status'] = 'success';
                        }
                    } else {
                        $attribute->fromString($newValue);
                        $attribute->store();
                        eZSearch::addObject($object);
                        eZContentCacheManager::clearObjectViewCacheIfNeeded($object->attribute('id'));
                        $data['status'] = 'success';
                    }
                }
示例#6
0
            } else {
                // We are comparing the content of rest attributes
                if ($storedContent != $value) {
                    $isUpdateNeeded = true;
                    break;
                }
            }
        }
    }
    if ($isUpdateNeeded) {
        // User should be logged in before update his profile
        $user = eZUser::fetch($object->attribute('id'));
        if ($user instanceof eZUser) {
            $user->loginCurrent();
        }
        eZContentFunctions::updateAndPublishObject($object, array('attributes' => $attributes));
    }
}
// Removing social media avatar (it was stored locally)
if (isset($attributes['image'])) {
    unlink($attributes['image']);
}
// Logging in into eZ Publish
if ($object instanceof eZContentObject) {
    $user = eZUser::fetch($object->attribute('id'));
    if ($user instanceof eZUser) {
        $user->loginCurrent();
        // We can not use state for FB, because it uses it to defense against CSRF attacks
        if ($http->hasGetVariable('login_redirect_url')) {
            $redirectURI = $http->getVariable('login_redirect_url');
        } elseif ($handler instanceof nxcSocialNetworksLoginHandlerFacebook === false && $http->hasGetVariable('state')) {