function execute($process, $event)
 {
     // get object being published
     $parameters = $process->attribute('parameter_list');
     $objectID = $parameters['object_id'];
     eZDebug::writeDebug('Update object state for object: ' . $objectID);
     $object = eZContentObject::fetch($objectID);
     $state_before = $event->attribute('state_before');
     $state_after = $event->attribute('state_after');
     if ($object == null) {
         eZDebug::writeError('Update object state failed for inexisting object: ' . $objectID, __METHOD__);
         return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
     }
     if ($state_before == null || $state_after == null) {
         eZDebug::writeError('Update object state failed: badly configured states', __METHOD__);
         return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
     }
     $currentStateIDArray = $object->attribute('state_id_array');
     if (in_array($state_before->attribute('id'), $currentStateIDArray)) {
         $canAssignStateIDList = $object->attribute('allowed_assign_state_id_list');
         if (!in_array($state_after->attribute('id'), $canAssignStateIDList)) {
             eZDebug::writeWarning("Not enough rights to assign state to object {$objectID}: " . $state_after->attribute('id'), __METHOD__);
         } else {
             eZDebug::writeDebug('Changing object state from ' . $state_before->attribute('name') . ' to ' . $state_after->attribute('name'), __METHOD__);
             if (eZOperationHandler::operationIsAvailable('content_updateobjectstate')) {
                 $operationResult = eZOperationHandler::execute('content', 'updateobjectstate', array('object_id' => $objectID, 'state_id_list' => array($state_after->attribute('id'))));
             } else {
                 eZContentOperationCollection::updateObjectState($objectID, array($state_after->attribute('id')));
             }
         }
     }
     return eZWorkflowType::STATUS_ACCEPTED;
 }
 function modifier()
 {
     if ($this->Modifier === null) {
         $this->Modifier = eZContentObject::fetch($this->ModifierID);
     }
     return $this->Modifier;
 }
    /**
     * @param eZContentObjectTreeNode $node
     * @return string
     */
    public function getNodeUrl(&$node = null)
    {
        $token = $this->getToken();

        $dataMap                        = $node->dataMap();
        $mediaContentAttribute          = $dataMap['media_content'];
        $mediaContentAttributeContent   = $mediaContentAttribute->content();
        $linkObjectID                   = $mediaContentAttributeContent['relation_list'][0]['contentobject_id'];
        $linkObject                     = eZContentObject::fetch( $linkObjectID );
        $linkDatamap                    = $linkObject->dataMap();
        $url                            = $linkDatamap['url']->content();

        $queryStringPosition = strpos($url, '?');
        $queryString = substr($url, $queryStringPosition + 1);
        $url = substr($url, 0, $queryStringPosition);

        $queryStringParts = array();

        parse_str($queryString, $queryStringParts);
        $queryStringParts[self::SESSION_ID_FIELD] = $token;

        $queryString = http_build_query($queryStringParts);
        $url .= '?' . $queryString;

        return $url;
    }
 function execute($process, $event)
 {
     $parameters = $process->attribute('parameter_list');
     $object = eZContentObject::fetch($parameters['object_id']);
     $versionID = $parameters['version'];
     if (!$object) {
         return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
     }
     $version = $object->version($versionID);
     if (!$version) {
         return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
     }
     $akismetObject = new eZContentObjectAkismet();
     $comment = $akismetObject->akismetInformationExtractor($version);
     if ($comment) {
         $akismet = new eZAkismet($comment);
         if ($akismet) {
             $isSpam = $akismet->isCommentSpam();
             eZDebug::writeDebug($comment);
             eZDebug::writeDebug("this is spam: " . $isSpam);
         } else {
             return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
         }
         if (!$isSpam) {
             $response = $akismet->submitHam();
             return eZWorkflowType::STATUS_ACCEPTED;
         }
         return eZWorkflowType::STATUS_REJECTED;
     }
 }
 function runOperation(&$node)
 {
     $object = $node->attribute('object');
     $object_id = $object->attribute('id');
     $objectLocales = $object->attribute('available_languages');
     // If the alternative locale does not exist for object, create it
     if (!in_array($this->altLocale, $objectLocales)) {
         // The only translation is in locate to be removed - create a version in another locale first.
         echo "Copying the single translation in " . $this->remLocale . " to " . $this->altLocale . " so former could be removed.\n";
         $newVersion = $object->createNewVersionIn($this->altLocale, $this->remLocale, false, true, eZContentObjectVersion::STATUS_DRAFT);
         $publishResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object_id, 'version' => $newVersion->attribute('version')));
         eZContentObject::clearCache();
         $object = eZContentObject::fetch($object_id);
     }
     // Change objects main language to alternative language, if its current main language is to be removed.
     if ($object->attribute('initial_language_code') == $this->remLocale) {
         eZContentObject::clearCache();
         $object = eZContentObject::fetch($object_id);
         echo "Switching initial language to {$this->altLocale} so that " . $this->remLocale . " could be removed.\n";
         $updateResult = eZContentOperationCollection::updateInitialLanguage($object_id, $this->altLangID);
         $object->store();
         eZContentObject::clearCache();
         $object = eZContentObject::fetch($object_id);
     }
     // Now it should be safe to remove translation.
     return $object->removeTranslation($this->remLangID);
 }
 /**
  * Returns part of the data for the attribute
  *
  * @param string $dataMember
  *
  * @return string
  */
 public function getDataMember($dataMember)
 {
     if ($dataMember === 'related_images') {
         $images = array();
         $relations = $this->ContentObjectAttribute->attribute('content');
         foreach ($relations['relation_list'] as $relation) {
             $object = eZContentObject::fetch($relation['contentobject_id']);
             if ($object instanceof eZContentObject) {
                 $dataMap = $object->attribute('data_map');
                 foreach ($dataMap as $attribute) {
                     /** @var eZContentObjectAttribute $attribute */
                     if ($attribute->attribute('data_type_string') !== eZImageType::DATA_TYPE_STRING) {
                         continue;
                     }
                     if ($attribute->hasContent()) {
                         $imageAliasHandler = $attribute->attribute('content');
                         $imageAlias = $imageAliasHandler->imageAlias('opengraph');
                         if ($imageAlias['is_valid'] == 1) {
                             $images[] = eZSys::serverURL() . '/' . $imageAlias['full_path'];
                         }
                     }
                 }
             }
         }
         if (empty($images)) {
             $images[] = eZSys::serverURL() . eZURLOperator::eZImage(null, 'opengraph_default_image.png', '');
         }
         return $images;
     }
     return $this->getData();
 }
