/**
     * Test that saving a content class in DEFINED version status
     * correctly manipulate associated class groups
     *
     * @link http://issues.ez.no/16197
     */
    public function testContentClassStillInGroupAfterEdition()
    {
        $class = eZContentClass::fetch( $this->class->id );
        // This is logic contained in kernel/class/edit.php
        foreach ( eZContentClassClassGroup::fetchGroupList( $class->attribute( 'id' ),
                                                            eZContentClass::VERSION_STATUS_DEFINED )  as $classGroup )
        {
            eZContentClassClassGroup::create( $class->attribute( 'id' ),
                                              eZContentClass::VERSION_STATUS_TEMPORARY,
                                              $classGroup->attribute( 'group_id' ),
                                              $classGroup->attribute( 'group_name' ) )
                ->store();
        }

        $attributes = $class->fetchAttributes();
        $class->setAttribute( 'version', eZContentClass::VERSION_STATUS_TEMPORARY );
        $class->NameList->setHasDirtyData();

        foreach ( $attributes as $attribute )
        {
            $attribute->setAttribute( 'version', eZContentClass::VERSION_STATUS_TEMPORARY );
            if ( $dataType = $attribute->dataType() )
                $dataType->initializeClassAttribute( $attribute );
        }

        $class->store( $attributes );
        $db = eZDB::instance();
        $db->begin();
        $class->storeVersioned( $attributes, eZContentClass::VERSION_STATUS_DEFINED );
        $db->commit();

        $this->assertTrue( eZContentClassClassGroup::classInGroup( $class->attribute( 'id' ),
                                                                   eZContentClass::VERSION_STATUS_DEFINED,
                                                                   1 ) );
    }
