/** * Regression test for issue #15263 * Content object name/url of imported content classes aren't generated correctly * * @url http://issues.ez.no/15263 * * @outline * 1) Expire and force generation of class attribute cache * 2) Load a test package * 3) Install the package * 4) Publish an object of the imported class * 5) The object name / url alias shouldn't be the expected one **/ public function testIssue15263() { $adminUser = eZUser::fetchByName('admin'); $previousUser = eZUser::currentUser(); eZUser::setCurrentlyLoggedInUser($adminUser, $adminUser->attribute('contentobject_id')); // 1) Expire and force generation of class attribute cache $handler = eZExpiryHandler::instance(); $handler->setTimestamp('class-identifier-cache', time() - 1); $handler->store(); eZContentClassAttribute::classAttributeIdentifierByID(1); // 1) Load a test package $packageName = 'ezpackage_regression_testIssue15223.ezpkg'; $packageFilename = dirname(__FILE__) . DIRECTORY_SEPARATOR . $packageName; $packageImportTried = false; while (!$packageImportTried) { $package = eZPackage::import($packageFilename, $packageName); if (!$package instanceof eZPackage) { if ($package === eZPackage::STATUS_ALREADY_EXISTS) { $packageToRemove = eZPackage::fetch($packageName); $packageToRemove->remove(); } else { self::fail("An error occured loading the package '{$packageFilename}'"); } } $packageImportTried = true; } // 2) Install the package $installParameters = array('site_access_map' => array('*' => false), 'top_nodes_map' => array('*' => 2), 'design_map' => array('*' => false), 'restore_dates' => true, 'user_id' => $adminUser->attribute('contentobject_id'), 'non-interactive' => true, 'language_map' => $package->defaultLanguageMap()); $result = $package->install($installParameters); // 3) Publish an object of the imported class $object = new ezpObject('test_issue_15523', 2, $adminUser->attribute('contentobject_id'), 1); $object->myname = __METHOD__; $object->myothername = __METHOD__; $publishedObjectID = $object->publish(); unset($object); // 4) Test data from the publish object $publishedNodeArray = eZContentObjectTreeNode::fetchByContentObjectID($publishedObjectID); if (count($publishedNodeArray) != 1) { $this->fail("An error occured fetching node for object #{$publishedObjectID}"); } $publishedNode = $publishedNodeArray[0]; if (!$publishedNode instanceof eZContentObjectTreeNode) { $this->fail("An error occured fetching node for object #{$publishedObjectID}"); } else { $this->assertEquals("eZPackageRegression::testIssue15263", $publishedNode->attribute('name')); $this->assertEquals("eZPackageRegression-testIssue15263", $publishedNode->attribute('url_alias')); } // Remove the installed package & restore the logged in user $package->remove(); eZUser::setCurrentlyLoggedInUser($previousUser, $previousUser->attribute('contentobject_id')); }
/** * get the objectId of the parent nl list node * to fetch subscriptions */ function getParentListContentObjectIdByListId($virtualListContentObjectId) { $listNode = eZContentObjectTreeNode::fetchByContentObjectID($virtualListContentObjectId, true); if (isset($listNode[0]) && is_object($listNode[0])) { $parentListNode = $listNode[0]->attribute('parent'); if (is_object($parentListNode) && $parentListNode->attribute('class_identifier') == 'cjw_newsletter_list') { $parentListContentObjectId = $parentListNode->attribute('contentobject_id'); return $parentListContentObjectId; } else { return 0; } } else { return 0; } }
function discountPercent() { $discountPercent = 0; $user = eZUser::currentUser(); $userID = $user->attribute('contentobject_id'); $nodes = eZContentObjectTreeNode::fetchByContentObjectID($userID); $idArray = array(); $idArray[] = $userID; foreach ($nodes as $node) { $parentNodeID = $node->attribute('parent_node_id'); $idArray[] = $parentNodeID; } $rules = eZUserDiscountRule::fetchByUserIDArray($idArray); foreach ($rules as $rule) { $percent = $rule->attribute('discount_percent'); if ($discountPercent < $percent) { $discountPercent = $percent; } } return $discountPercent; }
/** * Hides an object specified by $objectId. * * @param int $objectId */ public function hideObject($objectId) { $node = eZContentObjectTreeNode::fetchByContentObjectID($objectId); eZContentObjectTreeNode::hideSubTree($node[0]); }
function createContentObject( $objectInformation ) { $db = eZDB::instance(); $contentObjectVersion = false; if ( $objectInformation['ownerID'] ) { $userID = $objectInformation['ownerID']; } else { $user = eZUser::currentUser(); $userID = $user->attribute( 'contentobject_id' ); } if ( $objectInformation['remoteID'] ) { $contentObject = eZContentObject::fetchByRemoteId( $objectInformation['remoteID'] ); if ( $contentObject ) { $this->writeMessage( "\t[".$objectInformation['remoteID']."] Object exists: " . $contentObject->attribute("name") . ". Creating new version.", 'notice' ); $contentObjectVersion = $contentObject->createNewVersion(); } } elseif ( $objectInformation['objectID'] ) { $contentObject = eZContentObject::fetch( $objectInformation['objectID'] ); if ( $contentObject ) { $this->writeMessage( "\t[".$objectInformation['remoteID']."] Object exists: " . $contentObject->attribute("name") . ". Creating new version.", 'notice' ); $contentObjectVersion = $contentObject->createNewVersion(); } } if ( !$contentObjectVersion ) { if ( is_numeric( $objectInformation['classID'] ) ) { $contentClass = eZContentClass::fetch( $objectInformation['classID'] ); } elseif ( is_string( $objectInformation['classID'] ) && $objectInformation['classID'] != "" ) { $contentClass = eZContentClass::fetchByIdentifier( $objectInformation['classID'] ); } else { $this->writeMessage( "\tNo class defined. Using class article.", 'warning' ); $contentClass = eZContentClass::fetchByIdentifier( 'article' ); } if ( !$contentClass ) { $this->writeMessage( "\tCannot instantiate class '". $objectInformation['classID'] ."'." , 'error' ); return false; } $contentObject = $contentClass->instantiate( $userID ); $contentObject->setAttribute( 'remote_id', $objectInformation['remoteID'] ); if ( $contentObject ) { $contentObjectVersion = $contentObject->currentVersion(); } } if ( $contentObjectVersion ) { $db->begin(); $versionNumber = $contentObjectVersion->attribute( 'version' ); $sortField = intval( eZContentObjectTreeNode::sortFieldID( $objectInformation['sort_field'] ) ); $sortOrder = strtolower( $objectInformation['sort_order'] ) == 'desc' ? eZContentObjectTreeNode::SORT_ORDER_DESC : eZContentObjectTreeNode::SORT_ORDER_ASC; $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObject->attribute( 'id' ), 'contentobject_version' => $versionNumber, 'parent_node' => $objectInformation['parentNode'], 'is_main' => 1, 'sort_field' => $sortField, 'sort_order' => $sortOrder, ) ); $nodeAssignment->store(); $dataMap = $contentObjectVersion->dataMap(); foreach ( $objectInformation['attributes'] as $attributeName => $attributesContent ) { if ( array_key_exists( $attributeName, $dataMap ) ) { $attribute = $dataMap[$attributeName]; $classAttributeID = $attribute->attribute( 'contentclassattribute_id' ); $dataType = $attribute->attribute( 'data_type_string' ); switch ( $dataType ) { case 'ezstring': case 'eztext': case 'ezselection': case 'ezemail': { if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $attribute->setAttribute( 'data_text', $this->parseAndReplaceStringReferences( $attributesContent['content'] ) ); } else { $attribute->setAttribute( 'data_text', $attributesContent['content'] ); } } break; case 'ezboolean': case 'ezinteger': { $attribute->setAttribute( 'data_int', (int)$attributesContent['content'] ); } break; case 'ezxmltext': { if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $attributesContent['content'] = $this->parseAndReplaceStringReferences( $attributesContent['content'] ); } if ( array_key_exists( 'htmlDecode', $attributesContent ) && $attributesContent['htmlDecode'] == "true" ) { $content = html_entity_decode( $attributesContent['content'] ); } else { $content = $attributesContent['content']; } if( array_key_exists( 'fullxml', $attributesContent ) && $attributesContent['fullxml'] == "true" ) { $xml = $content; } else { $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n". '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"'."\n". ' xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"'."\n". ' xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">'."\n". ' <section>'."\n"; $xml .= ' <paragraph>' . $content . "</paragraph>\n"; $xml .= " </section>\n</section>\n"; } $attribute->setAttribute( 'data_text', $xml ); } break; case 'ezprice': case 'ezfloat': { $attribute->setAttribute( 'data_float', (float)$attributesContent['content'] ); } break; case 'ezimage': { $imagePath = $this->setting( 'data_source' ) . '/' . $attributesContent['src']; $imageName = $attributesContent['title']; $path = realpath( $imagePath ); if ( file_exists( $path ) ) { $content = $attribute->content(); $content->initializeFromFile( $path, $imageName, basename( $attributesContent['src'] ) ); $content->store( $attribute ); } else { $this->writeMessage( "\tFile " . $path . " not found.", 'warning' ); } } break; case 'ezobjectrelation': { $relationContent = trim( $attributesContent['content'] ); if ( $relationContent != '' ) { $objectID = $this->getReferenceID( $attributesContent['content'] ); if ( $objectID ) { $attribute->setAttribute( 'data_int', $objectID ); eZContentObject::fetch( $objectID )->addContentObjectRelation( $objectID, $versionNumber, $contentObject->attribute( 'id' ), $attribute->attribute( 'contentclassattribute_id' ), eZContentObject::RELATION_ATTRIBUTE ); } else { $this->writeMessage( "\tReference " . $attributesContent['content'] . " not set.", 'warning' ); } } } break; case 'ezurl': { $url = ''; $title = ''; if ( array_key_exists( 'url', $attributesContent ) ) $url = $attributesContent['url']; if ( array_key_exists( 'title', $attributesContent ) ) $title = $attributesContent['title']; if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $title = $this->parseAndReplaceStringReferences( $title ); $url = $this->parseAndReplaceStringReferences( $url ); } $attribute->setAttribute( 'data_text', $title ); $attribute->setContent( $url ); } break; case 'ezuser': { $login = ''; $email = ''; $password = ''; if ( array_key_exists( 'login', $attributesContent ) ) $login = $attributesContent['login']; if ( array_key_exists( 'email', $attributesContent ) ) $email = $attributesContent['email']; if ( array_key_exists( 'password', $attributesContent ) ) $password = $attributesContent['password']; $contentObjectID = $attribute->attribute( "contentobject_id" ); $user =& $attribute->content(); if ( $user === null ) { $user = eZUser::create( $contentObjectID ); } $ini =& eZINI::instance(); $generatePasswordIfEmpty = $ini->variable( "UserSettings", "GeneratePasswordIfEmpty" ); if ( $password == "" ) { if ( $generatePasswordIfEmpty == 'true' ) { $passwordLength = $ini->variable( "UserSettings", "GeneratePasswordLength" ); $password = $user->createPassword( $passwordLength ); } else { $password = null; } } if ( $password == "_ezpassword" ) { $password = false; $passwordConfirm = false; } $user->setInformation( $contentObjectID, $login, $email, $password, $password ); $attribute->setContent( $user ); } break; case 'ezkeyword': { $keyword = new eZKeyword(); $keyword->initializeKeyword( $attributesContent['content'] ); $attribute->setContent( $keyword ); } break; case 'ezmatrix': { if ( is_array( $attributesContent ) ) { $matrix = $attribute->attribute( 'content' ); $cells = array(); $matrix->Matrix['rows']['sequential'] = array(); $matrix->NumRows = 0; foreach( $attributesContent as $key => $value ) { $cells = array_merge( $cells, $value ); $newRow['columns'] = $value; $newRow['identifier'] = 'row_' . ( $matrix->NumRows + 1 ); $newRow['name'] = 'Row_' . ( $matrix->NumRows + 1 ); $matrix->NumRows++; $matrix->Matrix['rows']['sequential'][] = $newRow; } $matrix->Cells = $cells; $attribute->setAttribute( 'data_text', $matrix->xmlString() ); $matrix->decodeXML( $attribute->attribute( 'data_text' ) ); $attribute->setContent( $matrix ); } } break; case 'ezobjectrelationlist': { $relationContent = explode( ',', $attributesContent['content'] ); if ( count( $relationContent ) ) { $objectIDs = array(); foreach( $relationContent as $relation ) { $objectIDs[] = $this->getReferenceID( trim ( $relation ) ); } $attribute->fromString( implode( '-', $objectIDs ) ); } else { eZDebug::writeWarning( $attributesContent['content'], "No relation declared" ); } } break; case 'ezauthor': case 'ezbinaryfile': case 'ezcountry': case 'ezdate': case 'ezdatetime': case 'ezenum': case 'ezidentifier': case 'ezinisetting': case 'ezisbn': case 'ezmedia': case 'ezmultioption': case 'ezmultiprice': case 'ezoption': case 'ezpackage': case 'ezproductcategory': case 'ezrangeoption': case 'ezsubtreesubscription': case 'eztime': default: { try { $attribute->fromString($attributesContent['content']); } catch ( Exception $e ) { $this->writeMessage( "\tDatatype " . $dataType . " fromString function rejected value " . $attributesContent['content'], 'warning' ); } } break; } $attribute->store(); } } if ( isset($objectInformation['sectionID']) && $objectInformation['sectionID'] != '' && $objectInformation['sectionID'] != 0 ) { $contentObject->setAttribute( 'section_id', $objectInformation['sectionID'] ); } if ( isset($objectInformation['creatorID']) && $objectInformation['creatorID'] != '' && $objectInformation['creatorID'] != 0 ) { $contentObjectVersion->setAttribute( 'creator_id', $objectInformation['creatorID'] ); } if ( isset($objectInformation['ownerID']) && $objectInformation['ownerID'] != '' && $objectInformation['ownerID'] != 0 ) { $contentObject->setAttribute( 'owner_id', $objectInformation['ownerID'] ); } if( isset( $objectInformation['relations'] ) && is_array( $objectInformation['relations'] ) ) { foreach( $objectInformation['relations'] as $toObjectID ) { $contentObject->addContentObjectRelation( $toObjectID ); } } $contentObjectVersion->store(); $contentObject->store(); $db->commit(); eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version' => $versionNumber ) ); $newNodeArray = eZContentObjectTreeNode::fetchByContentObjectID( $contentObject->attribute( 'id' ) ); $refArray = false; if ( $newNodeArray && count($newNodeArray) >= 1 ) { $newNode = $newNodeArray[0]; if ( $newNode ) { $refArray = array( "node_id" => $newNode->attribute( 'node_id' ), "name" => $contentObjectVersion->attribute( 'name' ), "object_id" => $contentObject->attribute( 'id' ) ); if( $objectInformation['priority'] ) { $this->updateNodePriority( $refArray['node_id'], $objectInformation['priority'] ); } } } unset($contentObjectVersion); unset($contentObject); return $refArray; } return false; }
/** * @param int $languageID * @param int|bool $version */ function setAlwaysAvailableLanguageID( $languageID, $version = false ) { $db = eZDB::instance(); $db->begin(); if ( $version == false ) { $version = $this->currentVersion(); if ( $languageID ) { $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) | 1 ); } else { $this->setAttribute( 'language_mask', (int)$this->attribute( 'language_mask' ) & ~1 ); } $this->store(); } $objectID = $this->attribute( 'id' ); $versionID = $version->attribute( 'version' ); // reset 'always available' flag $sql = "UPDATE ezcontentobject_name SET language_id="; if ( $db->databaseName() == 'oracle' ) { $sql .= "bitand( language_id, -2 )"; } else { $sql .= "language_id & ~1"; } $sql .= " WHERE contentobject_id = '$objectID' AND content_version = '$versionID'"; $db->query( $sql ); if ( $languageID != false ) { $newLanguageID = $languageID | 1; $sql = "UPDATE ezcontentobject_name SET language_id='$newLanguageID' WHERE language_id='$languageID' AND contentobject_id = '$objectID' AND content_version = '$versionID'"; $db->query( $sql ); } $version->setAlwaysAvailableLanguageID( $languageID ); // Update url alias for all locations $nodeRows = eZContentObjectTreeNode::fetchByContentObjectID( $objectID, false ); $actions = array(); foreach ( $nodeRows as $nodeRow ) { $nodeID = (int)$nodeRow['node_id']; $actions[] = array( 'eznode', $nodeID ); } eZURLAliasML::setLangMaskAlwaysAvailable( $languageID, $actions, null ); $db->commit(); }
static function publishNewUserGroup($parentNodeIDs, $newGroupAttributes, $isUtf8Encoding = false) { $newNodeIDs = array(); if (!is_array($newGroupAttributes) or !isset($newGroupAttributes['name']) or empty($newGroupAttributes['name'])) { eZDebug::writeWarning('Cannot create user group with empty name.', __METHOD__); return $newNodeIDs; } if (!is_array($parentNodeIDs) or count($parentNodeIDs) < 1) { eZDebug::writeWarning('No one parent node IDs was passed for publishing new group (group name = "' . $newGroupAttributes['name'] . '")', __METHOD__); return $newNodeIDs; } $ini = eZINI::instance(); $userGroupClassID = $ini->variable("UserSettings", "UserGroupClassID"); $userCreatorID = $ini->variable("UserSettings", "UserCreatorID"); $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID"); $userGroupClass = eZContentClass::fetch($userGroupClassID); $contentObject = $userGroupClass->instantiate($userCreatorID, $defaultSectionID); $contentObject->store(); $contentObjectID = $contentObject->attribute('id'); reset($parentNodeIDs); $defaultPlacement = current($parentNodeIDs); array_shift($parentNodeIDs); $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $defaultPlacement, 'parent_remote_id' => uniqid('LDAP_'), 'is_main' => 1)); $nodeAssignment->store(); foreach ($parentNodeIDs as $parentNodeID) { $newNodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $parentNodeID, 'parent_remote_id' => uniqid('LDAP_'), 'is_main' => 0)); $newNodeAssignment->store(); } $version = $contentObject->version(1); $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $contentObjectAttributes = $version->contentObjectAttributes(); // find ant set 'name' and 'description' attributes (as standard user group class) $nameIdentifier = 'name'; $descIdentifier = 'description'; $nameContentAttribute = null; $descContentAttribute = null; foreach ($contentObjectAttributes as $attribute) { if ($attribute->attribute('contentclass_attribute_identifier') == $nameIdentifier) { $nameContentAttribute = $attribute; } else { if ($attribute->attribute('contentclass_attribute_identifier') == $descIdentifier) { $descContentAttribute = $attribute; } } } if ($nameContentAttribute) { if ($isUtf8Encoding) { $newGroupAttributes['name'] = utf8_decode($newGroupAttributes['name']); } $nameContentAttribute->setAttribute('data_text', $newGroupAttributes['name']); $nameContentAttribute->store(); } if ($descContentAttribute and isset($newGroupAttributes['description'])) { if ($isUtf8Encoding) { $newGroupAttributes['description'] = utf8_decode($newGroupAttributes['description']); } $descContentAttribute->setAttribute('data_text', $newGroupAttributes['description']); $descContentAttribute->store(); } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); $newNodes = eZContentObjectTreeNode::fetchByContentObjectID($contentObjectID, true, 1); foreach ($newNodes as $newNode) { $newNodeIDs[] = $newNode->attribute('node_id'); } return $newNodeIDs; }
/** * Returns the roles matching the given users' eZContentObject ID array * * @param array $idArray Array of eZContentObject IDs, either groups + user id or user id's only * If only user id's, then remember to set $recursive to true * @param bool $recursive * If true, roles will be looked up for all nodes of the id's and it's parents * * @return array(eZRole) */ static function fetchByUser($idArray, $recursive = false) { if (count($idArray) < 1) { return array(); } $db = eZDB::instance(); if (!$recursive) { $groupINSQL = $db->generateSQLINStatement($idArray, 'ezuser_role.contentobject_id', false, false, 'int'); $query = "SELECT DISTINCT ezrole.id,\n ezrole.name,\n ezuser_role.limit_identifier,\n ezuser_role.limit_value,\n ezuser_role.id as user_role_id\n FROM ezrole,\n ezuser_role\n WHERE {$groupINSQL} AND\n ezuser_role.role_id = ezrole.id"; } else { $userNodeIDArray = array(); foreach ($idArray as $id) { $nodeDefinition = eZContentObjectTreeNode::fetchByContentObjectID($id); foreach ($nodeDefinition as $nodeDefinitionElement) { $userNodeIDArray = array_merge($nodeDefinitionElement->attribute('path_array'), $userNodeIDArray); } } if (count($userNodeIDArray) < 1) { return array(); } $roleTreeINSQL = $db->generateSQLINStatement($userNodeIDArray, 'role_tree.node_id', false, false, 'int'); $query = "SELECT DISTINCT ezrole.id,\n ezrole.name,\n ezuser_role.limit_identifier,\n ezuser_role.limit_value,\n ezuser_role.id as user_role_id\n FROM ezrole,\n ezuser_role,\n ezcontentobject_tree role_tree\n WHERE ezuser_role.contentobject_id = role_tree.contentobject_id AND\n ezuser_role.role_id = ezrole.id AND\n {$roleTreeINSQL}"; } $roleArray = $db->arrayQuery($query); $roles = array(); foreach ($roleArray as $roleRow) { $role = new eZRole($roleRow); $roles[] = $role; } return $roles; }
function serialize( $package, $options = false, $contentNodeIDArray = false, $topNodeIDArray = false ) { $dom = new DOMDocument( '1.0', 'utf-8' ); $versionNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:version' ); $dom->appendChild( $versionNode ); $versionNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:version', $this->Version ); $versionNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:status', $this->Status ); $versionNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:created', eZDateUtils::rfc1123Date( $this->attribute( 'created' ) ) ); $versionNode->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:modified', eZDateUtils::rfc1123Date( $this->attribute( 'modified' ) ) ); $translationList = $this->translationList( false, false ); $contentObject = $this->attribute( 'contentobject' ); $db = eZDB::instance(); $db->begin(); $allowedLanguages = $options['language_array']; if ( $options['only_initial_language'] ) { $initialLanguageCode = $this->initialLanguageCode(); if ( !in_array( $initialLanguageCode, $allowedLanguages ) ) { // We can only export initial language but is not in the allowed // language list so we return false, ie. no export of this version. return false; } // Make sure only the initial language is exported $allowedLanguages = array( $initialLanguageCode ); } $exportedLanguages = array(); foreach ( $translationList as $translationItem ) { $language = $translationItem; if ( !in_array( $language, $allowedLanguages ) ) { continue; } $translationNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:object-translation' ); $translationNode->setAttribute( 'language', $language ); // serialize object name in current version-translation $objectName = $contentObject->name( $this->Version, $language ); if ( $objectName ) { $translationNode->setAttribute( 'object_name', $objectName ); } else { eZDebug::writeWarning( sprintf( "Name for object %s of version %s in translation %s not found", $contentObject->attribute( 'id' ), $this->Version, $language ) ); } $attributes = $this->contentObjectAttributes( $language ); foreach ( $attributes as $attribute ) { $serializedAttributeNode = $attribute->serialize( $package ); $importedSerializedAttributeNode = $dom->importNode( $serializedAttributeNode, true ); $translationNode->appendChild( $importedSerializedAttributeNode ); } $versionNode->appendChild( $translationNode ); $exportedLanguages[] = $language; } $nodeAssignmentListNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:node-assignment-list' ); $versionNode->appendChild( $nodeAssignmentListNode ); $contentNodeArray = eZContentObjectTreeNode::fetchByContentObjectID( $this->ContentObjectID, true, $this->Version ); foreach( $contentNodeArray as $contentNode ) { $contentNodeDOMNode = $contentNode->serialize( $options, $contentNodeIDArray, $topNodeIDArray ); if ( $contentNodeDOMNode !== false ) { $importedContentDOMNode = $dom->importNode( $contentNodeDOMNode, true ); $nodeAssignmentListNode->appendChild( $importedContentDOMNode ); } } $initialLanguage = $this->attribute( 'initial_language' ); $initialLanguageCode = $initialLanguage->attribute( 'locale' ); if ( in_array( $initialLanguageCode, $exportedLanguages ) ) { $versionNode->setAttribute( 'initial_language', $initialLanguageCode ); } if ( $options['related_objects'] === 'selected' ) { $relatedObjectArray = $contentObject->relatedContentObjectList( $this->Version, $contentObject->ID, 0, false, array( 'AllRelations' => eZContentObject::RELATION_COMMON ) ); if ( count( $relatedObjectArray ) ) { $relationListNode = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:object-relation-list' ); foreach( $relatedObjectArray as $relatedObject ) { $relatedObjectRemoteID = $relatedObject->attribute( 'remote_id' ); $relationNode = $dom->createElement( 'related-object-remote-id' ); $relationNode->appendChild( $dom->createTextNode( $relatedObjectRemoteID ) ); $relationListNode->appendChild( $relationNode ); } $versionNode->appendChild( $relationListNode ); } } $db->commit(); return $versionNode; }
{ $objects = eZContentObject::fetchSameClassList($class->ID, false, $offset, 100); foreach($objects as $row) { $ratingValues = array(); for($i=1; $i <= 10; $i++) { $ratingValues[] = sprintf("(%s, 'cluster_france', %s, %s, 1)", $row['id'], $i, mt_rand(0, 200)); } $db->arrayQuery($ratingQuery . implode(', ', $ratingValues) . ';'); $readValues = array(); $nodes = eZContentObjectTreeNode::fetchByContentObjectID($row['id'], false); foreach($nodes as $node) { if($node['node_id'] != $node['main_node_id']) { $readValues[] = sprintf("(%s, 'cluster_france', '%s', %s, 1)", $node['node_id'], date( 'Y-m-d H:i:s'), mt_rand(0, 5000)); } } $db->arrayQuery($readQuery . implode(', ', $readValues) . ';'); $progressBar->advance(); $offset += 1; $count -= 1;
function editContentObject( $objectInformation ) { $db = eZDB::instance(); $contentObjectVersion = false; $contentObject = $objectInformation['object']; if ( $objectInformation['ownerID'] ) { $userID = $objectInformation['ownerID']; } else { $userID = $contentObject->attribute( 'owner_id' ); } if ( $contentObject ) { $contentObjectVersion = $contentObject->createNewVersion(); } if ( $contentObjectVersion ) { $db->begin(); $versionNumber = $contentObjectVersion->attribute( 'version' ); $dataMap = $contentObjectVersion->dataMap(); foreach ( $objectInformation['attributes'] as $attributeName => $attributesContent ) { if ( array_key_exists( $attributeName, $dataMap ) ) { $attribute = $dataMap[$attributeName]; $classAttributeID = $attribute->attribute( 'contentclassattribute_id' ); $dataType = $attribute->attribute( 'data_type_string' ); switch ( $dataType ) { case 'ezstring': case 'eztext': case 'ezselection': case 'ezemail': { if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $attribute->setAttribute( 'data_text', $this->parseAndReplaceStringReferences( $attributesContent['content'] ) ); } else { $attribute->setAttribute( 'data_text', $attributesContent['content'] ); } } break; case 'ezboolean': case 'ezinteger': { $attribute->setAttribute( 'data_int', (int)$attributesContent['content'] ); } break; case 'ezxmltext': { if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $attributesContent['content'] = $this->parseAndReplaceStringReferences( $attributesContent['content'] ); } if ( array_key_exists( 'htmlDecode', $attributesContent ) && $attributesContent['htmlDecode'] == "true" ) { $content = html_entity_decode( $attributesContent['content'] ); } else { $content = $attributesContent['content']; } $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n". '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"'."\n". ' xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"'."\n". ' xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">'."\n". ' <section>'."\n"; $xml .= ' <paragraph>' . $content . "</paragraph>\n"; $xml .= " </section>\n</section>\n"; $attribute->setAttribute( 'data_text', $xml ); } break; case 'ezprice': case 'ezfloat': { $attribute->setAttribute( 'data_float', (float)$attributesContent['content'] ); } break; case 'ezimage': { $imagePath = $this->setting( 'data_source' ) . '/' . $attributesContent['src']; $imageName = $attributesContent['title']; $path = realpath( $imagePath ); if ( file_exists( $path ) ) { $content = $attribute->content(); $content->initializeFromFile( $path, $imageName, basename( $attributesContent['src'] ) ); $content->store( $attribute ); } else { $this->writeMessage( "\tFile " . $path . " not found.", 'warning' ); } } break; case 'ezobjectrelation': { $objectID = $this->getReferenceID( $attributesContent['content'] ); if ( $objectID ) { $attribute->setAttribute( 'data_int', $objectID ); eZContentObject::fetch( $objectID )->addContentObjectRelation( $objectID, $versionNumber, $contentObject->attribute( 'id' ), $attribute->attribute( 'contentclassattribute_id' ), eZContentObject::RELATION_ATTRIBUTE ); } else { $this->writeMessage( "\tReference " . $attributesContent['content'] . " not set.", 'warning' ); } } break; case 'ezurl': { $url = ''; $title = ''; if ( array_key_exists( 'url', $attributesContent ) ) $url = $attributesContent['url']; if ( array_key_exists( 'title', $attributesContent ) ) $title = $attributesContent['title']; if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $title = $this->parseAndReplaceStringReferences( $title ); $url = $this->parseAndReplaceStringReferences( $url ); } $attribute->setAttribute( 'data_text', $title ); $attribute->setContent( $url ); } break; case 'ezuser': { $login = ''; $email = ''; $password = ''; if ( array_key_exists( 'login', $attributesContent ) ) $login = $attributesContent['login']; if ( array_key_exists( 'email', $attributesContent ) ) $email = $attributesContent['email']; if ( array_key_exists( 'password', $attributesContent ) ) $password = $attributesContent['password']; $contentObjectID = $attribute->attribute( "contentobject_id" ); $user =& $attribute->content(); if ( $user === null ) { $user = eZUser::create( $contentObjectID ); } $ini =& eZINI::instance(); $generatePasswordIfEmpty = $ini->variable( "UserSettings", "GeneratePasswordIfEmpty" ); if ( $password == "" ) { if ( $generatePasswordIfEmpty == 'true' ) { $passwordLength = $ini->variable( "UserSettings", "GeneratePasswordLength" ); $password = $user->createPassword( $passwordLength ); } else { $password = null; } } if ( $password == "_ezpassword" ) { $password = false; $passwordConfirm = false; } $user->setInformation( $contentObjectID, $login, $email, $password, $password ); $attribute->setContent( $user ); } break; case 'ezkeyword': { $keyword = new eZKeyword(); $keyword->initializeKeyword( $attributesContent['content'] ); $attribute->setContent( $keyword ); } break; case 'ezmatrix': { if ( is_array( $attributesContent ) ) { $matrix = $attribute->attribute( 'content' ); $cells = array(); $matrix->Matrix['rows']['sequential'] = array(); $matrix->NumRows = 0; foreach( $attributesContent as $key => $value ) { $cells = array_merge( $cells, $value ); $newRow['columns'] = $value; $newRow['identifier'] = 'row_' . ( $matrix->NumRows + 1 ); $newRow['name'] = 'Row_' . ( $matrix->NumRows + 1 ); $matrix->NumRows++; $matrix->Matrix['rows']['sequential'][] = $newRow; } $matrix->Cells = $cells; $attribute->setAttribute( 'data_text', $matrix->xmlString() ); $matrix->decodeXML( $attribute->attribute( 'data_text' ) ); $attribute->setContent( $matrix ); } } break; case 'ezauthor': case 'ezbinaryfile': case 'ezcountry': case 'ezdate': case 'ezdatetime': case 'ezenum': case 'ezidentifier': case 'ezinisetting': case 'ezisbn': case 'ezmedia': case 'ezmultioption': case 'ezmultiprice': case 'ezobjectrelationlist': case 'ezoption': case 'ezpackage': case 'ezproductcategory': case 'ezrangeoption': case 'ezsubtreesubscription': case 'eztime': { $this->writeMessage( "\tDatatype " . $dataType . " not supported yet.", 'warning' ); } break; } $attribute->store(); } } if ( isset($objectInformation['sectionID']) && $objectInformation['sectionID'] != '' && $objectInformation['sectionID'] != 0 ) { $contentObject->setAttribute( 'section_id', $objectInformation['sectionID'] ); } if ( isset($objectInformation['creatorID']) && $objectInformation['creatorID'] != '' && $objectInformation['creatorID'] != 0 ) { $contentObjectVersion->setAttribute( 'creator_id', $objectInformation['creatorID'] ); } if ( isset($objectInformation['ownerID']) && $objectInformation['ownerID'] != '' && $objectInformation['ownerID'] != 0 ) { $contentObject->setAttribute( 'owner_id', $objectInformation['ownerID'] ); } $contentObjectVersion->store(); $contentObject->store(); $db->commit(); eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version' => $versionNumber ) ); // set chosen hidden/invisible attributes for object nodes $http = eZHTTPTool::instance(); $assignedNodes = $contentObject->assignedNodes( true ); foreach ( $assignedNodes as $node ) { $nodeID = $node->attribute( 'node_id' ); $parentNodeID = $node->attribute( 'parent_node_id' ); $db = eZDB::instance(); $db->begin(); $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID ); eZContentObjectTreeNode::updateNodeVisibility( $node, $parentNode, /* $recursive = */ false ); $db->commit(); unset( $node, $parentNode ); } unset( $assignedNodes ); eZContentCacheManager::clearObjectViewCacheIfNeeded( $contentObject->attribute( 'id' ) ); $newNodeArray = eZContentObjectTreeNode::fetchByContentObjectID( $contentObject->attribute( 'id' ) ); $refArray = false; if ( $newNodeArray && count($newNodeArray) >= 1 ) { $newNode = $newNodeArray[0]; if ( $newNode ) { $refArray = array( "node_id" => $newNode->attribute( 'node_id' ), "name" => $contentObject->attribute( 'name' ), "object_id" => $contentObject->attribute( 'id' ) ); } } unset($contentObjectVersion); unset($contentObject); return $refArray; } return false; }