Esempio n. 7
0
 /**
  * get the contentobject of one comment
  * @return eZContentObject
  */
 public function contentObject()
 {
     if (isset($this->ContentObjectID) and $this->ContentObjectID) {
         return eZContentObject::fetch($this->ContentObjectID);
     }
     return null;
 }
 private function solrMetaDataExists( $contentObjectID=0, $attributeIdentifier='', $subattr='' )
 {
     try
     {
         $contentObject = eZContentObject::fetch( $contentObjectID );
         $dataMap = $contentObject->dataMap();
         if ( array_key_exists( $attributeIdentifier, $dataMap ) )
         {
             $contentObjectAttribute = $dataMap[$attributeIdentifier];
             $eZType = eZDataType::create( solrMetaDataType::DATA_TYPE_STRING );
             $value = $eZType->getValue( $contentObjectAttribute->ID, $subattr );
             return ( ! empty( $value ) );
         }
         else
         {
             eZDebug::writeError( 'Object '.$contentObjectID.' has no attribute '.$attributeIdentifier, 'solrMetaDataExists Error' );
         }
         return false;
     }
     catch ( Exception $e )
     {
         eZDebug::writeError( $e, 'solrMetaDataExists Exception' );
         return false;
     }
 }
function akismet_ContentActionHandler($module, $http, $objectID)
{
    $object = eZContentObject::fetch($objectID);
    $version = $object->attribute('current');
    if ($http->hasPostVariable('AkismetSubmitSpam')) {
        $user = eZUser::currentUser();
        $accessResult = $user->hasAccessTo('akismet', 'submit');
        if ($accessResult['accessWord'] === 'yes') {
            $mainNode = $object->attribute('main_node');
            $module->redirectTo($mainNode->attribute('url_alias'));
            $akismetObject = new eZContentObjectAkismet();
            $comment = $akismetObject->akismetInformationExtractor($version);
            if ($comment) {
                $akismet = new eZAkismet($comment);
                if ($akismet) {
                    $feedback = $akismet->submitSpam();
                    $response[] = $feedback[1];
                } else {
                    $response[] = ezi18n('extension/contactivity/akismet/submit', "An error has occured, unable to submit spam to Akismet.");
                }
            } else {
                $response[] = ezi18n('extension/contactivity/akismet/submit', "An error has occured, unable to submit spam to Akismet.");
            }
        }
        $mainNode = $object->attribute('main_node');
        $module->redirectTo($mainNode->attribute('url_alias'));
        return true;
    }
}
 /**
  * Regression test for issue {@see #19174 http://issues.ez.no/19174}
  */
 public function testIssue19174()
 {
     $bkpLanguages = eZContentLanguage::prioritizedLanguageCodes();
     // add a secondary language
     $locale = eZLocale::instance('fre-FR');
     $translation = eZContentLanguage::addLanguage($locale->localeCode(), $locale->internationalLanguageName());
     // create related objects
     $relatedObjectsIds = array($this->createObjectForRelation(), $this->createObjectForRelation(), $this->createObjectForRelation(), $this->createObjectForRelation());
     $xmlTextEn = "<embed href=\"ezobject://{$relatedObjectsIds[0]}\" /><link href=\"ezobject://{$relatedObjectsIds[1]}\">link</link>";
     $xmlTextFr = "<embed href=\"ezobject://{$relatedObjectsIds[2]}\" /><link href=\"ezobject://{$relatedObjectsIds[3]}\">link</link>";
     // Create an article in eng-GB, and embed related object one in the intro
     $article = new ezpObject('article', 2, 14, 1, 'eng-GB');
     $article->title = __METHOD__ . ' eng-GB';
     $article->intro = $xmlTextEn;
     $articleId = $article->publish();
     // Workaround as setting folder->name directly doesn't produce the expected result
     $article->addTranslation('fre-FR', array('title' => __METHOD__ . ' fre-FR', 'intro' => $xmlTextFr));
     $relatedObjects = eZContentObject::fetch($articleId)->relatedObjects(false, false, 0, false, array('AllRelations' => eZContentObject::RELATION_LINK | eZContentObject::RELATION_EMBED));
     self::assertEquals(4, count($relatedObjects));
     $expectedRelations = array_flip($relatedObjectsIds);
     foreach ($relatedObjects as $relatedObject) {
         if (isset($expectedRelations[$relatedObject->ID])) {
             unset($expectedRelations[$relatedObject->ID]);
         }
     }
     self::assertEquals(0, count($expectedRelations));
     $article->remove();
     $translation->removeThis();
     eZContentLanguage::setPrioritizedLanguages($bkpLanguages);
 }
 public function execute($process, $event)
 {
     $params = $process->attribute('parameter_list');
     $object_id = $params['object_id'];
     $object = eZContentObject::fetch($object_id);
     if (!is_object($object)) {
         eZDebug::writeError("Unable to fetch object: '{$object_id}'", __METHOD__);
         return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
     }
     // current parent node(s)
     $parentNodeIds = $object->attribute('parent_nodes');
     $checkedObjs = array();
     foreach ($parentNodeIds as $parentNodeId) {
         //eZDebug::writeDebug( "Checking parent node: " . $parentNodeId, __METHOD__ );
         $parentNode = eZContentObjectTreeNode::fetch($parentNodeId);
         $parentObj = $parentNode->attribute('object');
         if (!in_array($parentObj->attribute('id'), $checkedObjs)) {
             //eZDebug::writeDebug( "Checking all nodes of parent obj: " . $parentObj->attribute( 'id' ), __METHOD__ );
             foreach ($parentObj->attribute('assigned_nodes') as $node) {
                 if (!in_array($node->attribute('node_id'), $parentNodeIds)) {
                     //eZDebug::writeDebug( "Found a node which is not parent of current obj: " . $node->attribute( 'node_id' ), __METHOD__ );
                     // the current obj has no node which is children of the given node of one of its parent objects
                     $operationResult = eZOperationHandler::execute('content', 'addlocation', array('node_id' => $object->attribute('main_node_id'), 'object_id' => $object->attribute('id'), 'select_node_id_array' => array($node->attribute('node_id'))), null, true);
                     if ($operationResult == null || $operationResult['status'] != true) {
                         eZDebug::writeError("Unable to add new location to object: " . $object->attribute('id'), __METHOD__);
                     }
                 } else {
                     //eZDebug::writeDebug( "Found a node which is already parent of current obj: " . $node->attribute( 'node_id' ), __METHOD__ );
                 }
             }
         }
         $checkedObjs[] = $parentObj->attribute('id');
     }
     return eZWorkflowType::STATUS_ACCEPTED;
 }
 /**
  * @group issue18073
  * @link http://issues.ez.no/18073
  */
 public function testUnauthorizedContentByObject()
 {
     $this->setExpectedException('ezpContentAccessDeniedException');
     // Let's take content node #5 / object #4 (users) as unauthorized content for anonymous user
     $unauthorizedObjectID = 4;
     $content = ezpContent::fromObject(eZContentObject::fetch($unauthorizedObjectID));
 }
 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());
     }
 }
 static function remove($objectID, $removeSubtrees = true)
 {
     eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     $object = eZContentObject::fetch($objectID);
     if (!is_object($object)) {
         return false;
     }
     // TODO: Is content cache cleared for all objects in subtree ??
     if ($removeSubtrees) {
         $assignedNodes = $object->attribute('assigned_nodes');
         if (count($assignedNodes) == 0) {
             $object->purge();
             eZContentObject::expireAllViewCache();
             return true;
         }
         $assignedNodeIDArray = array();
         foreach ($assignedNodes as $node) {
             $assignedNodeIDArray[] = $node->attribute('node_id');
         }
         eZContentObjectTreeNode::removeSubtrees($assignedNodeIDArray, false);
     } else {
         $object->purge();
     }
     return true;
 }
