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());
     }
 }
    public function setUp()
    {
        parent::setUp();

        $this->userLogin = uniqid( '', true );
        $this->userEmail = "{$this->userLogin}@ez.no";

        $ini = eZINI::instance();
        $params = array(
            'creator_id' => 14,
            'class_identifier' => 'user',
            'parent_node_id' => $ini->variable( 'UserSettings', 'DefaultUserPlacement' ),
            'attributes' => array(
                'first_name' => 'foo',
                'last_name' => 'bar' ),
        );

        $contentObject = eZContentFunctions::createAndPublishObject( $params );

        if( !$contentObject instanceof eZContentObject )
        {
            die( 'Impossible to create user object' );
        }

        $this->userObject = $contentObject;
    }
 function createSubscriptionUser($attributes)
 {
     $param = array('parent_node_id' => JAJSubscriptionUser::subscriptionUsersNodeID(), 'class_identifier' => 'subscription_user', 'creator_id' => ezUser::currentUserID(), 'attributes' => array('status' => 'Pending'));
     $param['attributes'] = array_merge($param['attributes'], $attributes);
     $object = eZContentFunctions::createAndPublishObject($param);
     $object->expireAllViewCache();
     return $object;
 }
 /**
  * Save article draft for later approval
  */
 public function save()
 {
     $user = eZUser::fetchByName('admin');
     $params = array('class_identifier' => 'article', 'creator_id' => $user->attribute('contentobject_id'), 'parent_node_id' => $this->location, 'name' => $this->header, 'attributes' => array('title' => $this->header, 'intro' => $this->xmlConvert($this->ingress), 'body' => $this->xmlConvert($this->text)));
     // Manipulate version (setting state to draft)
     $contentObject = eZContentFunctions::createAndPublishObject($params);
     $version = $contentObject->version(1);
     $version->setAttribute('modified', eZDateTime::currentTimeStamp());
     $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
     $version->store();
 }
 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");
 }
    function createContentObject( $params )
    {
        $objectID = false;

        $classIdentifier = $params['class_identifier'];
        $location = $params['location'];
        $attributesData = $params['attributes'];

        $parentNode = $this->nodeByUrl( $params );
        if( is_object( $parentNode ) )
        {
            $parentNodeID = $parentNode->attribute( 'node_id' );
            $object = eZContentFunctions::createAndPublishObject( array( 'parent_node_id' => $parentNodeID,
                                                                         'class_identifier' => $classIdentifier,
                                                                         'attributes' => $attributesData ) );

            if( is_object( $object ) )
            {
                $objectID = $object->attribute( 'id' );
            }
        }

        return $objectID;
    }
/**
 * Creates and returns pages folder for given country
 * @param eZContentObject $countryNode
 * @param string $clusterIdentifier
 * @return eZContentObject
 */
function createPagesFolder( $countryNode, $clusterIdentifier )
{
    $parentNodeId = $countryNode->MainNodeID();
    $options = array(
        'parent_node_id' => $parentNodeId,
        'remote_id' => 'application_folder-' . $clusterIdentifier . '-page',
        'class_identifier' => 'folder',
        'attributes' => array(
            'name' => 'Pages'
        ),
    );
    $pagesFolder = eZContentFunctions::createAndPublishObject( $options );
    return $pagesFolder;
}
    }
    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';
                    }
                }
 /**
  * @param int $remoteNodeID
  * @param int $localParentNodeID
  *
  * @return eZContentObject
  * @throws Exception
  */
 public function import($remoteNodeID, $localParentNodeID)
 {
     if (!class_exists('OCOpenDataApiNode')) {
         throw new Exception("Libreria OCOpenDataApiNode non trovata");
     }
     $apiNodeUrl = rtrim($this->attributes['definition']['Url'], '/') . '/api/opendata/v1/content/node/' . $remoteNodeID;
     $remoteApiNode = OCOpenDataApiNode::fromLink($apiNodeUrl);
     if (!$remoteApiNode instanceof OCOpenDataApiNode) {
         throw new Exception("Url remoto \"{$apiNodeUrl}\" non raggiungibile");
     }
     $attributeList = array();
     foreach ($this->remoteClassAttributes as $identifier) {
         if (isset($remoteApiNode->fields[$identifier])) {
             $fieldArray = $remoteApiNode->fields[$identifier];
             $localeIdentifier = isset($this->mapAttributes[$identifier]) ? $this->mapAttributes[$identifier] : false;
             if ($localeIdentifier) {
                 if (strpos($localeIdentifier, '::') === 0) {
                     $localeIdentifier = str_replace('::', '', $localeIdentifier);
                     $attributeList[$localeIdentifier] = $this->importAttribute($identifier, $localeIdentifier, $fieldArray);
                 } else {
                     switch ($fieldArray['type']) {
                         case 'ezxmltext':
                             $attributeList[$localeIdentifier] = SQLIContentUtils::getRichContent($fieldArray['value']);
                             break;
                         case 'ezbinaryfile':
                         case 'ezimage':
                             $attributeList[$localeIdentifier] = !empty($fieldArray['value']) ? SQLIContentUtils::getRemoteFile($fieldArray['value']) : '';
                             break;
                         default:
                             $attributeList[$localeIdentifier] = $fieldArray['string_value'];
                             break;
                     }
                 }
             }
         }
     }
     $params = array();
     $params['class_identifier'] = $this->mapClassIdentifier;
     $params['remote_id'] = static::REMOTE_PREFIX . $remoteApiNode->metadata['objectRemoteId'];
     $params['parent_node_id'] = $localParentNodeID;
     $params['attributes'] = $attributeList;
     $newObject = eZContentFunctions::createAndPublishObject($params);
     if (!$newObject instanceof eZContentObject) {
         throw new Exception("Fallita la creazione dell'oggetto da nodo remoto");
     }
     return $newObject;
 }
