/**
  * Setter
  * Sets value to an attribute for the content object.
  * All "classic" attributes can be used (See {@link eZContentObject::definition()}).
  * If attribute doesn't exist, will throw an exception
  * @param $name Attribute name
  * @param $value Attribute value
  * @throws ezcBasePropertyNotFoundException
  * @return void
  */
 public function __set($name, $value)
 {
     if (!$this->contentObject->hasAttribute($name)) {
         throw new ezcBasePropertyNotFoundException($name);
     }
     $this->contentObject->setAttribute($name, $value);
 }
 /**
  * Updates an existing content object.
  *
  * This function works like createAndPublishObject
  *
  * Here is an example
  * <code>
  *
  * <?php
  * $contentObjectID = 1;
  * $contentObject = eZContentObject::fetch( $contentObjectID );
  *
  * if( $contentObject instanceof eZContentObject )
  * {
  *     $xmlDeclaration = '<?xml version="1.0" encoding="utf-8"?>
  *                         <section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
  *                                  xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
  *                                  xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">';
  *
  *     $now = $now = date( 'Y/m/d H:i:s', time() );
  *     $xmlDeclaration = '<?xml version="1.0" encoding="utf-8"?>
  *                     <section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
  *                                 xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
  *                                 xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">';
  *
  *     $attributeList = array( 'name'              => 'Name ' . $now,
  *                             'short_name'        => 'Short name ' . $now,
  *                             'short_description' => $xmlDeclaration . '<paragraph>Short description '. $now . '</paragraph></section>',
  *                             'description'       => $xmlDeclaration . '<paragraph>Description '. $now . '</paragraph></section>',
  *                             'show_children'     => false);
  *
  *     $params = array();
  *     $params['attributes'] = $attributeList;
  *     // $params['remote_id'] = $now;
  *     // $params['section_id'] = 3;
  *     // $params['language']  = 'ger-DE';
  *
  *     $result = eZContentFunctions::updateAndPublishObject( $contentObject, $params );
  *
  *     if( $result )
  *         print( 'Update OK' );
  *     else
  *         print( 'Failed' );
  * }
  * ?>
  * </code>
  * @param eZContentObject an eZContentObject object
  * @param array an array with the attributes to update
  * @static
  * @return bool true if the object has been successfully updated, false otherwise
  */
 public static function updateAndPublishObject(eZContentObject $object, array $params)
 {
     if (!array_key_exists('attributes', $params) and !is_array($params['attributes']) and count($params['attributes']) > 0) {
         eZDebug::writeError('No attributes specified for object' . $object->attribute('id'), __METHOD__);
         return false;
     }
     $storageDir = '';
     $languageCode = false;
     $mustStore = false;
     if (array_key_exists('remote_id', $params)) {
         $object->setAttribute('remote_id', $params['remote_id']);
         $mustStore = true;
     }
     if (array_key_exists('section_id', $params)) {
         $object->setAttribute('section_id', $params['section_id']);
         $mustStore = true;
     }
     if ($mustStore) {
         $object->store();
     }
     if (array_key_exists('storage_dir', $params)) {
         $storageDir = $params['storage_dir'];
     }
     if (array_key_exists('language', $params) and $params['language'] != false) {
         $languageCode = $params['language'];
     } else {
         $initialLanguageID = $object->attribute('initial_language_id');
         $language = eZContentLanguage::fetch($initialLanguageID);
         $languageCode = $language->attribute('locale');
     }
     $db = eZDB::instance();
     $db->begin();
     $newVersion = $object->createNewVersion(false, true, $languageCode);
     if (!$newVersion instanceof eZContentObjectVersion) {
         eZDebug::writeError('Unable to create a new version for object ' . $object->attribute('id'), __METHOD__);
         $db->rollback();
         return false;
     }
     $newVersion->setAttribute('modified', time());
     $newVersion->store();
     $attributeList = $newVersion->attribute('contentobject_attributes');
     $attributesData = $params['attributes'];
     foreach ($attributeList as $attribute) {
         $attributeIdentifier = $attribute->attribute('contentclass_attribute_identifier');
         if (array_key_exists($attributeIdentifier, $attributesData)) {
             $dataString = $attributesData[$attributeIdentifier];
             switch ($datatypeString = $attribute->attribute('data_type_string')) {
                 case 'ezimage':
                 case 'ezbinaryfile':
                 case 'ezmedia':
                     $dataString = $storageDir . $dataString;
                     break;
                 default:
             }
             $attribute->fromString($dataString);
             $attribute->store();
         }
     }
     $db->commit();
     $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $newVersion->attribute('contentobject_id'), 'version' => $newVersion->attribute('version')));
     if ($operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE) {
         return true;
     }
     return false;
 }