function feZMetaData_ContentActionHandler( &$module, &$http, &$objectID )
{
	// Action when user clicks on the Add Button
	if( $http->hasPostVariable( 'AddMetaDataButton' ) )
	{
		$link = 'fezmetadata/edit/0/(contentObjectID)/'.$objectID;
		$link .= '/(metaDataName)/'.$_POST['metaDataName'];
		$link .= '/(language)/'.$_POST['language'];
		eZURI::transformURI( $link );
		$http->redirect( $link );
	}

	// Action when user clicks on the Remove Button
	if( $http->hasPostVariable( 'RemoveMetaDataButton' ) and $http->hasPostVariable( 'MetaDataIDSelection' ) )
	{
		$metaDataSelection = $http->postVariable( 'MetaDataIDSelection' );
		foreach( $metaDataSelection as $metaData )
		{
			$metaDataObject = feZMetaData::fetch( $metaData );
			$metaDataObject->remove();
		}
		eZContentCacheManager::clearContentCache( $objectID );
		$ContentObject = eZContentObject::fetch( $objectID );
		$ContentNodeID = $ContentObject->mainNodeID();
		return $module->redirect( 'content', 'view', array( 'full', $ContentNodeID ) );
	}
}
Esempio n. 16
0
 public function execute($process, $event)
 {
     $processParameters = $process->attribute('parameter_list');
     $object = eZContentObject::fetch($processParameters['object_id']);
     $targetClassIdentifier = $object->contentClass()->attribute('identifier');
     $iniGroups = eZINI::instance('ngindexer.ini')->groups();
     $targets = array();
     foreach ($iniGroups as $iniGroupName => $iniGroup) {
         $iniGroupNameArray = explode('/', $iniGroupName);
         if (is_array($iniGroupNameArray) && count($iniGroupNameArray) == 3) {
             $class = eZContentClass::fetchByIdentifier($iniGroupNameArray[0]);
             if ($class instanceof eZContentClass) {
                 $classAttribute = $class->fetchAttributeByIdentifier($iniGroupNameArray[1]);
                 if ($classAttribute instanceof eZContentClassAttribute) {
                     $indexTarget = isset($iniGroup['IndexTarget']) ? trim($iniGroup['IndexTarget']) : '';
                     $referencedClassIdentifiers = isset($iniGroup['ClassIdentifiers']) && is_array($iniGroup['ClassIdentifiers']) ? $iniGroup['ClassIdentifiers'] : null;
                     if ($referencedClassIdentifiers != null && (empty($referencedClassIdentifiers) || in_array($targetClassIdentifier, $referencedClassIdentifiers))) {
                         switch ($indexTarget) {
                             case 'parent':
                             case 'parent_line':
                                 $children = eZContentObjectTreeNode::subTreeByNodeID(array('ClassFilterType' => 'include', 'ClassFilterArray' => array($iniGroupNameArray[0]), 'Depth' => $indexTarget == 'parent' ? 1 : false), $object->mainNode()->attribute('node_id'));
                                 if (is_array($children)) {
                                     $targets = array_merge($targets, $children);
                                 }
                                 break;
                             case 'children':
                                 $parentNode = $object->mainNode()->fetchParent();
                                 if ($parentNode->classIdentifier() == $iniGroupNameArray[0]) {
                                     $targets[] = $parentNode;
                                 }
                                 break;
                             case 'subtree':
                                 $path = $object->mainNode()->fetchPath();
                                 foreach ($path as $pathNode) {
                                     if ($pathNode->classIdentifier() == $iniGroupNameArray[0]) {
                                         $targets[] = $parentNode;
                                     }
                                 }
                                 break;
                             default:
                                 continue;
                         }
                     }
                 }
             }
         }
     }
     $filteredTargets = array();
     foreach ($targets as $target) {
         $objectID = $target->attribute('contentobject_id');
         $version = $target->object()->attribute('current_version');
         if (!isset($filteredTargets[$objectID])) {
             $filteredTargets[$objectID] = $version;
             eZContentOperationCollection::registerSearchObject($objectID, $version);
         }
     }
     return eZWorkflowType::STATUS_ACCEPTED;
 }
 public static function execute($exclusiveParentID = 1)
 {
     $db = eZDB::instance();
     $cli = eZCLI::instance();
     //1. delete the assignments from eznode_assignment table
     // delete the assignments which don't have relevant entry in ezconentobject_tree
     // select the data that doesn't exist in either eznode_assignment or ezcontentobject_tree
     $deletedAssignmentList = $db->arrayQuery("SELECT * FROM eznode_assignment WHERE id NOT IN " . "(SELECT assign.id FROM eznode_assignment assign, ezcontentobject_tree tree WHERE " . "assign.contentobject_id = tree.contentobject_id AND assign.parent_node = tree.parent_node_id)");
     $deletedCount = 0;
     foreach ($deletedAssignmentList as $deletedAssignment) {
         // select the content object which is published.
         //If the object of the assignment is in trash or draft, it's not the one to be deleted
         $tempAssignID = $deletedAssignment["id"];
         $content = eZContentObject::fetch($deletedAssignment["contentobject_id"], false);
         if ($content && $deletedAssignment['parent_node'] != $exclusiveParentID) {
             if ($content["status"] == eZContentObject::STATUS_PUBLISHED) {
                 // iterate the data to be deleted, delete them
                 $cli->notice('Node assignment [ id: ' . $deletedAssignment['id'] . ' ] for contentobject [ id: ' . $deletedAssignment['contentobject_id'] . ' ] is not consistent with entries in contentobject_tree' . ' table thus will be removed.');
                 $sql = "DELETE FROM eznode_assignment WHERE id = " . $tempAssignID;
                 $result = $db->query($sql);
                 if ($result === false) {
                     $cli->notice('Node assignment [ id: ' . $deletedAssignment['id'] . ' ] ' . 'could not be removed. Please restore your database from backup and try again.');
                     return;
                 }
                 $deletedCount++;
             }
         }
     }
     //2. Delete the duplicated entries which have same contentobject_id, contentobject_version and is_main
     // The process of deleting duplicated entries deletes the old entries, keeps the latest entry in the
     // duplicated entry list.
     $tempDeleteList = array();
     $duplicatedContentList = $db->arrayQuery("SELECT contentobject_id, contentobject_version, is_main, parent_node\n                                              FROM eznode_assignment\n                                              GROUP BY contentobject_id, contentobject_version, is_main, parent_node\n                                              HAVING COUNT(*) > 1");
     foreach ($duplicatedContentList as $duplicatedContent) {
         $assignmentList = $db->arrayQuery("SELECT * FROM eznode_assignment" . " WHERE contentobject_id = " . $duplicatedContent['contentobject_id'] . " AND contentobject_version = " . $duplicatedContent["contentobject_version"] . " AND parent_node =" . $duplicatedContent["parent_node"] . " ORDER BY id DESC");
         $assignmentListCount = count($assignmentList);
         //Find the duplicated entries( array index start from 1 ) and delete them. Leave the one entry( array index is 0 )
         for ($i = 1; $i < $assignmentListCount; $i++) {
             if ($assignmentList[$i]["parent_node"] != $exclusiveParentID) {
                 $tempAssignID = $assignmentList[$i]["id"];
                 $cli->notice('Node assignment [ id: ' . $tempAssignID . ' ] for contentobject [ id: ' . $assignmentList[$i]["contentobject_id"] . '] is duplicated thus will be removed.');
                 $sql = "DELETE FROM eznode_assignment WHERE id = " . $tempAssignID;
                 $result = $db->query($sql);
                 if ($result === false) {
                     $cli->notice('Node assignment [ id: ' . $tempAssignID . ' ] ' . 'could not be removed. Please restore your database from backup and try again.');
                     return;
                 }
                 $deletedCount++;
             }
         }
     }
     if ($deletedCount != 0) {
         $cli->output($deletedCount . ' node assignments have been deleted.');
     } else {
         $cli->output('None of available node assignments has been deleted.');
     }
 }
