Exemplo n.º 1
0
        $validation['class_errors'][] = array('text' => ezpI18n::tr('kernel/class', 'There is a class already having the same identifier.'));
        $basicClassPropertiesValid = false;
    }
    unset($classList);
    if (!$basicClassPropertiesValid) {
        $db->commit();
        $canStore = false;
        $validation['processed'] = false;
    } else {
        if (!$http->hasSessionVariable('ClassCanStoreTicket')) {
            $db->commit();
            return $Module->redirectToView('view', array($ClassID), array('Language' => $EditLanguage));
        }
        $unorderedParameters = array('Language' => $EditLanguage);
        // Is there existing objects of this content class?
        if (eZContentObject::fetchSameClassListCount($ClassID) > 0) {
            eZExtension::getHandlerClass(new ezpExtensionOptions(array('iniFile' => 'site.ini', 'iniSection' => 'ContentSettings', 'iniVariable' => 'ContentClassEditHandler')))->store($class, $attributes, $unorderedParameters);
        } else {
            $unorderedParameters['ScheduledScriptID'] = 0;
            $class->storeVersioned($attributes, eZContentClass::VERSION_STATUS_DEFINED);
        }
        $db->commit();
        $http->removeSessionVariable('ClassCanStoreTicket');
        ezpEvent::getInstance()->notify('content/class/cache', array($ClassID));
        return $Module->redirectToView('view', array($ClassID), $unorderedParameters);
    }
}
// Store changes
if ($canStore) {
    $class->store($attributes);
}
Exemplo n.º 2
0
 function install($package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData)
 {
     $serializedNameListNode = $content->getElementsByTagName('serialized-name-list')->item(0);
     $serializedNameList = $serializedNameListNode ? $serializedNameListNode->textContent : false;
     $classNameList = new eZContentClassNameList($serializedNameList);
     if ($classNameList->isEmpty()) {
         $classNameList->initFromString($content->getElementsByTagName('name')->item(0)->textContent);
         // for backward compatibility( <= 3.8 )
     }
     $classNameList->validate();
     $serializedDescriptionListNode = $content->getElementsByTagName('serialized-description-list')->item(0);
     $serializedDescriptionList = $serializedDescriptionListNode ? $serializedDescriptionListNode->textContent : false;
     $classDescriptionList = new eZSerializedObjectNameList($serializedDescriptionList);
     $classIdentifier = $content->getElementsByTagName('identifier')->item(0)->textContent;
     $classRemoteID = $content->getElementsByTagName('remote-id')->item(0)->textContent;
     $classObjectNamePattern = $content->getElementsByTagName('object-name-pattern')->item(0)->textContent;
     $classURLAliasPattern = is_object($content->getElementsByTagName('url-alias-pattern')->item(0)) ? $content->getElementsByTagName('url-alias-pattern')->item(0)->textContent : null;
     $classIsContainer = $content->getAttribute('is-container');
     if ($classIsContainer !== false) {
         $classIsContainer = $classIsContainer == 'true' ? 1 : 0;
     }
     $classRemoteNode = $content->getElementsByTagName('remote')->item(0);
     $classID = $classRemoteNode->getElementsByTagName('id')->item(0)->textContent;
     $classGroupsNode = $classRemoteNode->getElementsByTagName('groups')->item(0);
     $classCreated = $classRemoteNode->getElementsByTagName('created')->item(0)->textContent;
     $classModified = $classRemoteNode->getElementsByTagName('modified')->item(0)->textContent;
     $classCreatorNode = $classRemoteNode->getElementsByTagName('creator')->item(0);
     $classModifierNode = $classRemoteNode->getElementsByTagName('modifier')->item(0);
     $classAttributesNode = $content->getElementsByTagName('attributes')->item(0);
     $dateTime = time();
     $classCreated = $dateTime;
     $classModified = $dateTime;
     $userID = false;
     if (isset($installParameters['user_id'])) {
         $userID = $installParameters['user_id'];
     }
     $class = eZContentClass::fetchByRemoteID($classRemoteID);
     if ($class) {
         $className = $class->name();
         $description = ezpI18n::tr('kernel/package', "Class '%classname' already exists.", false, array('%classname' => $className));
         $choosenAction = $this->errorChoosenAction(self::ERROR_EXISTS, $installParameters, $description, $this->HandlerType);
         switch ($choosenAction) {
             case eZPackage::NON_INTERACTIVE:
             case self::ACTION_REPLACE:
                 if (eZContentClassOperations::remove($class->attribute('id')) == false) {
                     eZDebug::writeWarning("Unable to remove class '{$className}'.");
                     return true;
                 }
                 eZDebug::writeNotice("Class '{$className}' will be replaced.", 'eZContentClassPackageHandler');
                 break;
             case self::ACTION_SKIP:
                 return true;
             case self::ACTION_NEW:
                 $class->setAttribute('remote_id', eZRemoteIdUtility::generate('class'));
                 $class->store();
                 $classNameList->appendGroupName(" (imported)");
                 break;
             default:
                 $installParameters['error'] = array('error_code' => self::ERROR_EXISTS, 'element_id' => $classRemoteID, 'description' => $description, 'actions' => array());
                 if ($class->isRemovable()) {
                     $errorMsg = ezpI18n::tr('kernel/package', "Replace existing class");
                     $objectsCount = eZContentObject::fetchSameClassListCount($class->attribute('id'));
                     if ($objectsCount) {
                         $errorMsg .= ' ' . ezpI18n::tr('kernel/package', "(Warning! {$objectsCount} content object(s) and their sub-items will be removed)");
                     }
                     $installParameters['error']['actions'][self::ACTION_REPLACE] = $errorMsg;
                 }
                 $installParameters['error']['actions'][self::ACTION_SKIP] = ezpI18n::tr('kernel/package', 'Skip installing this class');
                 $installParameters['error']['actions'][self::ACTION_NEW] = ezpI18n::tr('kernel/package', 'Keep existing and create a new one');
                 return false;
         }
     }
     unset($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;
     $values = array('version' => 0, 'serialized_name_list' => $classNameList->serializeNames(), 'serialized_description_list' => $classDescriptionList->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);
     if ($content->hasAttribute('sort-field')) {
         $values['sort_field'] = eZContentObjectTreeNode::sortFieldID($content->getAttribute('sort-field'));
     } else {
         eZDebug::writeNotice('The sort field was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__);
     }
     if ($content->hasAttribute('sort-order')) {
         $values['sort_order'] = $content->getAttribute('sort-order');
     } else {
         eZDebug::writeNotice('The sort order was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__);
     }
     if ($content->hasAttribute('always-available')) {
         $values['always_available'] = $content->getAttribute('always-available') === 'true' ? 1 : 0;
     } else {
         eZDebug::writeNotice('The default object availability was not specified in the content class package. ' . 'This property is exported and imported since eZ Publish 4.0.2', __METHOD__);
     }
     // create class
     $class = eZContentClass::create($userID, $values);
     $class->store();
     $classID = $class->attribute('id');
     if (!isset($installData['classid_list'])) {
         $installData['classid_list'] = array();
     }
     if (!isset($installData['classid_map'])) {
         $installData['classid_map'] = array();
     }
     $installData['classid_list'][] = $class->attribute('id');
     $installData['classid_map'][$classID] = $class->attribute('id');
     // create class attributes
     $classAttributeList = $classAttributesNode->getElementsByTagName('attribute');
     foreach ($classAttributeList as $classAttributeNode) {
         $isNotSupported = strtolower($classAttributeNode->getAttribute('unsupported')) == 'true';
         if ($isNotSupported) {
             continue;
         }
         $attributeDatatype = $classAttributeNode->getAttribute('datatype');
         $attributeIsRequired = strtolower($classAttributeNode->getAttribute('required')) == 'true';
         $attributeIsSearchable = strtolower($classAttributeNode->getAttribute('searchable')) == 'true';
         $attributeIsInformationCollector = strtolower($classAttributeNode->getAttribute('information-collector')) == 'true';
         $attributeIsTranslatable = strtolower($classAttributeNode->getAttribute('translatable')) == 'true';
         $attributeSerializedNameListNode = $classAttributeNode->getElementsByTagName('serialized-name-list')->item(0);
         $attributeSerializedNameListContent = $attributeSerializedNameListNode ? $attributeSerializedNameListNode->textContent : false;
         $attributeSerializedNameList = new eZSerializedObjectNameList($attributeSerializedNameListContent);
         if ($attributeSerializedNameList->isEmpty()) {
             $attributeSerializedNameList->initFromString($classAttributeNode->getElementsByTagName('name')->item(0)->textContent);
         }
         // for backward compatibility( <= 3.8 )
         $attributeSerializedNameList->validate();
         $attributeSerializedDescriptionListNode = $classAttributeNode->getElementsByTagName('serialized-description-list')->item(0);
         $attributeSerializedDescriptionListContent = $attributeSerializedDescriptionListNode ? $attributeSerializedDescriptionListNode->textContent : false;
         $attributeSerializedDescriptionList = new eZSerializedObjectNameList($attributeSerializedDescriptionListContent);
         $attributeCategoryNode = $classAttributeNode->getElementsByTagName('category')->item(0);
         $attributeCategory = $attributeCategoryNode ? $attributeCategoryNode->textContent : '';
         $attributeSerializedDataTextNode = $classAttributeNode->getElementsByTagName('serialized-description-text')->item(0);
         $attributeSerializedDataTextContent = $attributeSerializedDataTextNode ? $attributeSerializedDataTextNode->textContent : false;
         $attributeSerializedDataText = new eZSerializedObjectNameList($attributeSerializedDataTextContent);
         $attributeIdentifier = $classAttributeNode->getElementsByTagName('identifier')->item(0)->textContent;
         $attributePlacement = $classAttributeNode->getElementsByTagName('placement')->item(0)->textContent;
         $attributeDatatypeParameterNode = $classAttributeNode->getElementsByTagName('datatype-parameters')->item(0);
         $classAttribute = $class->fetchAttributeByIdentifier($attributeIdentifier);
         if (!$classAttribute) {
             $classAttribute = eZContentClassAttribute::create($class->attribute('id'), $attributeDatatype, array('version' => 0, 'identifier' => $attributeIdentifier, 'serialized_name_list' => $attributeSerializedNameList->serializeNames(), 'serialized_description_list' => $attributeSerializedDescriptionList->serializeNames(), 'category' => $attributeCategory, 'serialized_data_text' => $attributeSerializedDataText->serializeNames(), 'is_required' => $attributeIsRequired, 'is_searchable' => $attributeIsSearchable, 'is_information_collector' => $attributeIsInformationCollector, 'can_translate' => $attributeIsTranslatable, 'placement' => $attributePlacement));
             $dataType = $classAttribute->dataType();
             $classAttribute->store();
             $dataType->unserializeContentClassAttribute($classAttribute, $classAttributeNode, $attributeDatatypeParameterNode);
             $classAttribute->sync();
         }
     }
     // 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);
     }
     return true;
 }
function updateClass($classId)
{
    global $cli, $script, $db, $scheduledScript;
    // If the class is not stored yet, store it now
    $class = eZContentClass::fetch($classId, true, eZContentClass::VERSION_STATUS_TEMPORARY);
    if ($class) {
        $cli->output("Storing class");
        $class->storeDefined($class->fetchAttributes());
    }
    // Fetch the stored class
    $class = eZContentClass::fetch($classId);
    if (!$class) {
        $cli->error('Could not fetch class with ID: ' . $classId);
        return;
    }
    $classAttributes = $class->fetchAttributes();
    $classAttributeIDs = array();
    foreach ($classAttributes as $classAttribute) {
        $classAttributeIDs[] = $classAttribute->attribute('id');
    }
    $objectCount = eZContentObject::fetchSameClassListCount($classId);
    $cli->output('Number of objects to be processed: ' . $objectCount);
    $counter = 0;
    $offset = 0;
    $limit = 100;
    $objects = eZContentObject::fetchSameClassList($classId, true, $offset, $limit);
    // Add and/or remove attributes for all versions and translations of all objects of this class
    while (count($objects) > 0) {
        // Run a transaction per $limit objects
        $db->begin();
        foreach ($objects as $object) {
            $contentObjectID = $object->attribute('id');
            $objectVersions = $object->versions();
            foreach ($objectVersions as $objectVersion) {
                $versionID = $objectVersion->attribute('version');
                $translations = $objectVersion->translations();
                foreach ($translations as $translation) {
                    $translationName = $translation->attribute('language_code');
                    // Class attribute IDs of object attributes (not necessarily the same as those in the class, hence the manual sql)
                    $objectClassAttributeIDs = array();
                    $rows = $db->arrayQuery("SELECT id,contentclassattribute_id, data_type_string\n                                              FROM ezcontentobject_attribute\n                                              WHERE contentobject_id = '{$contentObjectID}' AND\n                                                    version = '{$versionID}' AND\n                                                    language_code='{$translationName}'");
                    foreach ($rows as $row) {
                        $objectClassAttributeIDs[$row['id']] = $row['contentclassattribute_id'];
                    }
                    // Quick array diffs
                    $attributesToRemove = array_diff($objectClassAttributeIDs, $classAttributeIDs);
                    // Present in the object, not in the class
                    $attributesToAdd = array_diff($classAttributeIDs, $objectClassAttributeIDs);
                    // Present in the class, not in the object
                    // Remove old attributes
                    foreach ($attributesToRemove as $objectAttributeID => $classAttributeID) {
                        $objectAttribute = eZContentObjectAttribute::fetch($objectAttributeID, $versionID);
                        if (!is_object($objectAttribute)) {
                            continue;
                        }
                        $objectAttribute->remove($objectAttributeID);
                    }
                    // Add new attributes
                    foreach ($attributesToAdd as $classAttributeID) {
                        $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentObjectID, $versionID, $translationName);
                        if (!is_object($objectAttribute)) {
                            continue;
                        }
                        $objectAttribute->setAttribute('language_code', $translationName);
                        $objectAttribute->initialize();
                        $objectAttribute->store();
                        $objectAttribute->postInitialize();
                    }
                }
            }
            // Progress bar and Script Monitor progress
            $cli->output('.', false);
            $counter++;
            if ($counter % 70 == 0 or $counter >= $objectCount) {
                $progressPercentage = $counter / $objectCount * 100;
                $cli->output(sprintf(' %01.1f %%', $progressPercentage));
                if ($scheduledScript) {
                    $scheduledScript->updateProgress($progressPercentage);
                }
            }
        }
        $db->commit();
        $offset += $limit;
        $objects = eZContentObject::fetchSameClassList($classId, true, $offset, $limit);
    }
    // Set the object name to the first attribute, if not set
    $classAttributes = $class->fetchAttributes();
    // Fetch the first attribute
    if (count($classAttributes) > 0 && trim($class->attribute('contentobject_name')) == '') {
        $db->begin();
        $identifier = $classAttributes[0]->attribute('identifier');
        $identifier = '<' . $identifier . '>';
        $class->setAttribute('contentobject_name', $identifier);
        $class->store();
        $db->commit();
    }
}
global $cli;
global $currencyList;
$currencyList = false;
$cli = eZCLI::instance();
$script = eZScript::instance(array('description' => "\n" . "This script will convert objects with 'price' datatype to\n" . "the objects with 'multiprice' datatype.\n", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true, 'user' => true));
$script->startup();
$scriptOptions = $script->getOptions("", "", array(), false, array('user' => true));
$script->initialize();
$convertedObjectsCount = 0;
$classList = eZContentClass::fetchList();
$db = eZDB::instance();
$db->begin();
foreach ($classList as $class) {
    if (eZShopFunctions::isSimplePriceClass($class)) {
        $classID = $class->attribute('id');
        $objectListCount = eZContentObject::fetchSameClassListCount($classID);
        if ($objectListCount == 0) {
            $cli->output("No objects found for '" . $class->attribute('name') . "' class");
            continue;
        }
        $cli->output("Processing objects of the '" . $class->attribute('name') . "' class");
        $defaultCurrency = currencyForLocale();
        if (!$defaultCurrency) {
            $script->shutdown(1);
        }
        $defaultCurrencyCode = $defaultCurrency->attribute('code');
        $priceClassAttribute = eZShopFunctions::priceAttribute($class);
        $priceClassAttributeID = $priceClassAttribute->attribute('id');
        // replace 'ezprice' class attribute with 'ezmultiprice'.
        $priceClassAttribute->setAttribute('data_type_string', 'ezmultiprice');
        $priceClassAttribute->setAttribute(eZMultiPriceType::DEFAULT_CURRENCY_CODE_FIELD, $defaultCurrencyCode);
Exemplo n.º 5
0
Arquivo: index.php Projeto: truffo/eep
 private function deleteClass($classIdentifier)
 {
     $chunkSize = 1000;
     $classId = eZContentClass::classIDByIdentifier($classIdentifier);
     $contentClass = eZContentClass::fetch($classId);
     if (!$contentClass) {
         throw new Exception("Failed to instantiate content class. [" . $classIdentifier . "]");
     }
     $totalObjectCount = eZContentObject::fetchSameClassListCount($classId);
     echo "Deleting " . $totalObjectCount . " objects.\n";
     $moreToDelete = 0 < $totalObjectCount;
     $totalDeleted = 0;
     // need to operate in a privileged account - use doug@mugo.ca
     $adminUserObject = eZUser::fetch(eepSetting::PrivilegedAccountId);
     $adminUserObject->loginCurrent();
     while ($moreToDelete) {
         $params["IgnoreVisibility"] = true;
         $params['Limitation'] = array();
         $params['Limit'] = $chunkSize;
         $params['ClassFilterType'] = "include";
         $params['ClassFilterArray'] = array($classIdentifier);
         $children = eZContentObjectTreeNode::subTreeByNodeID($params, 2);
         foreach ($children as $child) {
             $info = eZContentObjectTreeNode::subtreeRemovalInformation(array($child->NodeID));
             if (!$info["can_remove_all"]) {
                 $msg = " permission is denied for nodeid=" . $child->NodeID;
                 // todo, this can yield an infinite loop if some objects are
                 // not deleteable, but you don't take that number into account
                 // at the bottom of the loop - where there will always be
                 // some >0 number of undeleteable objects left
                 echo $msg . "\n";
                 continue;
             }
             $removeResult = eZContentObjectTreeNode::removeSubtrees(array($child->NodeID), false, false);
             if (true === $removeResult) {
                 $totalDeleted += 1;
             } else {
                 $msg = " failed to delete nodeid=" . $child->NodeID;
                 echo $msg . "\n";
             }
             echo "Percent complete: " . sprintf("% 3.3f", $totalDeleted / $totalObjectCount * 100.0) . "%\r";
             unset($GLOBALS['eZContentObjectContentObjectCache']);
             unset($GLOBALS['eZContentObjectDataMapCache']);
             unset($GLOBALS['eZContentObjectVersionCache']);
         }
         $moreToDelete = 0 < eZContentObject::fetchSameClassListCount($classId);
     }
     echo "\nDone deleting objects.\n";
     $adminUserObject->logoutCurrent();
     eZContentClassClassGroup::removeClassMembers($classId, 0);
     eZContentClassClassGroup::removeClassMembers($classId, 1);
     // Fetch real version and remove it
     $contentClass->remove(true);
     // this seems to mainly cause an exception, might be an idea to simply skip it
     // Fetch temp version and remove it
     $tempDeleteClass = eZContentClass::fetch($classId, true, 1);
     if ($tempDeleteClass != null) {
         $tempDeleteClass->remove(true, 1);
     }
 }
 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();
 }
Exemplo n.º 7
0
 /**
  * update all the objects with the new attribute info
  * todo; this might have to support processing in batches
  */
 static function updateContentObjectAttributes($contentClass, $classAttributeID, $identifier = false)
 {
     $classId = $contentClass->attribute("id");
     // update object attributes
     $countProcessed = 0;
     $batchSize = 200;
     $totalObjectCount = eZContentObject::fetchSameClassListCount($classId);
     for ($offset = 0; $offset < $totalObjectCount; $offset += $batchSize) {
         $objects = eZContentObject::fetchSameClassList($classId, false, $offset, $batchSize);
         foreach ($objects as $num => $object) {
             $object = eZContentObject::fetch($object["id"]);
             if ($object) {
                 $contentobjectID = $object->attribute("id");
                 $objectVersions = $object->versions();
                 foreach ($objectVersions as $objectVersion) {
                     $translations = $objectVersion->translations(false);
                     $version = $objectVersion->attribute("version");
                     $dataMap = $objectVersion->attribute("data_map");
                     if ($identifier && isset($dataMap[$identifier])) {
                         // Attribute already exists for this object version
                     } else {
                         foreach ($translations as $translation) {
                             $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentobjectID, $version);
                             $objectAttribute->setAttribute("language_code", $translation);
                             $objectAttribute->initialize();
                             $objectAttribute->store();
                             $objectAttribute->postInitialize();
                         }
                     }
                 }
                 $countProcessed += 1;
             }
             echo "Percent complete: " . sprintf("% 3.2f", $countProcessed / $totalObjectCount * 100.0) . "%\r";
         }
         unset($GLOBALS["eZContentObjectContentObjectCache"]);
         unset($GLOBALS["eZContentObjectDataMapCache"]);
         unset($GLOBALS["eZContentObjectVersionCache"]);
         unset($objects);
     }
     echo "\n";
 }
<?php

$db     = eZDB::instance();
$class  = eZContentClass::fetchByIdentifier('article');
$count  = (int) eZContentObject::fetchSameClassListCount($class->ID);
$offset = 0;

$db->arrayQuery('TRUNCATE TABLE mm_rating;');
$db->arrayQuery('TRUNCATE TABLE mm_readcount;');

$progressBar = new ezcConsoleProgressbar( new ezcConsoleOutput(), $count, array(
    'emptyChar' => ' ',
    'barChar'   => '='
) );

$ratingQuery = 'INSERT INTO mm_rating (object_id, cluster_identifier, rating, counter, to_reindex) VALUES ';
$readQuery   = 'INSERT INTO mm_readcount (node_id, cluster_identifier, date, count, to_reindex) VALUES ';

while($count > 0)
{
    $objects = eZContentObject::fetchSameClassList($class->ID, false, $offset, 100);

    foreach($objects as $row)
    {
        $ratingValues = array();

        for($i=1; $i <= 10; $i++)
        {
            $ratingValues[] = sprintf("(%s, 'cluster_france', %s, %s, 1)", $row['id'], $i, mt_rand(0, 200));
        }
Exemplo n.º 9
0
 public static function addClassAttributes($class_identifier, $attributesInfo)
 {
     if (isset($class_identifier)) {
         $class = eZContentClass::fetchByIdentifier($class_identifier);
     }
     if (!is_object($class)) {
         return;
     }
     $classID = $class->attribute('id');
     foreach ($attributesInfo as $attributeInfo) {
         $classAttributeIdentifier = $attributeInfo['identifier'];
         $classAttributeName = $attributeInfo['name'];
         $datatype = $attributeInfo['data_type_string'];
         $defaultValue = isset($attributeInfo['default_value']) ? $attributeInfo['default_value'] : false;
         $canTranslate = isset($attributeInfo['can_translate']) ? $attributeInfo['can_translate'] : 1;
         $isRequired = isset($attributeInfo['is_required']) ? $attributeInfo['is_required'] : 0;
         $isSearchable = isset($attributeInfo['is_searchable']) ? $attributeInfo['is_searchable'] : 1;
         $attrContent = isset($attributeInfo['content']) ? $attributeInfo['content'] : false;
         $attrCreateInfo = array('identifier' => $classAttributeIdentifier, 'name' => $classAttributeName, 'can_translate' => $canTranslate, 'is_required' => $isRequired, 'is_searchable' => $isSearchable);
         $newAttribute = eZContentClassAttribute::create($classID, $datatype, $attrCreateInfo);
         $dataType = $newAttribute->dataType();
         $dataType->initializeClassAttribute($newAttribute);
         // not all datatype can have 'default_value'. do check here.
         if ($defaultValue !== false) {
             switch ($datatype) {
                 case 'ezboolean':
                     $newAttribute->setAttribute('data_int3', $defaultValue);
                     break;
                 default:
                     break;
             }
         }
         if ($attrContent) {
             $newAttribute->setContent($attrContent);
         }
         // store attribute, update placement, etc...
         $attributes = $class->fetchAttributes();
         $attributes[] = $newAttribute;
         // remove temporary version
         if ($newAttribute->attribute('id') !== null) {
             $newAttribute->remove();
         }
         $newAttribute->setAttribute('version', eZContentClass::VERSION_STATUS_DEFINED);
         $newAttribute->setAttribute('placement', count($attributes));
         $class->adjustAttributePlacements($attributes);
         foreach ($attributes as $attribute) {
             $attribute->storeDefined();
         }
         // update objects
         $classAttributeID = $newAttribute->attribute('id');
         $count = eZContentObject::fetchSameClassListCount($class->ID);
         $output = new ezcConsoleOutput();
         $bar = new ezcConsoleProgressbar($output, (int) $count);
         $offset = 0;
         $limit = 50;
         while (true) {
             if ($offset > $count) {
                 break;
             }
             $objects = eZContentObject::fetchSameClassList($classID, true, $offset, $limit);
             foreach ($objects as $object) {
                 $contentobjectID = $object->attribute('id');
                 $objectVersions = $object->versions();
                 foreach ($objectVersions as $objectVersion) {
                     $translations = $objectVersion->translations(false);
                     $version = $objectVersion->attribute('version');
                     foreach ($translations as $translation) {
                         $objectAttribute = eZContentObjectAttribute::create($classAttributeID, $contentobjectID, $version);
                         $objectAttribute->setAttribute('language_code', $translation);
                         $objectAttribute->initialize();
                         $objectAttribute->store();
                         $objectAttribute->postInitialize();
                     }
                 }
                 $bar->advance();
             }
             eZContentObject::clearCache();
             $offset += $limit;
         }
         $bar->finish();
     }
 }