Exemplo n.º 2
0
 static function classDOMTree($class)
 {
     if (!$class) {
         $retValue = false;
         return $retValue;
     }
     $dom = new DOMDocument('1.0', 'utf-8');
     $classNode = $dom->createElement('content-class');
     $dom->appendChild($classNode);
     $serializedNameListNode = $dom->createElement('serialized-name-list');
     $serializedNameListNode->appendChild($dom->createTextNode($class->attribute('serialized_name_list')));
     $classNode->appendChild($serializedNameListNode);
     $identifierNode = $dom->createElement('identifier');
     $identifierNode->appendChild($dom->createTextNode($class->attribute('identifier')));
     $classNode->appendChild($identifierNode);
     $serializedDescriptionListNode = $dom->createElement('serialized-description-list');
     $serializedDescriptionListNode->appendChild($dom->createTextNode($class->attribute('serialized_description_list')));
     $classNode->appendChild($serializedDescriptionListNode);
     $remoteIDNode = $dom->createElement('remote-id');
     $remoteIDNode->appendChild($dom->createTextNode($class->attribute('remote_id')));
     $classNode->appendChild($remoteIDNode);
     $objectNamePatternNode = $dom->createElement('object-name-pattern');
     $objectNamePatternNode->appendChild($dom->createTextNode($class->attribute('contentobject_name')));
     $classNode->appendChild($objectNamePatternNode);
     $urlAliasPatternNode = $dom->createElement('url-alias-pattern');
     $urlAliasPatternNode->appendChild($dom->createTextNode($class->attribute('url_alias_name')));
     $classNode->appendChild($urlAliasPatternNode);
     $isContainer = $class->attribute('is_container') ? 'true' : 'false';
     $classNode->setAttribute('is-container', $isContainer);
     $classNode->setAttribute('always-available', $class->attribute('always_available') ? 'true' : 'false');
     $classNode->setAttribute('sort-field', eZContentObjectTreeNode::sortFieldName($class->attribute('sort_field')));
     $classNode->setAttribute('sort-order', $class->attribute('sort_order'));
     // Remote data start
     $remoteNode = $dom->createElement('remote');
     $classNode->appendChild($remoteNode);
     $ini = eZINI::instance();
     $siteName = $ini->variable('SiteSettings', 'SiteURL');
     $classURL = 'http://' . $siteName . '/class/view/' . $class->attribute('id');
     $siteURL = 'http://' . $siteName . '/';
     $siteUrlNode = $dom->createElement('site-url');
     $siteUrlNode->appendChild($dom->createTextNode($siteURL));
     $remoteNode->appendChild($siteUrlNode);
     $urlNode = $dom->createElement('url');
     $urlNode->appendChild($dom->createTextNode($classURL));
     $remoteNode->appendChild($urlNode);
     $classGroupsNode = $dom->createElement('groups');
     $classGroupList = eZContentClassClassGroup::fetchGroupList($class->attribute('id'), $class->attribute('version'));
     foreach ($classGroupList as $classGroupLink) {
         $classGroup = eZContentClassGroup::fetch($classGroupLink->attribute('group_id'));
         if ($classGroup) {
             unset($groupNode);
             $groupNode = $dom->createElement('group');
             $groupNode->setAttribute('id', $classGroup->attribute('id'));
             $groupNode->setAttribute('name', $classGroup->attribute('name'));
             $classGroupsNode->appendChild($groupNode);
         }
     }
     $remoteNode->appendChild($classGroupsNode);
     $idNode = $dom->createElement('id');
     $idNode->appendChild($dom->createTextNode($class->attribute('id')));
     $remoteNode->appendChild($idNode);
     $createdNode = $dom->createElement('created');
     $createdNode->appendChild($dom->createTextNode($class->attribute('created')));
     $remoteNode->appendChild($createdNode);
     $modifiedNode = $dom->createElement('modified');
     $modifiedNode->appendChild($dom->createTextNode($class->attribute('modified')));
     $remoteNode->appendChild($modifiedNode);
     $creatorNode = $dom->createElement('creator');
     $remoteNode->appendChild($creatorNode);
     $creatorIDNode = $dom->createElement('user-id');
     $creatorIDNode->appendChild($dom->createTextNode($class->attribute('creator_id')));
     $creatorNode->appendChild($creatorIDNode);
     $creator = $class->attribute('creator');
     if ($creator) {
         $creatorLoginNode = $dom->createElement('user-login');
         $creatorLoginNode->appendChild($dom->createTextNode($creator->attribute('login')));
         $creatorNode->appendChild($creatorLoginNode);
     }
     $modifierNode = $dom->createElement('modifier');
     $remoteNode->appendChild($modifierNode);
     $modifierIDNode = $dom->createElement('user-id');
     $modifierIDNode->appendChild($dom->createTextNode($class->attribute('modifier_id')));
     $modifierNode->appendChild($modifierIDNode);
     $modifier = $class->attribute('modifier');
     if ($modifier) {
         $modifierLoginNode = $dom->createElement('user-login');
         $modifierLoginNode->appendChild($dom->createTextNode($modifier->attribute('login')));
         $modifierNode->appendChild($modifierLoginNode);
     }
     // Remote data end
     $attributesNode = $dom->createElementNS('http://ezpublish/contentclassattribute', 'ezcontentclass-attribute:attributes');
     $classNode->appendChild($attributesNode);
     $attributes = $class->fetchAttributes();
     foreach ($attributes as $attribute) {
         $attributeNode = $dom->createElement('attribute');
         $attributeNode->setAttribute('datatype', $attribute->attribute('data_type_string'));
         $required = $attribute->attribute('is_required') ? 'true' : 'false';
         $attributeNode->setAttribute('required', $required);
         $searchable = $attribute->attribute('is_searchable') ? 'true' : 'false';
         $attributeNode->setAttribute('searchable', $searchable);
         $informationCollector = $attribute->attribute('is_information_collector') ? 'true' : 'false';
         $attributeNode->setAttribute('information-collector', $informationCollector);
         $translatable = $attribute->attribute('can_translate') ? 'true' : 'false';
         $attributeNode->setAttribute('translatable', $translatable);
         $attributeRemoteNode = $dom->createElement('remote');
         $attributeNode->appendChild($attributeRemoteNode);
         $attributeIDNode = $dom->createElement('id');
         $attributeIDNode->appendChild($dom->createTextNode($attribute->attribute('id')));
         $attributeRemoteNode->appendChild($attributeIDNode);
         $attributeSerializedNameListNode = $dom->createElement('serialized-name-list');
         $attributeSerializedNameListNode->appendChild($dom->createTextNode($attribute->attribute('serialized_name_list')));
         $attributeNode->appendChild($attributeSerializedNameListNode);
         $attributeIdentifierNode = $dom->createElement('identifier');
         $attributeIdentifierNode->appendChild($dom->createTextNode($attribute->attribute('identifier')));
         $attributeNode->appendChild($attributeIdentifierNode);
         $attributeSerializedDescriptionListNode = $dom->createElement('serialized-description-list');
         $attributeSerializedDescriptionListNode->appendChild($dom->createTextNode($attribute->attribute('serialized_description_list')));
         $attributeNode->appendChild($attributeSerializedDescriptionListNode);
         $attributeCategoryNode = $dom->createElement('category');
         $attributeCategoryNode->appendChild($dom->createTextNode($attribute->attribute('category')));
         $attributeNode->appendChild($attributeCategoryNode);
         $attributeSerializedDataTextNode = $dom->createElement('serialized-data-text');
         $attributeSerializedDataTextNode->appendChild($dom->createTextNode($attribute->attribute('serialized_data_text')));
         $attributeNode->appendChild($attributeSerializedDataTextNode);
         $attributePlacementNode = $dom->createElement('placement');
         $attributePlacementNode->appendChild($dom->createTextNode($attribute->attribute('placement')));
         $attributeNode->appendChild($attributePlacementNode);
         $attributeParametersNode = $dom->createElement('datatype-parameters');
         $attributeNode->appendChild($attributeParametersNode);
         $dataType = $attribute->dataType();
         if (is_object($dataType)) {
             $dataType->serializeContentClassAttribute($attribute, $attributeNode, $attributeParametersNode);
         }
         $attributesNode->appendChild($attributeNode);
     }
     eZDebug::writeDebug($dom->saveXML(), 'content class package XML');
     return $classNode;
 }