Esempio n. 18
0
 static function validateContentObjectId($id)
 {
     if (is_numeric($id) && 0 < (int) $id) {
         $id = (int) $id;
         if (eZContentObject::fetch($id, false)) {
             return true;
         }
     }
     return false;
 }
    /**
     * Wrong use of array_intersect() in ezsubtreenotificationrule.php
     *
     * @link http://issues.ez.no/16248
     */
    public function testCorrectUsageArrayIntersect()
    {
        $access = eZSubtreeNotificationRule::checkObjectAccess(
            eZContentObject::fetch( 1 ),
            $this->policy->attribute( 'id' ),
            array( 14 )
        );

        $this->assertEquals( array( 14 ), $access );
    }
 /**
  * Test for issue #16322: eZTextFileUser makes user names with newline (with patch)
  */
 public function testLoginCorrect()
 {
     $userClass = eZUserLoginHandler::instance('textfile');
     $user = $userClass->loginUser($this->username, $this->password);
     // the username and password were accepted
     $this->assertEquals(true, $user instanceof eZUser);
     // check that the name doesn't contain new line at the end
     $userObject = eZContentObject::fetch($user->ContentObjectID);
     $this->assertEquals($this->firstname . ' ' . $this->lastname, $userObject->Name);
 }
 function contentObject()
 {
     if ($this->ContentObject === null) {
         if ($this->ContentObjectID == 0) {
             return null;
         }
         $this->ContentObject = eZContentObject::fetch($this->ContentObjectID);
     }
     return $this->ContentObject;
 }
    function execute( $process, $event )
    {
        $parameters = $process->attribute( 'parameter_list' );
        $object = eZContentObject::fetch( $parameters['object_id'] );

        if ( !$object )
        {
            eZDebugSetting::writeError( 'kernel-workflow-waituntildate','The object with ID '.$parameters['object_id'].' does not exist.', 'eZApproveType::execute() object is unavailable' );
            return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
        }

        $version = $object->version( $parameters['version'] );
        $objectAttributes = $version->attribute( 'contentobject_attributes' );
        $waitUntilDateObject = $this->workflowEventContent( $event );
        $waitUntilDateEntryList = $waitUntilDateObject->attribute( 'classattribute_id_list' );
        $modifyPublishDate = $event->attribute( 'data_int1' );

        foreach ( array_keys( $objectAttributes ) as $key )
        {
            $objectAttribute = $objectAttributes[$key];
            $contentClassAttributeID = $objectAttribute->attribute( 'contentclassattribute_id' );
            if ( in_array( $objectAttribute->attribute( 'contentclassattribute_id' ), $waitUntilDateEntryList ) )
            {
                $dateTime = $objectAttribute->attribute( 'content' );
                if ( $dateTime instanceof eZDateTime or
                     $dateTime instanceof eZTime or
                     $dateTime instanceof eZDate )
                {
                    if ( time() < $dateTime->timeStamp() )
                    {
                        $this->setInformation( "Event delayed until " . $dateTime->toString( true ) );
                        $this->setActivationDate( $dateTime->timeStamp() );
                        return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
                    }
                    else if ( $dateTime->isValid() and $modifyPublishDate )
                    {
                        $object->setAttribute( 'published', $dateTime->timeStamp() );
                        $object->store();
                    }
                    else
                    {
                        return eZWorkflowType::STATUS_ACCEPTED;
//                        return eZWorkflowType::STATUS_WORKFLOW_DONE;
                    }
                }
                else
                {
                    return eZWorkflowType::STATUS_ACCEPTED;
//                   return eZWorkflowType::STATUS_WORKFLOW_DONE;
                }
            }
        }
        return eZWorkflowType::STATUS_ACCEPTED;
//        return eZWorkflowType::STATUS_WORKFLOW_DONE;
    }
 public function execute($process, $event)
 {
     $parameters = $process->attribute('parameter_list');
     try {
         // WORKFLOW HERE
         if ($parameters['trigger_name'] == 'post_updateobjectstate') {
             $objectId = $parameters['object_id'];
             $object = eZContentObject::fetch($objectId);
             $parentStateIDArray = $object->stateIDArray();
             $fetch_parameters = array('parent_node_id' => $object->mainNodeID());
             $childs = eZFunctionHandler::execute('content', 'list', $fetch_parameters);
             $stateGroups = eZINI::instance('patbase.ini')->variable('ChildsPropagationState', 'StateGroupID');
             foreach ($childs as $child) {
                 $childStateIDArray = $child->object()->stateIDArray();
                 $stateChanged = FALSE;
                 foreach ($stateGroups as $stateGroup) {
                     if ($childStateIDArray[$stateGroup] !== $parentStateIDArray[$stateGroup]) {
                         $stateChanged = TRUE;
                         $childStateIDArray[$stateGroup] = $parentStateIDArray[$stateGroup];
                     }
                 }
                 if ($stateChanged) {
                     eZOperationHandler::execute('content', 'updateobjectstate', array('object_id' => $child->ContentObjectID, 'state_id_list' => $childStateIDArray));
                 }
             }
         } else {
             if ($parameters['trigger_name'] == 'post_publish') {
                 if ($parameters['version'] === '1') {
                     $objectId = $parameters['object_id'];
                     $object = eZContentObject::fetch($objectId);
                     $objectStateIDArray = $object->stateIDArray();
                     $fetch_parameters = array('node_id' => $object->mainParentNodeID());
                     $parent = eZFunctionHandler::execute('content', 'node', $fetch_parameters);
                     $stateGroups = eZINI::instance('patbase.ini')->variable('ChildsPropagationState', 'StateGroupID');
                     $parentStateIDArray = $parent->object()->stateIDArray();
                     $stateChanged = FALSE;
                     foreach ($stateGroups as $stateGroup) {
                         if ($objectStateIDArray[$stateGroup] !== $parentStateIDArray[$stateGroup]) {
                             $stateChanged = TRUE;
                             $objectStateIDArray[$stateGroup] = $parentStateIDArray[$stateGroup];
                         }
                     }
                     if ($stateChanged) {
                         eZOperationHandler::execute('content', 'updateobjectstate', array('object_id' => $objectId, 'state_id_list' => $objectStateIDArray));
                     }
                 }
             }
         }
         //
         return eZWorkflowType::STATUS_ACCEPTED;
     } catch (Exception $e) {
         eZDebug::writeError($e->getMessage(), __METHOD__);
         return eZWorkflowType::STATUS_REJECTED;
     }
 }
