Beispiel #1
0
 static function canInstantiateClassList($asObject = false, $includeFilter = true, $groupList = false, $fetchID = false)
 {
     $ini = eZINI::instance();
     $groupArray = array();
     $enableCaching = $ini->variable('RoleSettings', 'EnableCaching') == 'true';
     if (is_array($groupList)) {
         if ($fetchID == false) {
             $enableCaching = false;
         }
     }
     if ($enableCaching) {
         $http = eZHTTPTool::instance();
         eZExpiryHandler::registerShutdownFunction();
         $handler = eZExpiryHandler::instance();
         $expiredTimeStamp = 0;
         if ($handler->hasTimestamp('user-class-cache')) {
             $expiredTimeStamp = $handler->timestamp('user-class-cache');
         }
         $classesCachedForUser = $http->sessionVariable('ClassesCachedForUser');
         $classesCachedTimestamp = $http->sessionVariable('ClassesCachedTimestamp');
         $cacheVar = 'CanInstantiateClassList';
         if (is_array($groupList) and $fetchID !== false) {
             $cacheVar = 'CanInstantiateClassListGroup';
         }
         $user = eZUser::currentUser();
         $userID = $user->id();
         if ($classesCachedTimestamp >= $expiredTimeStamp && $classesCachedForUser == $userID) {
             if ($http->hasSessionVariable($cacheVar)) {
                 if ($fetchID !== false) {
                     // Check if the group contains our ID, if not we need to fetch from DB
                     $groupArray = $http->sessionVariable($cacheVar);
                     if (isset($groupArray[$fetchID])) {
                         return $groupArray[$fetchID];
                     }
                 } else {
                     return $http->sessionVariable($cacheVar);
                 }
             }
         } else {
             $http->setSessionVariable('ClassesCachedForUser', $userID);
             $http->setSessionVariable('ClassesCachedTimestamp', time());
         }
     }
     $languageCodeList = eZContentLanguage::fetchLocaleList();
     $allowedLanguages = array('*' => array());
     $user = eZUser::currentUser();
     $accessResult = $user->hasAccessTo('content', 'create');
     $accessWord = $accessResult['accessWord'];
     $classIDArray = array();
     $classList = array();
     $fetchAll = false;
     if ($accessWord == 'yes') {
         $fetchAll = true;
         $allowedLanguages['*'] = $languageCodeList;
     } else {
         if ($accessWord == 'no') {
             // Cannot create any objects, return empty list.
             return $classList;
         } else {
             $policies = $accessResult['policies'];
             foreach ($policies as $policyKey => $policy) {
                 $classIDArrayPart = '*';
                 if (isset($policy['Class'])) {
                     $classIDArrayPart = $policy['Class'];
                 }
                 $languageCodeArrayPart = $languageCodeList;
                 if (isset($policy['Language'])) {
                     $languageCodeArrayPart = array_intersect($policy['Language'], $languageCodeList);
                 }
                 // No class limitation for this policy AND no previous limitation(s)
                 if ($classIDArrayPart == '*' && empty($classIDArray)) {
                     $fetchAll = true;
                     $allowedLanguages['*'] = array_unique(array_merge($allowedLanguages['*'], $languageCodeArrayPart));
                 } else {
                     if (is_array($classIDArrayPart)) {
                         $fetchAll = false;
                         foreach ($classIDArrayPart as $class) {
                             if (isset($allowedLanguages[$class])) {
                                 $allowedLanguages[$class] = array_unique(array_merge($allowedLanguages[$class], $languageCodeArrayPart));
                             } else {
                                 $allowedLanguages[$class] = $languageCodeArrayPart;
                             }
                         }
                         $classIDArray = array_merge($classIDArray, array_diff($classIDArrayPart, $classIDArray));
                     }
                 }
             }
         }
     }
     $db = eZDB::instance();
     $filterTableSQL = '';
     $filterSQL = '';
     // Create extra SQL statements for the class group filters.
     if (is_array($groupList)) {
         if (count($groupList) == 0) {
             return $classList;
         }
         $filterTableSQL = ', ezcontentclass_classgroup ccg';
         $filterSQL = " AND" . "      cc.id = ccg.contentclass_id AND" . "      ";
         $filterSQL .= $db->generateSQLINStatement($groupList, 'ccg.group_id', !$includeFilter, true, 'int');
     }
     $classNameFilter = eZContentClassName::sqlFilter('cc');
     $filterSQL .= " AND      cc.id=" . $classNameFilter['from'] . ".contentclass_id";
     if ($fetchAll) {
         // If $asObject is true we fetch all fields in class
         $fields = $asObject ? "cc.*, {$classNameFilter['nameField']}" : "cc.id, {$classNameFilter['nameField']}";
         $rows = $db->arrayQuery("SELECT DISTINCT {$fields} " . "FROM ezcontentclass cc{$filterTableSQL}, {$classNameFilter['from']} " . "WHERE cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . " {$filterSQL} " . "ORDER BY {$classNameFilter['nameField']} ASC");
         $classList = eZPersistentObject::handleRows($rows, 'eZContentClass', $asObject);
     } else {
         // If the constrained class list is empty we are not allowed to create any class
         if (count($classIDArray) == 0) {
             return $classList;
         }
         $classIDCondition = $db->generateSQLINStatement($classIDArray, 'cc.id');
         // If $asObject is true we fetch all fields in class
         $fields = $asObject ? "cc.*, {$classNameFilter['nameField']}" : "cc.id, {$classNameFilter['nameField']}";
         $rows = $db->arrayQuery("SELECT DISTINCT {$fields} " . "FROM ezcontentclass cc{$filterTableSQL}, {$classNameFilter['from']} " . "WHERE {$classIDCondition} AND" . "      cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . " {$filterSQL} " . "ORDER BY {$classNameFilter['nameField']} ASC");
         $classList = eZPersistentObject::handleRows($rows, 'eZContentClass', $asObject);
     }
     if ($asObject) {
         foreach ($classList as $key => $class) {
             $id = $class->attribute('id');
             if (isset($allowedLanguages[$id])) {
                 $languageCodes = array_unique(array_merge($allowedLanguages['*'], $allowedLanguages[$id]));
             } else {
                 $languageCodes = $allowedLanguages['*'];
             }
             $classList[$key]->setCanInstantiateLanguages($languageCodes);
         }
     }
     eZDebugSetting::writeDebug('kernel-content-class', $classList, "class list fetched from db");
     if ($enableCaching) {
         if ($fetchID !== false) {
             $groupArray[$fetchID] = $classList;
             $http->setSessionVariable($cacheVar, $groupArray);
         } else {
             $http->setSessionVariable($cacheVar, $classList);
         }
     }
     return $classList;
 }
 function handleParameters( $packageType, $package, $cli, $type, $arguments )
 {
     $nodeList = array();
     $includeClasses = true;
     $includeTemplates = true;
     $siteAccessList = array();
     $nodeAssignmentType = 'main';
     $relatedObjectType = 'selected';
     $embedObjectType = 'selected';
     $versionType = 'current';
     $languageList = array();
     $minimalTemplateSet = false;
     $nodeItem = array( 'node-id-list' => array() );
     $longOptions = array( 'include-classes' => 'include-classes',
                           'include-templates' => 'include-templates',
                           'exclude-classes' => 'exclude-classes',
                           'exclude-templates' => 'exclude-templates',
                           'language' => 'language',
                           'current-version' => 'current-version',
                           'all-versions' => 'all-versions',
                           'node-main' => 'node-main',
                           'node-selected' => 'node-selected',
                           'siteaccess' => 'siteaccess',
                           'minimal-template-set' => 'minimal-template-set' );
     $shortOptions = array();
     $error = false;
     foreach ( $arguments as $argument )
     {
         if ( $argument[0] == '-' )
         {
             if ( strlen( $argument ) > 1 and
                  $argument[1] == '-' )
             {
                 $option = substr( $argument, 2 );
                 $valuePos = strpos( $option, '=' );
                 $optionValue = false;
                 if ( $valuePos !== false )
                 {
                     $optionValue = substr( $option, $valuePos + 1 );
                     $option = substr( $option, 0, $valuePos );
                 }
                 if ( isset( $longOptions[$option] ) )
                     $optionName = $longOptions[$option];
                 else
                     $optionName = false;
             }
             else
             {
                 $option = substr( $argument, 1 );
                 if ( isset( $shortOptions[$option] ) )
                     $optionName = $shortOptions[$option];
                 else
                     $optionName = false;
             }
             if ( $optionName == 'include-classes' or $optionName == 'exclude-classes' )
             {
                 if ( count( $nodeItem['node-id-list'] ) > 0 )
                 {
                     $nodeList[] = $nodeItem;
                     $nodeItem['node-id-list'] = array();
                 }
                 $includeClasses = ( $optionName == 'include-classes' );
             }
             else if ( $optionName == 'include-templates' or $optionName == 'exclude-templates' )
             {
                 if ( count( $nodeItem['node-id-list'] ) > 0 )
                 {
                     $nodeList[] = $nodeItem;
                     $nodeItem['node-id-list'] = array();
                 }
                 $includeTemplates = ( $optionName == 'include-templates' );
             }
             else if ( $optionName == 'node-main' )
             {
                 $nodeAssignmentType = 'main';
             }
             else if ( $optionName == 'node-selected' )
             {
                 $nodeAssignmentType = 'selected';
             }
             else if ( $optionName == 'siteaccess' )
             {
                 $siteAccessList = explode( ',', $optionValue );
             }
             else if ( $optionName == 'language' )
             {
                 $languageList = explode( ',', $optionValue );
             }
             else if ( $optionName == 'current-version' )
             {
                 $versionType = 'current';
             }
             else if ( $optionName == 'all-versions' )
             {
                 $versionType = 'all';
             }
             else if ( $optionName == 'minimal-template-set' )
             {
                 $minimalTemplateSet = true;
             }
         }
         else
         {
             $nodeID = false;
             $subtree = false;
             if ( is_numeric( $argument ) )
             {
                 $nodeID = (int)$argument;
                 $node = eZContentObjectTreeNode::fetch( $nodeID );
                 if ( !is_object( $node ) )
                 {
                     $error = true;
                     $nodeID = false;
                     $cli->notice( "Could not find content-node using ID " . $cli->stylize( 'emphasize', $nodeID ) );
                 }
             }
             else
             {
                 $path = $argument;
                 if ( preg_match( "#(.+)/\*$#", $path, $matches ) )
                 {
                     $path = $matches[1];
                     $subtree = true;
                 }
                 $node = eZContentObjectTreeNode::fetchByURLPath( $path );
                 if ( is_object( $node ) )
                 {
                     $nodeID = $node->attribute( 'node_id' );
                 }
                 else
                 {
                     $cli->notice( "Could not find content-node using path " . $cli->stylize( 'emphasize', $path ) );
                     $error = true;
                 }
             }
             if ( $nodeID )
             {
                 $nodeItem['node-id-list'][] = array( 'id' => $nodeID,
                                                      'subtree' => $subtree,
                                                      'node' => &$node );
             }
             if ( $error )
                 return false;
         }
     }
     if ( count( $nodeItem['node-id-list'] ) > 0 )
     {
         $nodeList[] = $nodeItem;
     }
     if ( count( $nodeList ) == 0 )
     {
         $cli->error( "No objects chosen" );
         return false;
     }
     if ( count( $languageList ) == 0 )
     {
         // The default is to fetch all languages
         $languageList = eZContentLanguage::fetchLocaleList();
     }
     if ( count( $siteAccessList ) == 0 )
     {
         $ini = eZINI::instance();
         $siteAccessList[] = $ini->variable( 'SiteSettings', 'DefaultAccess' );
     }
     return array( 'node-list' => $nodeList,
                   'include-classes' => $includeClasses,
                   'include-templates' => $includeTemplates,
                   'siteaccess-list' => $siteAccessList,
                   'language-list' => $languageList,
                   'node-assignment-type' => $nodeAssignmentType,
                   'related-type' => $relatedObjectType,
                   'embed-type' => $embedObjectType,
                   'version-type' => $versionType,
                   'minimal-template-set' => $minimalTemplateSet,
                   );
 }
 function canCreateClassList($asObject = false, $includeFilter = true, $groupList = false, $fetchID = false)
 {
     $ini = eZINI::instance();
     $groupArray = array();
     $languageCodeList = eZContentLanguage::fetchLocaleList();
     $allowedLanguages = array('*' => array());
     $user = eZUser::currentUser();
     $accessResult = $user->hasAccessTo('content', 'create');
     $accessWord = $accessResult['accessWord'];
     $classIDArray = array();
     $classList = array();
     $fetchAll = false;
     if ($accessWord == 'yes') {
         $fetchAll = true;
         $allowedLanguages['*'] = $languageCodeList;
     } else {
         if ($accessWord == 'no') {
             // Cannot create any objects, return empty list.
             return $classList;
         } else {
             foreach ($accessResult['policies'] as $policy) {
                 $policyArray = $this->classListFromPolicy($policy, $languageCodeList);
                 if (empty($policyArray)) {
                     continue;
                 }
                 // Wildcard on all classes
                 if ($policyArray['classes'] == '*') {
                     $fetchAll = true;
                     $allowedLanguages['*'] = array_unique(array_merge($allowedLanguages['*'], $policyArray['language_codes']));
                     // we remove individual class ids that are overriden in all languages by the wildcard (#EZP-20933)
                     foreach ($allowedLanguages as $classId => $classLanguageCodes) {
                         if ($classId == '*') {
                             continue;
                         }
                         if (!count(array_diff($classLanguageCodes, $allowedLanguages['*']))) {
                             unset($allowedLanguages[$classId]);
                         }
                     }
                 } else {
                     if (is_array($policyArray['classes']) && $this->hasCurrentSubtreeLimitation($policy)) {
                         foreach ($policyArray['classes'] as $class) {
                             if (isset($allowedLanguages[$class])) {
                                 $allowedLanguages[$class] = array_unique(array_merge($allowedLanguages[$class], $policyArray['language_codes']));
                             } else {
                                 // we don't add class identifiers that are already covered by the 'all classes' in a language
                                 if (!empty($allowedLanguages['*'])) {
                                     if (!count(array_diff($policyArray['language_codes'], $allowedLanguages['*']))) {
                                         continue;
                                     }
                                 }
                                 $allowedLanguages[$class] = $policyArray['language_codes'];
                             }
                         }
                         $classIDArray = array_merge($classIDArray, array_diff($policyArray['classes'], $classIDArray));
                     }
                 }
             }
         }
     }
     $db = eZDB::instance();
     $filterTableSQL = '';
     $filterSQL = '';
     // Create extra SQL statements for the class group filters.
     if (is_array($groupList)) {
         if (count($groupList) == 0) {
             return $classList;
         }
         $filterTableSQL = ', ezcontentclass_classgroup ccg';
         $filterSQL = " AND" . "      cc.id = ccg.contentclass_id AND" . "      ";
         $filterSQL .= $db->generateSQLINStatement($groupList, 'ccg.group_id', !$includeFilter, true, 'int');
     }
     $classNameFilter = eZContentClassName::sqlFilter('cc');
     if ($fetchAll) {
         // If $asObject is true we fetch all fields in class
         $fields = $asObject ? "cc.*, {$classNameFilter['nameField']}" : "cc.id, {$classNameFilter['nameField']}";
         $rows = $db->arrayQuery("SELECT DISTINCT {$fields} " . "FROM ezcontentclass cc{$filterTableSQL}, {$classNameFilter['from']} " . "WHERE cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . " {$filterSQL} AND {$classNameFilter['where']} " . "ORDER BY {$classNameFilter['nameField']} ASC");
         $classList = eZPersistentObject::handleRows($rows, 'eZContentClass', $asObject);
     } else {
         // If the constrained class list is empty we are not allowed to create any class
         if (count($classIDArray) == 0) {
             return $classList;
         }
         $classIDCondition = $db->generateSQLINStatement($classIDArray, 'cc.id');
         // If $asObject is true we fetch all fields in class
         $fields = $asObject ? "cc.*, {$classNameFilter['nameField']}" : "cc.id, {$classNameFilter['nameField']}";
         $rows = $db->arrayQuery("SELECT DISTINCT {$fields} " . "FROM ezcontentclass cc{$filterTableSQL}, {$classNameFilter['from']} " . "WHERE {$classIDCondition} AND" . "      cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . " {$filterSQL} AND {$classNameFilter['where']} " . "ORDER BY {$classNameFilter['nameField']} ASC");
         $classList = eZPersistentObject::handleRows($rows, 'eZContentClass', $asObject);
     }
     if ($asObject) {
         foreach ($classList as $key => $class) {
             $id = $class->attribute('id');
             if (isset($allowedLanguages[$id])) {
                 $languageCodes = array_unique(array_merge($allowedLanguages['*'], $allowedLanguages[$id]));
             } else {
                 $languageCodes = $allowedLanguages['*'];
             }
             $classList[$key]->setCanInstantiateLanguages($languageCodes);
         }
     }
     eZDebugSetting::writeDebug('kernel-content-class', $classList, "class list fetched from db");
     return $classList;
 }
$script->startup();
$config = '';
$argumentConfig = '';
$optionHelp = false;
$arguments = false;
$useStandardOptions = true;
$options = $script->getOptions($config, $argumentConfig, $optionHelp, $arguments, $useStandardOptions);
$script->initialize();
eZContentObjectStateGroup::$allowInternalCUD = true;
$lockGroup = eZContentObjectStateGroup::fetchByIdentifier('ez_lock');
if ($lockGroup) {
    $script->shutdown(1, 'ez_lock state group already exists');
}
$db = eZDB::instance();
$db->begin();
$locales = eZContentLanguage::fetchLocaleList();
$localeToUse = false;
$localeIDToUse = false;
// this script inserts English names, so preferably use an English locale
$preferredLocales = array('eng-GB', 'eng-US');
foreach ($preferredLocales as $preferredLocale) {
    if (in_array($preferredLocale, $locales)) {
        $localeToUse = $preferredLocale;
        break;
    }
}
// when none of the preferred locales are in use, then use the top priority language
if ($localeToUse === false) {
    $prioritizedLanguage = eZContentLanguage::topPriorityLanguage();
    $localeToUse = $prioritizedLanguage->attribute('locale');
}
    /**
     * Finds all classes that the current user can create objects from and returns.
     * It is also possible to filter the list event more with $includeFilter and $groupList.
     *
     * @param bool $asObject If true then it return eZContentClass objects, if not it will be an associative array
     * @param bool $includeFilter If true then it will include only from class groups defined in $groupList, if not it will exclude those groups.
     * @param bool $groupList An array with class group IDs that should be used in filtering, use false if you do not wish to filter at all.
     * @param bool $fetchID A unique name for the current fetch, this must be supplied when filtering is used if you want caching to work.
     * @return array|eZPersistentObject[]
     */
    function canCreateClassList( $asObject = false, $includeFilter = true, $groupList = false, $fetchID = false )
    {
        $ini = eZINI::instance();
        $groupArray = array();
        $languageCodeList = eZContentLanguage::fetchLocaleList();
        $allowedLanguages = array( '*' => array() );

        $user = eZUser::currentUser();
        $accessResult = $user->hasAccessTo( 'content' , 'create' );
        $accessWord = $accessResult['accessWord'];

        $classIDArray = array();
        $classList = array();
        $fetchAll = false;
        if ( $accessWord == 'yes' )
        {
            $fetchAll = true;
            $allowedLanguages['*'] = $languageCodeList;
        }
        else if ( $accessWord == 'no' )
        {
            // Cannot create any objects, return empty list.
            return $classList;
        }
        else
        {
            $policies = $accessResult['policies'];
            foreach ( $policies as $policyKey => $policy )
            {
                $policyArray = $this->classListFromPolicy( $policy, $languageCodeList );
                if ( empty( $policyArray ) )
                {
                    continue;
                }
                $classIDArrayPart = $policyArray['classes'];
                $languageCodeArrayPart = $policyArray['language_codes'];
                // No class limitation for this policy AND no previous limitation(s)
                if ( $classIDArrayPart == '*' && empty( $classIDArray ) )
                {
                    $fetchAll = true;
                    $allowedLanguages['*'] = array_unique( array_merge( $allowedLanguages['*'], $languageCodeArrayPart ) );
                }
                else if ( is_array( $classIDArrayPart ) )
                {
                    $fetchAll = false;
                    foreach( $classIDArrayPart as $class )
                    {
                        if ( isset( $allowedLanguages[$class] ) )
                        {
                            $allowedLanguages[$class] = array_unique( array_merge( $allowedLanguages[$class], $languageCodeArrayPart ) );
                        }
                        else
                        {
                            $allowedLanguages[$class] = $languageCodeArrayPart;
                        }
                    }
                    $classIDArray = array_merge( $classIDArray, array_diff( $classIDArrayPart, $classIDArray ) );
                }
            }
        }

        $db = eZDB::instance();

        $filterTableSQL = '';
        $filterSQL = '';
        // Create extra SQL statements for the class group filters.
        if ( is_array( $groupList ) )
        {
            if ( count( $groupList ) == 0 )
            {
                return $classList;
            }

            $filterTableSQL = ', ezcontentclass_classgroup ccg';
            $filterSQL = ( " AND" .
                           "      cc.id = ccg.contentclass_id AND" .
                           "      " );
            $filterSQL .= $db->generateSQLINStatement( $groupList, 'ccg.group_id', !$includeFilter, true, 'int' );
        }

        $classNameFilter = eZContentClassName::sqlFilter( 'cc' );

        if ( $fetchAll )
        {
            // If $asObject is true we fetch all fields in class
            $fields = $asObject ? "cc.*, $classNameFilter[nameField]" : "cc.id, $classNameFilter[nameField]";
            $rows = $db->arrayQuery( "SELECT DISTINCT $fields " .
                                     "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from] " .
                                     "WHERE cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . " $filterSQL AND $classNameFilter[where] " .
                                     "ORDER BY $classNameFilter[nameField] ASC" );
            $classList = eZPersistentObject::handleRows( $rows, 'eZContentClass', $asObject );
        }
        else
        {
            // If the constrained class list is empty we are not allowed to create any class
            if ( count( $classIDArray ) == 0 )
            {
                return $classList;
            }

            $classIDCondition = $db->generateSQLINStatement( $classIDArray, 'cc.id' );
            // If $asObject is true we fetch all fields in class
            $fields = $asObject ? "cc.*, $classNameFilter[nameField]" : "cc.id, $classNameFilter[nameField]";
            $rows = $db->arrayQuery( "SELECT DISTINCT $fields " .
                                     "FROM ezcontentclass cc$filterTableSQL, $classNameFilter[from] " .
                                     "WHERE $classIDCondition AND" .
                                     "      cc.version = " . eZContentClass::VERSION_STATUS_DEFINED . " $filterSQL AND $classNameFilter[where] " .
                                     "ORDER BY $classNameFilter[nameField] ASC" );
            $classList = eZPersistentObject::handleRows( $rows, 'eZContentClass', $asObject );
        }

        if ( $asObject )
        {
            foreach ( $classList as $key => $class )
            {
                $id = $class->attribute( 'id' );
                if ( isset( $allowedLanguages[$id] ) )
                {
                    $languageCodes = array_unique( array_merge( $allowedLanguages['*'], $allowedLanguages[$id] ) );
                }
                else
                {
                    $languageCodes = $allowedLanguages['*'];
                }
                $classList[$key]->setCanInstantiateLanguages( $languageCodes );
            }
        }

        eZDebugSetting::writeDebug( 'kernel-content-class', $classList, "class list fetched from db" );
        return $classList;
    }
 function execute($xml)
 {
     $classList = $xml->getElementsByTagName('ContentClass');
     $refArray = array();
     $availableLanguageList = eZContentLanguage::fetchLocaleList();
     foreach ($classList as $class) {
         $this->adjustAttributesPlacement = false;
         $user = eZUser::currentUser();
         $userID = $user->attribute('contentobject_id');
         $classIdentifier = $class->getAttribute('identifier');
         $classRemoteID = $class->getAttribute('remoteID');
         $classObjectNamePattern = $class->getAttribute('objectNamePattern');
         $classExistAction = $class->getAttribute('classExistAction');
         $referenceID = $class->getAttribute('referenceID');
         $this->writeMessage("\tClass '{$classIdentifier}' will be updated.", 'notice');
         $classURLAliasPattern = $class->getAttribute('urlAliasPattern') ? $class->getAttribute('urlAliasPattern') : null;
         $classIsContainer = $class->getAttribute('isContainer');
         if ($classIsContainer !== false) {
             $classIsContainer = $classIsContainer == 'true' ? 1 : 0;
         }
         $classGroupsNode = $class->getElementsByTagName('Groups')->item(0);
         $classAttributesNode = $class->getElementsByTagName('Attributes')->item(0);
         $nameList = array();
         $nameListObject = $class->getElementsByTagName('Names')->item(0);
         if ($nameListObject && $nameListObject->parentNode === $class && $nameListObject->hasAttributes()) {
             $attributes = $nameListObject->attributes;
             if (!is_null($attributes)) {
                 foreach ($attributes as $index => $attr) {
                     if (in_array($attr->name, $availableLanguageList)) {
                         $nameList[$attr->name] = $attr->value;
                     }
                 }
             }
         }
         if (!empty($nameList)) {
             $classNameList = new eZContentClassNameList(serialize($nameList));
             $classNameList->validate();
         } else {
             $classNameList = null;
         }
         $dateTime = time();
         $classCreated = $dateTime;
         $classModified = $dateTime;
         $class = eZContentClass::fetchByRemoteID($classRemoteID);
         if (!$class) {
             $class = eZContentClass::fetchByIdentifier($classIdentifier);
         }
         if ($class) {
             $className = $class->name();
             switch ($classExistAction) {
                 case 'replace':
                     $this->writeMessage("\t\tClass '{$classIdentifier}' will be replaced.", 'notice');
                     foreach ($nameList as $lang => $name) {
                         if (in_array($lang, $availableLanguageList)) {
                             $class->setName($name, $lang);
                         }
                     }
                     $class->setAttribute('contentobject_name', $classObjectNamePattern);
                     $class->setAttribute('identifier', $classIdentifier);
                     $class->setAttribute('is_container', $classIsContainer);
                     $class->setAttribute('url_alias_name', $classURLAliasPattern);
                     $class->store();
                     $class->removeAttributes();
                     break;
                 case 'new':
                     unset($class);
                     $class = false;
                     break;
                     break;
                 case 'extend':
                     $this->writeMessage("\t\tClass '{$classIdentifier}' will be extended.", 'notice');
                     foreach ($nameList as $lang => $name) {
                         if (in_array($lang, $availableLanguageList)) {
                             $class->setName($name, $lang);
                         }
                     }
                     $class->setAttribute('contentobject_name', $classObjectNamePattern);
                     $class->setAttribute('identifier', $classIdentifier);
                     $class->setAttribute('is_container', $classIsContainer);
                     $class->setAttribute('url_alias_name', $classURLAliasPattern);
                     $class->store();
                     break;
                 case 'skip':
                 default:
                     continue;
                     break;
             }
         }
         if (!$class) {
             // Try to create a unique class identifier
             $currentClassIdentifier = $classIdentifier;
             $unique = false;
             while (!$unique) {
                 $classList = eZContentClass::fetchByIdentifier($currentClassIdentifier);
                 if ($classList) {
                     // "increment" class identifier
                     if (preg_match('/^(.*)_(\\d+)$/', $currentClassIdentifier, $matches)) {
                         $currentClassIdentifier = $matches[1] . '_' . ($matches[2] + 1);
                     } else {
                         $currentClassIdentifier = $currentClassIdentifier . '_1';
                     }
                 } else {
                     $unique = true;
                 }
                 unset($classList);
             }
             $classIdentifier = $currentClassIdentifier;
             // create class
             $class = eZContentClass::create($userID, array('version' => 1, 'serialized_name_list' => $classNameList->serializeNames(), 'create_lang_if_not_exist' => true, 'identifier' => $classIdentifier, 'remote_id' => $classRemoteID, 'contentobject_name' => $classObjectNamePattern, 'url_alias_name' => $classURLAliasPattern, 'is_container' => $classIsContainer, 'created' => $classCreated, 'modified' => $classModified));
             $class->store();
             $attributes = $class->fetchAttributes();
             $class->storeDefined($attributes);
             $classID = $class->attribute('id');
             $this->writeMessage("\t\tClass '{$classIdentifier}' will be newly created.", 'notice');
         }
         // create class attributes
         $classAttributeList = $classAttributesNode->getElementsByTagName('Attribute');
         $classDataMap = $class->attribute('data_map');
         $updateAttributeList = array();
         if ($classDataMap == NULL) {
             $classDataMap = array();
         }
         foreach ($classAttributeList as $classAttributeNode) {
             $attributeDatatype = $classAttributeNode->getAttribute('datatype');
             $attributeIsRequired = strtolower($classAttributeNode->getAttribute('required')) == 'true';
             $attributeIsSearchable = strtolower($classAttributeNode->getAttribute('searchable')) == 'true';
             $attributeIsInformationCollector = strtolower($classAttributeNode->getAttribute('informationCollector')) == 'true';
             $attributeIsTranslatable = strtolower($classAttributeNode->getAttribute('translatable')) == 'false' ? 0 : 1;
             $attributeIdentifier = $classAttributeNode->getAttribute('identifier');
             $attributePlacement = $classAttributeNode->getAttribute('placement');
             $attributeNameListObject = $classAttributeNode->getElementsByTagName('Names')->item(0);
             if ($attributeNameListObject->hasAttributes()) {
                 if ($attributeNameListObject->hasAttributes()) {
                     $attributes = $attributeNameListObject->attributes;
                     if (!is_null($attributes)) {
                         $attributeNameList = array();
                         foreach ($attributes as $index => $attr) {
                             $attributeNameList[$attr->name] = $attr->value;
                         }
                     }
                 }
             }
             $classAttributeNameList = new eZContentClassNameList(serialize($attributeNameList));
             $classAttributeNameList->validate();
             $attributeDatatypeParameterNode = $classAttributeNode->getElementsByTagName('DatatypeParameters')->item(0);
             $classAttribute = $class->fetchAttributeByIdentifier($attributeIdentifier);
             $params = array();
             $params['identifier'] = $attributeIdentifier;
             $params['name_list'] = $classAttributeNameList;
             $params['data_type_string'] = $attributeDatatype;
             $params['default_value'] = '';
             $params['can_translate'] = $attributeIsTranslatable;
             $params['is_required'] = $attributeIsRequired;
             $params['is_searchable'] = $attributeIsSearchable;
             $params['content'] = '';
             $params['placement'] = $attributePlacement;
             $params['is_information_collector'] = $attributeIsInformationCollector;
             $params['datatype-parameter'] = $this->parseAndReplaceNodeStringReferences($attributeDatatypeParameterNode);
             $params['attribute-node'] = $classAttributeNode;
             if (!array_key_exists($attributeIdentifier, $classDataMap)) {
                 $this->writeMessage("\t\tClass '{$classIdentifier}' will get new Attribute '{$attributeIdentifier}'.", 'notice');
                 $updateAttributeList[] = $this->addClassAttribute($class, $params);
             } else {
                 $this->writeMessage("\t\tClass '{$classIdentifier}' will get updated Attribute '{$attributeIdentifier}'.", 'notice');
                 $this->updateClassAttribute($class, $params);
             }
         }
         if ($this->adjustAttributesPlacement) {
             //once every attribute has been processed, we may reset placement
             $this->writeMessage("\t\tAdjusting attributes placement.", 'notice');
             $this->adjustClassAttributesPlacement($class);
         }
         if (count($updateAttributeList)) {
             $this->writeMessage("\t\tUpdating content object attributes.", 'notice');
             $classID = $class->attribute('id');
             // update object attributes
             $objects = eZContentObject::fetchSameClassList($classID, false);
             foreach ($objects as $objectID) {
                 $object = eZContentObject::fetch($objectID['id']);
                 if ($object) {
                     $contentobjectID = $object->attribute('id');
                     $objectVersions = $object->versions();
                     foreach ($objectVersions as $objectVersion) {
                         $translations = $objectVersion->translations(false);
                         $version = $objectVersion->attribute('version');
                         foreach ($translations as $translation) {
                             foreach ($updateAttributeList as $classAttributeID) {
                                 $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentobjectID, $version);
                                 $objectAttribute->setAttribute('language_code', $translation);
                                 $objectAttribute->initialize();
                                 $objectAttribute->store();
                                 $objectAttribute->postInitialize();
                             }
                         }
                     }
                 }
                 unset($object);
             }
         }
         if ($classNameList) {
             $classNameList->store($class);
         }
         // add class to a class group
         $classGroupsList = $classGroupsNode->getElementsByTagName('Group');
         foreach ($classGroupsList as $classGroupNode) {
             $classGroupName = $classGroupNode->getAttribute('name');
             $classGroup = eZContentClassGroup::fetchByName($classGroupName);
             if (!$classGroup) {
                 $classGroup = eZContentClassGroup::create();
                 $classGroup->setAttribute('name', $classGroupName);
                 $classGroup->store();
             }
             $classGroup->appendClass($class);
         }
         if ($referenceID) {
             $refArray[$referenceID] = $class->attribute('id');
         }
     }
     $this->addReference($refArray);
     eZContentCacheManager::clearAllContentCache();
 }