function runOperation(&$node) { $datamap = $node->dataMap(); $object_attribute = $datamap[$this->attribute]; if (!isset($object_attribute)) { echo "Attribute '{$this->attribute}' not found. "; return false; } $old_value = $object_attribute->toString(); // Set new value to specified attributes $arg_array = $this->arguments; foreach ($datamap as $key => $object_attribute) { $value = $object_attribute->toString(); $arg_array = str_replace('{' . $key . '}', $value, $arg_array); } $new_value = call_user_func_array($this->change_function, $arg_array); if ($new_value == $old_value) { // Nothing to change return true; } $db = eZDB::instance(); $db->begin(); // Create new version $content_object = $node->object(); $content_object_id = $content_object->attribute('id'); $version = $content_object->createNewVersion(); $version->setAttribute('modified', time()); $version->setAttribute('status', 'EZ_VERSION_STATUS_DRAFT'); $version->store(); $datamap = $version->dataMap(); $object_attribute = $datamap[$this->attribute]; $object_attribute->fromString($new_value); $object_attribute->store(); // Publish new version $operation_result = eZOperationHandler::execute('content', 'publish', array('object_id' => $content_object_id, 'version' => $version->attribute('version'))); $db->commit(); eZContentCacheManager::clearObjectViewCache($content_object_id); return $operation_result['status'] == 1; }
function removeReverseRelations( $objectID ) { $db = eZDB::instance(); $objectID = (int) $objectID; // Get list of objects referring to this one. $relatingObjects = $this->reverseRelatedObjectList( false, 0, false, array( 'AllRelations' => true ) ); // Finds all the attributes that store relations to the given object. $result = $db->arrayQuery( "SELECT attr.* FROM ezcontentobject_link link, ezcontentobject_attribute attr WHERE link.from_contentobject_id=attr.contentobject_id AND link.from_contentobject_version=attr.version AND link.contentclassattribute_id=attr.contentclassattribute_id AND link.to_contentobject_id=$objectID" ); // Remove references from XML. if ( count( $result ) > 0 ) { foreach( $result as $row ) { $attr = new eZContentObjectAttribute( $row ); $dataType = $attr->dataType(); $dataType->removeRelatedObjectItem( $attr, $objectID ); eZContentCacheManager::clearObjectViewCache( $attr->attribute( 'contentobject_id' ), true ); $attr->storeData(); } } // Remove references in ezcontentobject_link. foreach ( $relatingObjects as $fromObject ) { $fromObject->removeContentObjectRelation( $this->attribute( 'id' ), false, false ); } }
static function clearViewCache($objectID, $versionNum = true, $additionalNodeList = false) { eZDebug::writeWarning("'clearViewCache' function was deprecated. Use 'clearObjectViewCache' instead", __METHOD__); eZContentCacheManager::clearObjectViewCache($objectID, $versionNum, $additionalNodeList); }
static function clearContentCache($objectID, $versionNum = true, $additionalNodeList = false) { eZDebug::accumulatorStart('check_cache', '', 'Check cache'); eZContentCacheManager::clearObjectViewCache($objectID, $versionNum, $additionalNodeList); eZContentCacheManager::clearTemplateBlockCache($objectID); // Clear cached path strings of content SSL zones. eZSSLZone::clearCache(); eZDebug::accumulatorStop('check_cache'); return true; }
function &createObject($object_class_name, $parent_node_id, $import_field_list, $sectionID = 1, $priority = 0, $add_node_list = false) { $class = eZContentClass::fetchByIdentifier($object_class_name); $user =& eZUser::currentUser(); $contentObject =& $class->instantiate($user->attribute('contentobject_id'), $sectionID); unset($user); $contentObject->remoteID(); $contentObjectID = $contentObject->attribute('id'); $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $parent_node_id, 'is_main' => 1)); $nodeAssignment->setAttribute('parent_remote_id', "VHB_" . $parent_node_id); $nodeAssignment->store(); if ($priority) { $node = $nodeAssignment->attribute('node'); $node->setAttribute('priority', $priority); $node->store(); } $version =& $contentObject->version(1); $version->setAttribute('modified', time()); $version->setAttribute('status', EZ_VERSION_STATUS_DRAFT); $version->store(); $contentObjectID = $contentObject->attribute('id'); $contentObjectAttributes =& $version->contentObjectAttributes(); foreach ($contentObjectAttributes as $attribute) { if (isset($import_field_list[$attribute->attribute("contentclass_attribute_identifier")])) { $data = $import_field_list[$attribute->attribute("contentclass_attribute_identifier")]; importAttribute($data, $attribute); } } if (is_array($add_node_list)) { foreach ($add_node_list as $parent_node_id) { addNodeAssignment($contentObject, $parent_node_id); } } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); eZContentCacheManager::clearObjectViewCache($contentObjectID, 1); return $contentObject; }
static function publishUpdateUser($parentNodeIDs, $defaultUserPlacement, $userAttributes, $isUtf8Encoding = false) { if (!is_array($userAttributes) or !isset($userAttributes['login']) or empty($userAttributes['login'])) { eZDebug::writeWarning('Empty user login passed.', __METHOD__); return false; } if ((!is_array($parentNodeIDs) or count($parentNodeIDs) < 1) and !is_numeric($defaultUserPlacement)) { eZDebug::writeWarning('No one parent node IDs was passed for publishing new user (login = "******")', __METHOD__); return false; } $parentNodeIDs[] = $defaultUserPlacement; $parentNodeIDs = array_unique($parentNodeIDs); $login = $userAttributes['login']; $first_name = $userAttributes['first_name']; $last_name = $userAttributes['last_name']; $email = $userAttributes['email']; if ($isUtf8Encoding) { $first_name = utf8_decode($first_name); $last_name = utf8_decode($last_name); } $user = eZUser::fetchByName($login); $createNewUser = is_object($user) ? false : true; if ($createNewUser) { if (!isset($first_name) or empty($first_name) or !isset($last_name) or empty($last_name) or !isset($email) or empty($email)) { eZDebug::writeWarning('Cannot create user with empty first name (last name or email).', __METHOD__); return false; } $ini = eZINI::instance(); $userClassID = $ini->variable("UserSettings", "UserClassID"); $userCreatorID = $ini->variable("UserSettings", "UserCreatorID"); $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID"); $class = eZContentClass::fetch($userClassID); $contentObject = $class->instantiate($userCreatorID, $defaultSectionID); $contentObject->store(); $userID = $contentObjectID = $contentObject->attribute('id'); $version = $contentObject->version(1); $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $user = eZLDAPUser::create($userID); $user->setAttribute('login', $login); } else { $userID = $contentObjectID = $user->attribute('contentobject_id'); $contentObject = eZContentObject::fetch($userID); $version = $contentObject->attribute('current'); } //================= common part 1: start ======================== $contentObjectAttributes = $version->contentObjectAttributes(); // find and set 'name' and 'description' attributes (as standard user group class) $firstNameIdentifier = 'first_name'; $lastNameIdentifier = 'last_name'; $firstNameAttribute = null; $lastNameAttribute = null; foreach ($contentObjectAttributes as $attribute) { if ($attribute->attribute('contentclass_attribute_identifier') == $firstNameIdentifier) { $firstNameAttribute = $attribute; } else { if ($attribute->attribute('contentclass_attribute_identifier') == $lastNameIdentifier) { $lastNameAttribute = $attribute; } } } //================= common part 1: end ========================== // If we are updating an existing user, we must find out if some data should be changed. // In that case, we must create a new version and publish it. if (!$createNewUser) { $userDataChanged = false; $firstNameChanged = false; $lastNameChanged = false; $emailChanged = false; if ($firstNameAttribute and $firstNameAttribute->attribute('data_text') != $first_name) { $firstNameChanged = true; } $firstNameAttribute = false; // We will load this again from the new version we will create, if it has changed if ($lastNameAttribute and $lastNameAttribute->attribute('data_text') != $last_name) { $lastNameChanged = true; } $lastNameAttribute = false; // We will load this again from the new version we will create, if it has changed if ($user->attribute('email') != $email) { $emailChanged = true; } if ($firstNameChanged or $lastNameChanged or $emailChanged) { $userDataChanged = true; // Create new version $version = $contentObject->createNewVersion(); $contentObjectAttributes = $version->contentObjectAttributes(); foreach ($contentObjectAttributes as $attribute) { if ($attribute->attribute('contentclass_attribute_identifier') == $firstNameIdentifier) { $firstNameAttribute = $attribute; } else { if ($attribute->attribute('contentclass_attribute_identifier') == $lastNameIdentifier) { $lastNameAttribute = $attribute; } } } } } //================= common part 2: start ======================== if ($firstNameAttribute) { $firstNameAttribute->setAttribute('data_text', $first_name); $firstNameAttribute->store(); } if ($lastNameAttribute) { $lastNameAttribute->setAttribute('data_text', $last_name); $lastNameAttribute->store(); } if (!isset($userDataChanged) or $userDataChanged === true) { $contentClass = $contentObject->attribute('content_class'); $name = $contentClass->contentObjectName($contentObject); $contentObject->setName($name); } if (!isset($emailChanged) or $emailChanged === true) { $user->setAttribute('email', $email); } $user->setAttribute('password_hash', ""); $user->setAttribute('password_hash_type', 0); $user->store(); $debugArray = array('Updating user data', 'createNewUser' => $createNewUser, 'userDataChanged' => isset($userDataChanged) ? $userDataChanged : null, 'login' => $login, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'firstNameAttribute is_object' => is_object($firstNameAttribute), 'lastNameAttribute is_object' => is_object($lastNameAttribute), 'content object id' => $contentObjectID, 'version id' => $version->attribute('version')); eZDebug::writeNotice(var_export($debugArray, true), __METHOD__); //================= common part 2: end ========================== if ($createNewUser) { reset($parentNodeIDs); // prepare node assignments for publishing new user foreach ($parentNodeIDs as $parentNodeID) { $newNodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $parentNodeID, 'parent_remote_id' => uniqid('LDAP_'), 'is_main' => $defaultUserPlacement == $parentNodeID ? 1 : 0)); $newNodeAssignment->store(); } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); } else { if ($userDataChanged) { // Publish object $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => $version->attribute('version'))); // Refetch object $contentObject = eZContentObject::fetch($contentObjectID); $version = $contentObject->attribute('current'); } $LDAPIni = eZINI::instance('ldap.ini'); $keepGroupAssignment = $LDAPIni->hasVariable('LDAPSettings', 'KeepGroupAssignment') ? $LDAPIni->variable('LDAPSettings', 'KeepGroupAssignment') == "enabled" : false; if ($keepGroupAssignment == false) { $objectIsChanged = false; $db = eZDB::instance(); $db->begin(); // First check existing assignments, remove any that should not exist $assignedNodesList = $contentObject->assignedNodes(); $existingParentNodeIDs = array(); foreach ($assignedNodesList as $node) { $parentNodeID = $node->attribute('parent_node_id'); if (!in_array($parentNodeID, $parentNodeIDs)) { $node->removeThis(); $objectIsChanged = true; } else { $existingParentNodeIDs[] = $parentNodeID; } } // Then check assignments that should exist, add them if they are missing foreach ($parentNodeIDs as $parentNodeID) { if (!in_array($parentNodeID, $existingParentNodeIDs)) { $newNode = $contentObject->addLocation($parentNodeID, true); $newNode->updateSubTreePath(); $newNode->setAttribute('contentobject_is_published', 1); $newNode->sync(); $existingParentNodeIDs[] = $parentNodeID; $objectIsChanged = true; } } // Then ensure that the main node is correct $currentMainParentNodeID = $contentObject->attribute('main_parent_node_id'); if ($currentMainParentNodeID != $defaultUserPlacement) { $existingNode = eZContentObjectTreeNode::fetchNode($contentObjectID, $defaultUserPlacement); if (!is_object($existingNode)) { eZDebug::writeError("Cannot find assigned node as {$defaultUserPlacement}'s child.", __METHOD__); } else { $existingNodeID = $existingNode->attribute('node_id'); $versionNum = $version->attribute('version'); eZContentObjectTreeNode::updateMainNodeID($existingNodeID, $contentObjectID, $versionNum, $defaultUserPlacement); $objectIsChanged = true; } } $db->commit(); // Finally, clear object view cache if something was changed if ($objectIsChanged) { eZContentCacheManager::clearObjectViewCache($contentObjectID, true); } } } eZUser::updateLastVisit($userID); //eZUser::setCurrentlyLoggedInUser( $user, $userID ); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); return $user; }
function updateReverseRelatedObjects($related_object, $new_related_object) { $related_object_id = $related_object->attribute('id'); $new_related_object_id = $new_related_object->attribute('id'); $reverse_related_list = eZFunctionHandler::execute('content', 'reverse_related_objects', array('object_id' => $related_object_id, 'all_relations' => true, 'group_by_attribute' => true, 'as_object' => true)); foreach ($reverse_related_list as $attribute_id => $reverse_related_sublist) { foreach ($reverse_related_sublist as $reverse_related_object) { // To get the different languages of the related object, we need to go through a node fetch $main_node_id = $reverse_related_object->attribute('main_node_id'); $language_list = $reverse_related_object->attribute('available_languages'); foreach ($language_list as $language) { $tmp_node = eZFunctionHandler::execute('content', 'node', array('node_id' => $main_node_id, 'language_code' => $language)); $reverse_related_object = $tmp_node->attribute('object'); $new_version = $reverse_related_object->createNewVersionIn($language); $new_version->setAttribute('modified', time()); $new_version->store(); $new_attributes = $new_version->contentObjectAttributes(); foreach ($new_attributes as $reverse_attribute) { if (empty($attribute_id) or $reverse_attribute->attribute('contentclassattribute_id') == $attribute_id) { switch ($reverse_attribute->attribute('data_type_string')) { case 'ezobjectrelationlist': $old_list = $reverse_attribute->toString(); $list = explode('-', $old_list); foreach ($list as $key => $object_id) { if ($object_id == $related_object_id) { $list[$key] = $new_related_object_id; } } $list = implode('-', array_unique($list)); if ($old_list != $list) { $reverse_attribute->fromString($list); $reverse_attribute->store(); } break; case 'ezobjectrelation': $old_relation = $reverse_attribute->toString(); if ($old_relation != $new_related_object_id) { $reverse_attribute->fromString($new_related_object_id); $reverse_attribute->store(); } break; case 'ezxmltext': $old_xml = $reverse_attribute->toString(); $xml = $old_xml; $xml = str_ireplace("object_id=\"{$related_object_id}\"", "object_id=\"{$new_related_object_id}\"", $xml); $related_node_array = $related_object->attribute('assigned_nodes'); $new_related_node_id = $new_related_object->attribute('main_node_id'); foreach ($related_node_array as $related_node) { $related_node_id = $related_node->attribute('node_id'); $xml = str_ireplace("node_id=\"{$related_node_id}\"", "node_id=\"{$new_related_node_id}\"", $xml); } if ($xml != $old_xml) { $reverse_attribute->fromString($xml); $reverse_attribute->store(); } break; default: } } } // Publish new version $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $reverse_related_object->attribute('id'), 'version' => $new_version->attribute('version'))); eZContentCacheManager::clearObjectViewCache($reverse_related_object->attribute('id'), $new_version->attribute('version')); } } } }
$db = eZDB::instance(); #include_once( 'kernel/classes/ezcontentobjecttreenode.php' ); $parentNodeIDArray = $object->attribute('parent_nodes'); $tmpNode = eZContentObjectTreeNode::create($parentNodeIDArray[0], $object->attribute('id'), $approveStatus->attribute('active_version')); $tmpNode->store(); $parentNode = $tmpNode->attribute('parent'); $tmpNode->setAttribute('main_node_id', $tmpNode->attribute('node_id')); $tmpNode->setAttribute('path_string', $parentNode->attribute('path_string') . $tmpNode->attribute('node_id') . '/'); $tmpNode->setAttribute('depth', $parentNode->attribute('depth') + 1); // $tmpNode->setAttribute( 'published', mktime() ); $tmpNode->setAttribute('path_identification_string', $tmpNode->pathWithNames()); $tmpNode->sync(); #include_once( 'kernel/classes/ezurlalias.php' ); $alias = eZURLAlias::create($tmpNode->attribute('path_identification_string'), 'content/versionview/' . $object->attribute('id') . '/' . $approveStatus->attribute('active_version')); $alias->store(); #include_once( "kernel/classes/ezcontentcachemanager.php" ); eZContentCacheManager::clearObjectViewCache($parentNode->attribute('contentobject_id')); } return $Module->redirect('collaboration', 'item', array('full', $collaborationItemID)); } } } } } $tpl = templateInit(); $tpl->setVariable('approval_status', $approveStatus); $tpl->setVariable('object', $approveStatus->attribute('object_version')); $tpl->setVariable('warning', $warning); $Result = array(); $Result['content'] = $tpl->fetch('design:workflow/eventtype/ezapprove2/select_approver.tpl'); $Result['path'] = array(array('url' => false, 'text' => ezi18n('ezapprove2', 'Edit Subscription')));
function execute($process, $event) { // Get some information about the object being passed $parameters = $process->attribute('parameter_list'); $object = eZContentObject::fetch($parameters['object_id']); // Because this is also run by the cronjob, check to make sure the object hasn't been deleted if (!$object) { eZDebugSetting::writeError('workflow-hideuntildate', 'The object with ID ' . $parameters['object_id'] . ' does not exist.', 'eZApproveType::execute() object is unavailable'); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } // if the current version of an object is not the version the workflow pertains to, cancel the workflow $currentVersion = $object->attribute('current_version'); $version = $parameters['version']; if ($currentVersion != $version) { return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } // Get the data map for this object $objectAttributes = $object->attribute('data_map'); // Get the user configuration with class and attribute mapping and the boolean modify publish date setting $workflowSettings = $this->getWorkflowSettings($event); foreach ($objectAttributes as $objectAttribute) { if (in_array($objectAttribute->attribute('contentclassattribute_id'), $workflowSettings['classattribute_map'])) { // Make sure this is of a date or datetime attribute if (in_array($objectAttribute->attribute('data_type_string'), array('ezdate', 'ezdatetime'))) { // If the publish date is in the future, hide the node if (time() < $objectAttribute->toString()) { // Set a time for when this workflow should be tested again via the cronjob // Store a description to be displayed in the Setup > Workflow processes list // This must also be accompanied by overriding the workflow/processlist.tpl template $parameters = array_merge($parameters, array('event_description' => 'Publishing of object delayed until ' . $objectAttribute->attribute('content')->toString(true))); $process->setParameters($parameters); $process->store(); // Hide the object's nodes $nodes = $object->attribute('assigned_nodes'); foreach ($nodes as $node) { if (!$node->attribute('is_hidden')) { eZContentObjectTreeNode::hideSubTree($node); } } return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; } elseif ($objectAttribute->hasContent()) { if ($workflowSettings['modify_publish_date']) { $object->setAttribute('published', $objectAttribute->toString()); $object->store(); } $nodes = $object->attribute('assigned_nodes'); foreach ($nodes as $node) { eZContentObjectTreeNode::unhideSubTree($node); eZContentCacheManager::clearContentCache($parameters['object_id']); eZContentCacheManager::clearObjectViewCache($parameters['object_id']); } return eZWorkflowType::STATUS_ACCEPTED; } } else { // Attribute that matched was not a valid date or datetime attribute, so ignore return eZWorkflowType::STATUS_ACCEPTED; } } } // No attributes matched the workflow configured by the user return eZWorkflowType::STATUS_ACCEPTED; }
catch (Exception $e) { $cli->output($e->getMessage()); } } //get XML $xml = getXML(); if(!empty($xml)) { //fetch objects parent node /* @type $parentObject eZContentObject */ /* @type $parentNode eZContentObjectTreeNode */ $parentObject = eZContentObject::fetchByRemoteID( 'congress_report_rss_folder' ); $parentNode = $parentObject->mainNode(); //delete parent node childrens deleteNodes($parentNode); //convert XML string into eZ Publish objects XMLToHTMLObjects($parentNode, $xml); //clear homepage varnish cache $varnishControl = new VarnishControl(); $varnishControl->banNodes($parentNode->attribute('parent_node_id')); //clear parent view cache eZContentCacheManager::clearObjectViewCache( $parentObject->attribute('id'), true ); }