Esempio n. 24
0
 public function getRelatedObjects($handleObjectId)
 {
     $return = array();
     $eZObj = eZContentObject::fetch($handleObjectId);
     $parentNode = $eZObj->attribute('main_node');
     $children = $parentNode->attribute('children');
     foreach ($children as $child) {
         $return[] = $child->attribute('object');
     }
     return $return;
 }
 function execute($process, $event)
 {
     $user = eZUser::currentUser();
     if ($user->isLoggedIn()) {
         return eZWorkflowType::STATUS_ACCEPTED;
     }
     $http = eZHTTPTool::instance();
     // Get current content object ID.
     $parameters = $process->attribute('parameter_list');
     $nodeID = $parameters['node_id'];
     $node = eZContentObjectTreeNode::fetch($nodeID);
     if (!$node) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $objectID = $node->attribute('contentobject_id');
     // Get newsletter hash
     $uri = $GLOBALS['eZRequestedURI'];
     $userParameters = $uri->userParameters();
     $hash = isset($userParameters['hash']) ? $userParameters['hash'] : false;
     $sendItem = eZSendNewsletterItem::fetchByHash($hash);
     if ($http->hasSessionVariable('NewsletterNodeIDArray')) {
         $globalNodeIDList = $http->sessionVariable('NewsletterNodeIDArray');
         if (in_array($nodeID, $http->sessionVariable('NewsletterNodeIDArray'))) {
             $sendID = $http->sessionVariable('NewletterNodeMap_' . $nodeID);
             $sendItem = eZSendNewsletterItem::fetch($sendID);
             $sendItem->addObjectRead($objectID);
             return eZWorkflowType::STATUS_ACCEPTED;
         }
     }
     // Get send item, and check that is contains the object id.
     if (!$sendItem) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $sendItemIDList = $sendItem->attribute('newsletter_related_object_list');
     if (!$sendItemIDList || !in_array($objectID, $sendItemIDList)) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $sendNodeIDArray = array();
     // Set session variables
     foreach ($sendItemIDList as $sendObjectID) {
         $sendObject = eZContentObject::fetch($sendObjectID);
         if ($sendObject) {
             foreach ($sendObject->assignedNodes(false) as $nodeArray) {
                 $http->setSessionVariable('NewletterNodeMap_' . $nodeArray['node_id'], $sendItem->attribute('id'));
                 $sendNodeIDArray[] = $nodeArray['node_id'];
             }
         }
     }
     $globalNodeIDList = array_unique(array_merge($globalNodeIDList, $sendNodeIDArray));
     $http->setSessionVariable('NewsletterNodeIDArray', $globalNodeIDList);
     // Add object read
     $sendItem->addObjectRead($objectID);
     return eZWorkflowType::STATUS_ACCEPTED;
 }