Exemplo n.º 3
0
 /**
  * Stores the current class as a modified version, updates the contentobject_name
  * attribute and recreates the class group entries.
  *
  * @note It will remove classes in the previous and specified version before storing.
  *
  * @param array $attributes array of attributes
  * @param int $version version status
  * @since Version 4.3
  */
 public function storeVersioned($attributes, $version)
 {
     $previousVersion = $this->attribute('version');
     $db = eZDB::instance();
     $db->begin();
     // Before removing anything from the attributes, load attribute information
     // which might otherwise not accessible when recreating them below.
     // See issue #18164
     foreach ($attributes as $attribute) {
         $attribute->content();
     }
     $this->removeAttributes(false, $version);
     $this->removeAttributes(false, $previousVersion);
     $this->remove(false);
     $this->setVersion($version, $attributes);
     $this->setAttribute("modifier_id", eZUser::currentUser()->attribute("contentobject_id"));
     $this->setAttribute("modified", time());
     $this->adjustAttributePlacements($attributes);
     foreach ($attributes as $attribute) {
         $attribute->storeVersioned($version);
     }
     // Set contentobject_name to something sensible if it is missing
     if (count($attributes) > 0 && trim($this->attribute('contentobject_name')) == '') {
         $this->setAttribute('contentobject_name', '<' . $attributes[0]->attribute('identifier') . '>');
     }
     // Recreate class member entries
     eZContentClassClassGroup::removeClassMembers($this->ID, $version);
     foreach (eZContentClassClassGroup::fetchGroupList($this->ID, $previousVersion) as $classgroup) {
         $classgroup->setAttribute('contentclass_version', $version);
         $classgroup->store();
     }
     eZContentClassClassGroup::removeClassMembers($this->ID, $previousVersion);
     eZExpiryHandler::registerShutdownFunction();
     $handler = eZExpiryHandler::instance();
     $time = time();
     $handler->setTimestamp('user-class-cache', $time);
     $handler->setTimestamp('class-identifier-cache', $time);
     $handler->setTimestamp('sort-key-cache', $time);
     $handler->store();
     eZContentCacheManager::clearAllContentCache();
     $this->setAttribute('serialized_name_list', $this->NameList->serializeNames());
     $this->setAttribute('serialized_description_list', $this->DescriptionList->serializeNames());
     eZPersistentObject::store();
     $this->NameList->store($this);
     $db->commit();
 }
