function execute( $xmlNode ) { $action = $xmlNode->getAttribute( 'action' ); $xmlNodeID = $xmlNode->getAttribute( 'nodeID' ); $nodeID = $this->getReferenceID( $xmlNodeID ); if ( !$nodeID ) { $this->writeMessage( "\tInvalid node $nodeID does not exist.", 'warning' ); return false; } if ( !$action ) { $action = 'toogle'; } $node = eZContentObjectTreeNode::fetch( $nodeID ); if ( !$node ) { $this->writeMessage( "\tNo node defined.", 'error' ); return false; } switch ( $action ) { case 'unhide': { if ( $node->attribute( 'is_hidden' ) ) { eZContentObjectTreeNode::unhideSubTree( $node ); $this->writeMessage( "\tNode " . $node->attribute( 'name' ) . " has be unhidden.", 'error' ); } } break; case 'hide': { if ( !$node->attribute( 'is_hidden' ) ) { eZContentObjectTreeNode::hideSubTree( $node ); $this->writeMessage( "\tNode " . $node->attribute( 'name' ) . " has be hidden.", 'error' ); } } break; case 'toogle': { if ( $node->attribute( 'is_hidden' ) ) { eZContentObjectTreeNode::unhideSubTree( $node ); $this->writeMessage( "\tNode " . $node->attribute( 'name' ) . " has be unhidden.", 'error' ); } else { eZContentObjectTreeNode::hideSubTree( $node ); $this->writeMessage( "\tNode " . $node->attribute( 'name' ) . " has be hidden.", 'error' ); } } break; } }
function runOperation(&$node) { if (!$node->canHide()) { return false; } if ($this->hidden) { eZContentObjectTreeNode::hideSubTree($node); } else { eZContentObjectTreeNode::unhideSubTree($node); } // We have no result value, so assume the operation worked return true; }
/** * Changes an contentobject's status * * @param int $nodeID * * @return array An array with operation status, always true */ public static function changeHideStatus($nodeID) { $action = 'hide'; $curNode = eZContentObjectTreeNode::fetch($nodeID); if (is_object($curNode)) { if ($curNode->attribute('is_hidden')) { eZContentObjectTreeNode::unhideSubTree($curNode); $action = 'show'; } else { eZContentObjectTreeNode::hideSubTree($curNode); } } //call appropriate method from search engine eZSearch::updateNodeVisibility($nodeID, $action); return array('status' => true); }
function checkContentActions( $module, $class, $object, $version, $contentObjectAttributes, $EditVersion, $EditLanguage, $FromLanguage, &$Result ) { if ( $module->isCurrentAction( 'Preview' ) ) { $module->redirectToView( 'versionview', array( $object->attribute('id'), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'Translate' ) ) { $module->redirectToView( 'translate', array( $object->attribute( 'id' ), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'VersionEdit' ) ) { if ( isset( $GLOBALS['eZRequestedURI'] ) and is_object( $GLOBALS['eZRequestedURI'] ) ) { $uri = $GLOBALS['eZRequestedURI']; $uri = $uri->originalURIString(); $http = eZHTTPTool::instance(); $http->setSessionVariable( 'LastAccessesVersionURI', $uri ); } $module->redirectToView( 'history', array( $object->attribute( 'id' ), $EditVersion, $EditLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'EditLanguage' ) ) { if ( $module->hasActionParameter( 'SelectedLanguage' ) ) { $EditLanguage = $module->actionParameter( 'SelectedLanguage' ); // We reset the from language to disable the translation look $FromLanguage = false; $module->redirectToView( 'edit', array( $object->attribute('id'), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } if ( $module->isCurrentAction( 'TranslateLanguage' ) ) { if ( $module->hasActionParameter( 'SelectedLanguage' ) ) { $FromLanguage = $EditLanguage; $EditLanguage = $module->actionParameter( 'SelectedLanguage' ); $module->redirectToView( 'edit', array( $object->attribute('id'), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } if ( $module->isCurrentAction( 'FromLanguage' ) ) { $FromLanguage = $module->actionParameter( 'FromLanguage' ); $module->redirectToView( 'edit', array( $object->attribute('id'), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'Discard' ) ) { $http = eZHTTPTool::instance(); $objectID = $object->attribute( 'id' ); $discardConfirm = true; if ( $http->hasPostVariable( 'DiscardConfirm' ) ) $discardConfirm = $http->postVariable( 'DiscardConfirm' ); $http->setSessionVariable( 'DiscardObjectID', $objectID ); $http->setSessionVariable( 'DiscardObjectVersion', $EditVersion ); $http->setSessionVariable( 'DiscardObjectLanguage', $EditLanguage ); $http->setSessionVariable( 'DiscardConfirm', $discardConfirm ); $module->redirectTo( $module->functionURI( 'removeeditversion' ) . '/' ); return eZModule::HOOK_STATUS_CANCEL_RUN; } // helper function which computes the redirect after // publishing and final store of a draft. function computeRedirect( $module, $object, $version, $EditLanguage = false ) { $http = eZHTTPTool::instance(); $node = $object->mainNode(); if ( $http->hasSessionVariable( 'RedirectIfDiscarded' ) ) { $http->removeSessionVariable( 'RedirectIfDiscarded' ); } $hasRedirected = false; if ( $http->hasSessionVariable( 'ParentObject' ) && $http->sessionVariable( 'NewObjectID' ) == $object->attribute( 'id' ) ) { $parentArray = $http->sessionVariable( 'ParentObject' ); $parentURL = $module->redirectionURI( 'content', 'edit', $parentArray ); $parentObject = eZContentObject::fetch( $parentArray[0] ); $db = eZDB::instance(); $db->begin(); $parentObject->addContentObjectRelation( $object->attribute( 'id' ), $parentArray[1] ); $db->commit(); $http->removeSessionVariable( 'ParentObject' ); $http->removeSessionVariable( 'NewObjectID' ); $module->redirectTo( $parentURL ); $hasRedirected = true; } if ( $http->hasSessionVariable( 'RedirectURIAfterPublish' ) && !$hasRedirected ) { $uri = $http->sessionVariable( 'RedirectURIAfterPublish' ); $http->removeSessionVariable( 'RedirectURIAfterPublish' ); $module->redirectTo( $uri ); $hasRedirected = true; } if ( $http->hasPostVariable( 'RedirectURIAfterPublish' ) && !$hasRedirected ) { $uri = $http->postVariable( 'RedirectURIAfterPublish' ); $module->redirectTo( $uri ); $hasRedirected = true; } if ( $http->hasPostVariable( "BackToEdit" ) && $http->postVariable( "BackToEdit" ) ) { $uri = $module->redirectionURI( 'content', 'edit', array( $object->attribute( 'id'), 'f', $EditLanguage ) ); $module->redirectTo( $uri ); eZDebug::writeDebug( $uri, "uri " . $object->attribute( 'id') ); $hasRedirected = true; } if ( !$hasRedirected ) { if ( $http->hasPostVariable( 'RedirectURI' ) ) { $uri = $http->postVariable( 'RedirectURI' ); $module->redirectTo( $uri ); } else if ( $node !== null ) { $parentNode = $node->attribute( 'parent_node_id' ); if ( $parentNode == 1 ) { $parentNode = $node->attribute( 'node_id' ); } $module->redirectToView( 'view', array( 'full', $parentNode ) ); } else { $module->redirectToView( 'view', array( 'full', $version->attribute( 'main_parent_node_id' ) ) ); } } } if( $module->isCurrentAction( 'StoreExit' ) ) { computeRedirect( $module, $object, $version, $EditLanguage ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'Publish' ) ) { // Checking the source and destination language from the url, // if they are the same no confirmation is needed. if ( $EditLanguage != $FromLanguage ) { $conflictingVersions = $version->hasConflicts( $EditLanguage ); if ( $conflictingVersions ) { $tpl = eZTemplate::factory(); $res = eZTemplateDesignResource::instance(); $res->setKeys( array( array( 'object', $object->attribute( 'id' ) ), array( 'remote_id', $object->attribute( 'remote_id' ) ), array( 'class', $class->attribute( 'id' ) ), array( 'class_identifier', $class->attribute( 'identifier' ) ), array( 'class_group', $class->attribute( 'match_ingroup_id_list' ) ) ) ); $tpl->setVariable( 'edit_language', $EditLanguage ); $tpl->setVariable( 'current_version', $version->attribute( 'version' ) ); $tpl->setVariable( 'object', $object ); $tpl->setVariable( 'draft_versions', $conflictingVersions ); $Result = array(); $Result['content'] = $tpl->fetch( 'design:content/edit_conflict.tpl' ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } eZDebug::accumulatorStart( 'publish', '', 'publish' ); $oldObjectName = $object->name(); $behaviour = new ezpContentPublishingBehaviour(); $behaviour->isTemporary = true; $behaviour->disableAsynchronousPublishing = false; ezpContentPublishingBehaviour::setBehaviour( $behaviour ); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $object->attribute( 'id' ), 'version' => $version->attribute( 'version' ) ) ); eZDebug::accumulatorStop( 'publish' ); if ( ( array_key_exists( 'status', $operationResult ) && $operationResult['status'] != eZModuleOperationInfo::STATUS_CONTINUE ) ) { eZDebug::writeDebug( $operationResult, __FILE__ ); switch( $operationResult['status'] ) { case eZModuleOperationInfo::STATUS_REPEAT: { eZContentOperationCollection::setVersionStatus( $object->attribute( 'id' ), $version->attribute( 'version' ), eZContentObjectVersion::STATUS_REPEAT ); } case eZModuleOperationInfo::STATUS_HALTED: { if ( isset( $operationResult['redirect_url'] ) ) { $module->redirectTo( $operationResult['redirect_url'] ); return; } else if ( isset( $operationResult['result'] ) ) { $result = $operationResult['result']; $resultContent = false; if ( is_array( $result ) ) { if ( isset( $result['content'] ) ) { $resultContent = $result['content']; } if ( isset( $result['path'] ) ) { $Result['path'] = $result['path']; } } else { $resultContent = $result; } // Temporary fix to make approval workflow work with edit. if ( strpos( $resultContent, 'Deffered to cron' ) === 0 ) { $Result = null; } else { $Result['content'] = $resultContent; } } }break; case eZModuleOperationInfo::STATUS_CANCELLED: { $Result = array(); $Result['content'] = "Content publish cancelled<br/>"; } } /* If we already have a correct module result * we don't need to continue module execution. */ if ( is_array( $Result ) ) return eZModule::HOOK_STATUS_CANCEL_RUN; } // update content object attributes array by refetching them from database $object = eZContentObject::fetch( $object->attribute( 'id' ) ); $contentObjectAttributes = $object->attribute( 'contentobject_attributes' ); // set chosen hidden/invisible attributes for object nodes $http = eZHTTPTool::instance(); $assignedNodes = $object->assignedNodes( true ); foreach ( $assignedNodes as $node ) { $nodeID = $node->attribute( 'node_id' ); $parentNodeID = $node->attribute( 'parent_node_id' ); $updateNodeVisibility = false; $postVarName = "FutureNodeHiddenState_$parentNodeID"; if ( !$http->hasPostVariable( $postVarName ) ) $updateNodeVisibility = true; else { $futureNodeHiddenState = $http->postVariable( $postVarName ); $db = eZDB::instance(); $db->begin(); if ( $futureNodeHiddenState == 'hidden' ) eZContentObjectTreeNode::hideSubTree( $node ); else if ( $futureNodeHiddenState == 'visible' ) eZContentObjectTreeNode::unhideSubTree( $node ); else if ( $futureNodeHiddenState == 'unchanged' ) $updateNodeVisibility = true; else eZDebug::writeWarning( "Unknown value for the future node hidden state: '$futureNodeHiddenState'" ); $db->commit(); } if ( $updateNodeVisibility ) { // this might be redundant $db = eZDB::instance(); $db->begin(); $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID ); eZContentObjectTreeNode::updateNodeVisibility( $node, $parentNode, /* $recursive = */ false ); $db->commit(); unset( $node, $parentNode ); } } unset( $assignedNodes ); $object = eZContentObject::fetch( $object->attribute( 'id' ) ); $newObjectName = $object->name(); $http = eZHTTPTool::instance(); computeRedirect( $module, $object, $version, $EditLanguage ); // we have set redirection URI for module so we don't need to continue module execution return eZModule::HOOK_STATUS_CANCEL_RUN; } }
public function execute( $process, $event ) { $parameters = $process->attribute( 'parameter_list' ); $object = eZContentObject::fetch( $parameters['object_id'] ); $attribute = false; $dataMap = $object->attribute( 'data_map' ); foreach ( $dataMap as $attr ) { $dataType = $attr->attribute( 'data_type_string' ); if ( $dataType == 'ezfeatureselect' ) { $attribute = $attr; continue; } } // if object does not have a featureselect attribute. if ( $attribute == false ) { return eZWorkflowType::STATUS_ACCEPTED; } // if we have not the first version published, we only need to enable/disable features if ( $object->attribute( 'modified' ) != $object->attribute( 'published' ) ) { $attributeContent = $attribute->attribute( 'content' ); $installedFeatureList = $attributeContent['installed_feature_list']; $availibleFeatureList = $attributeContent['availible_feature_list']; $mainNodeID = $object->attribute( 'main_node_id' ); foreach( $availibleFeatureList as $feature => $featureName ) { $featureObject = eZContentObject::fetchByRemoteID( $mainNodeID . '_' . $feature ); if( !$featureObject ) { eZDebug::writeError( "Cannot find feature object", "eZXMLPublisherType::execute" ); continue; } $featureNode = $featureObject->attribute( 'main_node' ); if( !$featureNode ) { eZDebug::writeError( "Cannot find feature node", "eZXMLPublisherType::execute" ); continue; } if ( in_array( $feature, $installedFeatureList ) ) { if ( $featureNode->attribute( 'is_hidden' ) ) { eZContentObjectTreeNode::unhideSubTree( $featureNode ); } $featureObject = $featureNode->attribute( 'object' ); $list = $featureObject->reverseRelatedObjectList( false, 0, false, array( 'AllRelations' => eZContentObject::RELATION_ATTRIBUTE, 'IgnoreVisibility' => true ) ); if ( is_array( $list ) ) { foreach ( $list as $reverseRelatedContentObject ) { $reverseRelatedMainNode = $reverseRelatedContentObject->attribute( 'main_node' ); eZContentObjectTreeNode::unhideSubTree( $reverseRelatedMainNode ); } } } elseif ( !in_array( $feature, $installedFeatureList ) && !$featureNode->attribute( 'is_hidden' ) ) { if ( !$featureNode->attribute( 'is_hidden' ) ) { eZContentObjectTreeNode::hideSubTree( $featureNode ); } $featureObject = $featureNode->attribute( 'object' ); $list = $featureObject->reverseRelatedObjectList( false, 0, false, array( 'AllRelations' => eZContentObject::RELATION_ATTRIBUTE, 'IgnoreVisibility' => true ) ); if ( is_array( $list ) ) { foreach ( $list as $reverseRelatedContentObject ) { $reverseRelatedMainNode = $reverseRelatedContentObject->attribute( 'main_node' ); eZContentObjectTreeNode::hideSubTree( $reverseRelatedMainNode ); } } } } } // defer to cron, this is safer because we might do a lot of things here include_once( 'lib/ezutils/classes/ezsys.php' ); if ( eZSys::isShellExecution() == false ) { return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; } // if we have the first version published, we need to set up the related things. if ( $object->attribute( 'modified' ) == $object->attribute( 'published' ) ) { $classAttribute = $attribute->attribute( 'contentclass_attribute' ); $templateName = $classAttribute->attribute( 'data_text1' ); $attributeContent = $attribute->attribute( 'content' ); $installedFeatureList = $attributeContent['installed_feature_list']; $availibleFeatureList = $attributeContent['availible_feature_list']; if( $templateName == '' ) { return eZWorkflowType::STATUS_ACCEPTED; } $template = 'design:' . $templateName; $tpl = eZTemplate::factory(); $tpl->setVariable( 'tpl_info', false ); $content = $tpl->fetch( $template ); $tpl->setVariable( 'install_features', $installedFeatureList ); $userID = $object->attribute( 'owner_id' ); $tpl->setVariable( 'owner_object_id', $userID ); $nodeID = $object->attribute( 'main_node_id' ); $tpl->setVariable( 'main_node_id', $nodeID ); $content = $tpl->fetch( $template ); $xml = $tpl->variable( "xml_data" ); $doc = new DOMDocument( '1.0', 'utf-8' ); if( !$doc->loadXML( $xml ) ) { eZDebug::writeError( "Cannot parse XML", "eZXMLPublisherType::execute" ); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } $xmlInstaller = new eZXMLInstaller( $doc ); if (! $xmlInstaller->proccessXML() ) { eZDebug::writeError( "Cannot proccess XML", "eZXMLPublisherType::execute" ); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } return eZWorkflowType::STATUS_ACCEPTED; } // otherwise we need only to enable, disable the selected features. else { } return eZWorkflowType::STATUS_ACCEPTED; }
/** * Depending on the new parent node visibility, recompute "is_invisible" attribute for the given node and * its children. (used after content/move or content/copy) * * @param eZContentObjectTreeNode $node * @param eZContentObjectTreeNode $parentNode * @param bool $recursive */ static function updateNodeVisibility($node, $parentNode, $recursive = true) { if (!$node) { eZDebug::writeWarning('No such node to update visibility for.'); return; } if (!$parentNode) { eZDebug::writeWarning('No parent node found when updating node visibility'); return; } if ($node->attribute('is_hidden') == 0 && $parentNode->attribute('is_invisible') != $node->attribute('is_invisible')) { $parentNodeIsVisible = $parentNode->attribute('is_invisible'); $nodeID = $node->attribute('node_id'); $db = eZDB::instance(); $db->begin(); $db->query("UPDATE ezcontentobject_tree SET is_invisible={$parentNodeIsVisible} WHERE node_id={$nodeID}"); if ($recursive) { // update visibility for children of the node if ($parentNodeIsVisible) { eZContentObjectTreeNode::hideSubTree($node, $modifyRootNode = false); } else { eZContentObjectTreeNode::unhideSubTree($node, $modifyRootNode = false); } } $db->commit(); } }
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; }
break; foreach ( $results as $result ) { if ( ($i+1)%100 == 0 ) $cli->notice( "$i nodes have been treated." ); $node = eZContentObjectTreeNode::fetch($result['node_id']); if ( !($node instanceof eZContentObjectTreeNode) ) { $cli->warning("{$result['node_id']} is not a valid node."); $offset+=1; continue; } else { $i++; } eZContentObjectTreeNode::unhideSubTree( $node ); eZContentObject::clearCache(); } // We don't need to increment the offset as is_hidden of unhidden nodes will change to 0 !! //$offset+= $limit; } $script->shutdown (0, "Treatment completed successfully; $i nodes treated." );
/** * Change node`s visibility * * @private * @param eZContentObject $object * @param bool $visibility * @return void */ private function updateVisibility($object, $visibility = true) { $action = $visibility ? 'show' : 'hide'; $nodeAssigments = eZPersistentObject::fetchObjectList(eZNodeAssignment::definition(), null, array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version')), null, null, true); foreach ($nodeAssigments as $nodeAssigment) { $node = $nodeAssigment->attribute('node'); if ($node instanceof eZContentObjectTreeNode === false) { continue; } if ((bool) (!$node->attribute('is_hidden')) === (bool) $visibility) { continue; } if ($action == 'show') { eZContentObjectTreeNode::unhideSubTree($node); } else { eZContentObjectTreeNode::hideSubTree($node); } eZSearch::updateNodeVisibility($node->attribute('node_id'), $action); } }