Esempio n. 26
0
 function getContentClassCollectorAttributes($objectID)
 {
     $formObject = eZContentObject::fetch($objectID);
     $formObjectClass = $formObject->contentClass();
     $contentClassAttributes = $formObjectClass->fetchAttributes();
     $this->contentClassCollectorAttributes = array();
     foreach ($contentClassAttributes as $contentClassAttribute) {
         if ($contentClassAttribute->attribute('is_information_collector')) {
             array_push($this->contentClassCollectorAttributes, $contentClassAttribute->attribute('id'));
         }
     }
 }
Esempio n. 27
0
 function execute($process, $event)
 {
     //execute user register operation
     $parameterList = $process->attribute('parameter_list');
     $objectID = $parameterList['object_id'];
     $object = eZContentObject::fetch($objectID);
     // @todo: improve the possible performance.
     if ($object->attribute('class_identifier') == 'user') {
         $result = eZOperationHandler::execute('user', 'register', array('user_id' => $objectID));
         return $result['status'];
     }
 }
 /**
  * Regression test for issue #15155
  *
  * @link http://issues.ez.no/15155
  */
 public function testIssue15155()
 {
     // figure out the max versions for images
     $contentINI = eZINI::instance('content.ini');
     $versionlimit = $contentINI->variable('VersionManagement', 'DefaultVersionHistoryLimit');
     $limitList = eZContentClass::classIDByIdentifier($contentINI->variable('VersionManagement', 'VersionHistoryClass'));
     $classID = 5;
     // image class, can remain hardcoded, I guess
     foreach ($limitList as $key => $value) {
         if ($classID == $key) {
             $versionlimit = $value;
         }
     }
     if ($versionlimit < 2) {
         $versionlimit = 2;
     }
     $baseImagePath = dirname(__FILE__) . '/ezimagealiashandler_regression_issue15155.png';
     $parts = pathinfo($baseImagePath);
     $imagePattern = $parts['dirname'] . DIRECTORY_SEPARATOR . $parts['filename'] . '_%s_%d.' . $parts['extension'];
     $toDelete = array();
     // Create version 1
     $imagePath = sprintf($imagePattern, md5(1), 1);
     copy($baseImagePath, $imagePath);
     $toDelete[] = $imagePath;
     $image = new ezpObject('image', 43);
     $image->name = __FUNCTION__;
     $image->image = $imagePath;
     $image->publish();
     $image->refresh();
     $contentObjectID = $image->object->attribute('id');
     $dataMap = eZContentObject::fetch($contentObjectID)->dataMap();
     $originalAliases[1] = $image->image->imageAlias('original');
     for ($i = 2; $i <= 20; $i++) {
         // Create a new image file
         $imagePath = sprintf($imagePattern, md5($i), $i);
         copy($baseImagePath, $imagePath);
         $toDelete[] = $imagePath;
         $newVersion = $image->createNewVersion();
         $dataMap = $newVersion->dataMap();
         $dataMap['image']->fromString($imagePath);
         ezpObject::publishContentObject($image->object, $newVersion);
         $image->refresh();
         $originalAliases[$i] = $image->image->imageAlias('original');
         if ($i > $versionlimit) {
             $removeVersion = $i - $versionlimit;
             $aliasPath = $originalAliases[$removeVersion]['url'];
             $this->assertFalse(file_exists($aliasPath), "Alias {$aliasPath} for version {$removeVersion} should have been removed");
         }
     }
     array_map('unlink', $toDelete);
     $image->purge();
 }
 function exportAttribute(&$attribute, $seperationChar)
 {
     eZDebug::writeDebug($attribute, "SMILE");
     $content = $attribute->content();
     $relation_list = $content['relation_list'];
     eZDebug::writeDebug($content, "SMILE");
     $names = array();
     foreach ($relation_list as $relation) {
         $object = eZContentObject::fetch($relation['contentobject_id']);
         $names[] = $object->name();
     }
     return $this->escape(join(" ", $names), $seperationChar);
 }
    /**
     * @param eZContentObjectTreeNode $node
     * @return string
     */
    public function getNodeUrl(&$node = null)
    {
        $dataMap                        = $node->dataMap();
        $mediaContentAttribute          = $dataMap['media_content'];
        $mediaContentAttributeContent   = $mediaContentAttribute->content();
        $linkObjectID                   = $mediaContentAttributeContent['relation_list'][0]['contentobject_id'];
        $linkObject                     = eZContentObject::fetch( $linkObjectID );
        $linkDatamap                    = $linkObject->dataMap();
        $url                            = $linkDatamap['url']->content();
        $delimiter                      = ( strpos($url, '?') === false ) ? '?' : '&';
        $url                           .= $delimiter.'ID=mmed45652&PASSWORD=medicus&NEWS=n';

        return $url;
    }