Exemplo n.º 4
0
$Module = $Params['Module'];
$http = eZHTTPTool::instance();
$deleteIDArray = $http->hasSessionVariable('DeleteGroupIDArray') ? $http->sessionVariable('DeleteGroupIDArray') : array();
$groupsInfo = array();
$deleteResult = array();
$deleteClassIDList = array();
foreach ($deleteIDArray as $deleteID) {
    $deletedClassName = '';
    $group = eZContentClassGroup::fetch($deleteID);
    if ($group != null) {
        $GroupName = $group->attribute('name');
        $classList = eZContentClassClassGroup::fetchClassList(null, $deleteID);
        $groupClassesInfo = array();
        foreach ($classList as $class) {
            $classID = $class->attribute("id");
            $classGroups = eZContentClassClassGroup::fetchGroupList($classID, 0);
            if (count($classGroups) == 1) {
                $classObject = eZContentclass::fetch($classID);
                $className = $classObject->attribute("name");
                $deletedClassName .= " '" . $className . "'";
                $deleteClassIDList[] = $classID;
                $groupClassesInfo[] = array('class_name' => $className, 'object_count' => $classObject->objectCount());
            }
        }
        if ($deletedClassName == '') {
            $deletedClassName = ezpI18n::tr('kernel/class', '(no classes)');
        }
        $deleteResult[] = array('groupName' => $GroupName, 'deletedClassName' => $deletedClassName);
        $groupsInfo[] = array('group_name' => $GroupName, 'class_list' => $groupClassesInfo);
    }
}
Exemplo n.º 5
0
//
$Module = $Params['Module'];
$ClassID = null;
if (isset($Params["ClassID"])) {
    $ClassID = $Params["ClassID"];
}
$class = eZContentClass::fetch($ClassID, true, 0);
if (!$class) {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE);
}
$classCopy = clone $class;
$classCopy->initializeCopy($class);
$classCopy->setAttribute('version', eZContentClass::VERSION_STATUS_MODIFIED);
$classCopy->store();
$mainGroupID = false;
$classGroups = eZContentClassClassGroup::fetchGroupList($class->attribute('id'), $class->attribute('version'));
for ($i = 0; $i < count($classGroups); ++$i) {
    $classGroup =& $classGroups[$i];
    $classGroup->setAttribute('contentclass_id', $classCopy->attribute('id'));
    $classGroup->setAttribute('contentclass_version', $classCopy->attribute('version'));
    $classGroup->store();
    if ($mainGroupID === false) {
        $mainGroupID = $classGroup->attribute('group_id');
    }
}
$classAttributeCopies = array();
$classAttributes = $class->fetchAttributes();
foreach (array_keys($classAttributes) as $classAttributeKey) {
    $classAttribute =& $classAttributes[$classAttributeKey];
    $classAttributeCopy = clone $classAttribute;
    if ($datatype = $classAttributeCopy->dataType()) {
Exemplo n.º 6
0
if (is_numeric($ClassID)) {
    $class = eZContentClass::fetch($ClassID, true, eZContentClass::VERSION_STATUS_MODIFIED);
    if (is_object($class)) {
        $tpl = eZTemplate::factory();
        $tpl->setVariable('class', $class);
        $tpl->setVariable("access_type", $GLOBALS['eZCurrentAccess']);
        return array('content' => $tpl->fetch('design:class/edit_locked.tpl'), 'path' => array(array('url' => '/class/grouplist/', 'text' => ezpI18n::tr('kernel/class', 'Class list'))));
    }
    $class = eZContentClass::fetch($ClassID, true, eZContentClass::VERSION_STATUS_TEMPORARY);
    // If temporary version does not exist fetch the current and add temperory class to corresponding group
    if (!is_object($class) or $class->attribute('id') == null) {
        $class = eZContentClass::fetch($ClassID, true, eZContentClass::VERSION_STATUS_DEFINED);
        if ($class === null) {
            return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
        }
        $classGroups = eZContentClassClassGroup::fetchGroupList($ClassID, eZContentClass::VERSION_STATUS_DEFINED);
        foreach ($classGroups as $classGroup) {
            $groupID = $classGroup->attribute('group_id');
            $groupName = $classGroup->attribute('group_name');
            $ingroup = eZContentClassClassGroup::create($ClassID, eZContentClass::VERSION_STATUS_TEMPORARY, $groupID, $groupName);
            $ingroup->store();
        }
        if (count($classGroups) > 0) {
            $mainGroupID = $classGroups[0]->attribute('group_id');
            $mainGroupName = $classGroups[0]->attribute('group_name');
        }
    } else {
        $user = eZUser::currentUser();
        $contentIni = eZINI::instance('content.ini');
        $timeOut = $contentIni->variable('ClassSettings', 'DraftTimeout');
        $groupList = $class->fetchGroupList();
 public function sync($force = false, $removeExtras = false)
 {
     $modified = eZContentClass::fetch($this->id, true, eZContentClass::VERSION_STATUS_MODIFIED);
     if (is_object($modified)) {
         throw new Exception("Classe bloccata in modifica");
     }
     $this->compare();
     if ($this->getData()->hasError && !$force) {
         throw new Exception("La classe contiene campi che ne impediscono la sincronizzazione automatica");
     }
     $temporary = eZContentClass::fetch($this->id, true, eZContentClass::VERSION_STATUS_TEMPORARY);
     if (!is_object($temporary) or $temporary->attribute('id') == null) {
         $temporary = eZContentClass::fetch($this->id, true, eZContentClass::VERSION_STATUS_DEFINED);
         if ($temporary === null) {
             throw new Exception("La classe non esiste");
         }
         /** @var eZContentClassClassGroup[] $classGroups */
         $classGroups = eZContentClassClassGroup::fetchGroupList($this->id, eZContentClass::VERSION_STATUS_DEFINED);
         foreach ($classGroups as $classGroup) {
             $groupID = $classGroup->attribute('group_id');
             $groupName = $classGroup->attribute('group_name');
             $ingroup = eZContentClassClassGroup::create($this->id, eZContentClass::VERSION_STATUS_TEMPORARY, $groupID, $groupName);
             $ingroup->store();
         }
         if (count($classGroups) > 0) {
             $mainGroupID = $classGroups[0]->attribute('group_id');
             $mainGroupName = $classGroups[0]->attribute('group_name');
         }
     } else {
         $user = eZUser::currentUser();
         $contentIni = eZINI::instance('content.ini');
         $timeOut = $contentIni->variable('ClassSettings', 'DraftTimeout');
         /** @var eZContentClassClassGroup[] $groupList */
         $groupList = $temporary->fetchGroupList();
         if (count($groupList) > 0) {
             $mainGroupID = $groupList[0]->attribute('group_id');
             $mainGroupName = $groupList[0]->attribute('group_name');
         }
         if ($temporary->attribute('modifier_id') != $user->attribute('contentobject_id') && $temporary->attribute('modified') + $timeOut > time()) {
             throw new Exception("Modifica alla classe non permessa");
         }
     }
     /** @var eZContentClassAttribute[] $localeAttributes */
     $localeAttributes = array();
     foreach ($this->currentClass->fetchAttributes() as $attribute) {
         /** @var eZContentClassAttribute $attribute */
         $attribute->setAttribute('version', eZContentClass::VERSION_STATUS_TEMPORARY);
         $localeAttributes[$attribute->attribute('identifier')] = $attribute;
     }
     $this->currentClass->setAttribute('version', eZContentClass::VERSION_STATUS_TEMPORARY);
     $remote = $this->getRemote();
     if ($remote === null) {
         throw new Exception("Classe remota non trovata");
     }
     if ($force && $this->getData()->hasError) {
         foreach ($this->getData()->errors as $identifier => $value) {
             if (!$localeAttributes[$identifier] instanceof eZContentClassAttribute) {
                 throw new Exception('Errore forzando la sincronizzazione');
             }
             foreach ($remote->DataMap[0] as $originalAttribute) {
                 if ($originalAttribute->Identifier == $identifier) {
                     ezpEvent::getInstance()->notify('classtools/switch_class_attribute', array($localeAttributes[$identifier], $originalAttribute));
                     if ($value == 'data_type_string') {
                         $localeAttributes[$identifier]->setAttribute('data_type_string', $originalAttribute->DataTypeString);
                         $localeAttributes[$identifier]->store();
                         $this->changeContentObjectAttributeDataTypeString($localeAttributes[$identifier], $originalAttribute->DataTypeString);
                         unset($this->notifications[self::ERROR][$originalAttribute->Identifier]);
                     } else {
                         $this->data->missingAttributes[] = $originalAttribute;
                         $this->currentClass->removeAttributes(array($localeAttributes[$identifier]));
                         unset($localeAttributes[$identifier]);
                     }
                     break;
                 }
             }
         }
     }
     $attributes = array();
     foreach ($this->properties as $identifier => $remoteProperty) {
         if ($remote->{$remoteProperty} != $this->currentClass->attribute($identifier)) {
             $this->currentClass->setAttribute($identifier, $remote->{$remoteProperty});
             if ($identifier == 'serialized_name_list') {
                 $nameList = new eZContentClassNameList();
                 $nameList->initFromSerializedList($remote->{$remoteProperty});
                 $this->currentClass->NameList = $nameList;
             } elseif ($identifier == 'serialized_description_list') {
                 $descriptionList = new eZSerializedObjectNameList();
                 $descriptionList->initFromSerializedList($remote->{$remoteProperty});
                 $this->currentClass->DescriptionList = $descriptionList;
             }
         }
     }
     foreach ($this->getData()->missingAttributes as $originalAttribute) {
         $add = $this->addAttribute($originalAttribute);
         if ($add) {
             $attributes[] = $add;
         }
     }
     foreach ($remote->DataMap[0] as $originalAttribute) {
         if (isset($localeAttributes[$originalAttribute->Identifier])) {
             $modified = $this->syncAttribute($originalAttribute, $localeAttributes[$originalAttribute->Identifier]);
             if ($modified) {
                 $attributes[] = $modified;
             }
         }
     }
     if (!$removeExtras) {
         foreach ($this->extraContentObjectAttributes as $extra) {
             $extra->setAttribute('placement', count($attributes) + 1);
             $attributes[] = $extra;
         }
     }
     $this->currentClass->store($attributes);
     $db = eZDB::instance();
     $db->begin();
     $unorderedParameters = array('Language' => $this->EditLanguage);
     if (eZContentObject::fetchSameClassListCount($this->id) > 0) {
         eZExtension::getHandlerClass(new ezpExtensionOptions(array('iniFile' => 'site.ini', 'iniSection' => 'ContentSettings', 'iniVariable' => 'ContentClassEditHandler')))->store($this->currentClass, $attributes, $unorderedParameters);
     } else {
         $unorderedParameters['ScheduledScriptID'] = 0;
         $this->currentClass->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED);
     }
     $db->commit();
     $this->syncGroups();
 }