/**
 * create HTML eZ Publish object
 * @param eZContentObjectTreeNode $parentNode
 * @param SimpleXMLElement $_item
 */
function createHTMLObject($parentNode, $_item)
{
    try
    {
        //get actual user
        $user = eZUser::currentUser();

        //object parameters
        $params                      = array();
        $params ['class_identifier'] = 'html';
        $params['creator_id']        = $user->attribute('contentobject_id');
        $params['parent_node_id']    = $parentNode->attribute('node_id');
        $params['section_id']        = $parentNode->object()->attribute('section_id');

        //set template attributes
        include_once('kernel/common/template.php');
        $htmlTpl = eZTemplate::factory();
        $htmlTpl->setVariable('title', $_item->title);
        $htmlTpl->setVariable('link', '/congressos-e-eventos?deeplink=' . urlencode($_item->link));
        $htmlTpl->setVariable('description', $_item->description);
        $htmlTpl->setVariable('category', $_item->category);
        $text = $htmlTpl->fetch('design:html/cronview.tpl');

        //attributes to insert
        $attributesData          = array();
        $attributesData['title'] = $_item->title;
        $attributesData['text']  = $text;

        $params['attributes'] = $attributesData;

        //object creation
        eZContentFunctions::createAndPublishObject($params);
    }
    catch (Exception $e)
    {
        $cli = eZCLI::instance();
        $cli->output($e->getMessage());
    }
}
            } 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')) {
                }
                if ($userStatus != 'Approved') {
                    $userDataMap['status']->fromString('Approved');
                    $userDataMap['status']->store();
                    $modified = true;
                }
                if ($modified) {
                    $warnings[] = "Row " . ($index + 1) . " subscriber found and updated." . " Email: '" . htmlspecialchars($row[1]) . "'";
                    eZContentObjectTreeNode::clearViewCacheForSubtree($user);
                } else {
                    $warnings[] = "Row " . ($index + 1) . " skipped, subscriber exists." . " Email: '" . htmlspecialchars($row[1]) . "'";
                }
                continue;
            }
            $param_creation['attributes'] = array('name' => $row[0], 'email' => $row[1], 'subscriptions' => $subscriptions, 'status' => 'Approved');
            $object = eZContentFunctions::createAndPublishObject($param_creation);
            if ($object == false) {
                $warnings[] = "Row " . ($index + 1) . " skipped, failed to create subscriber with email: '" . htmlspecialchars($row[1]) . "'";
            } else {
                $warnings[] = "Row " . ($index + 1) . " added subscriber with" . " email: '" . htmlspecialchars($row[1]) . "'";
            }
        }
        if ($http->hasSessionVariable('CSVData')) {
            $http->removeSessionVariable('CSVData');
        }
        $data = array();
    }
} while (false);
$tpl =& templateInit();
//$tpl->setVariable( 'subscriptionListNode', $subscriptionListNode );
$tpl->setVariable('subscription_lists_node', $subscriptionListsNode);