static function remove($classID) { $contentClass = eZContentClass::fetch($classID); if ($contentClass == null or !$contentClass->isRemovable()) { return false; } // Remove all objects $contentObjects = eZContentObject::fetchSameClassList($classID); foreach ($contentObjects as $contentObject) { eZContentObjectOperations::remove($contentObject->attribute('id')); } if (count($contentObjects) == 0) { eZContentObject::expireAllViewCache(); } eZContentClassClassGroup::removeClassMembers($classID, 0); eZContentClassClassGroup::removeClassMembers($classID, 1); // Fetch real version and remove it $contentClass->remove(true); // Fetch temp version and remove it $tempDeleteClass = eZContentClass::fetch($classID, true, 1); if ($tempDeleteClass != null) { $tempDeleteClass->remove(true, 1); } return true; }
function initSettings($parameters) { $siteINI = eZINI::instance(); $classIdentifier = 'template_look'; //get the class $class = eZContentClass::fetchByIdentifier($classIdentifier, true, eZContentClass::VERSION_STATUS_TEMPORARY); if (!$class) { $class = eZContentClass::fetchByIdentifier($classIdentifier, true, eZContentClass::VERSION_STATUS_DEFINED); if (!$class) { eZDebug::writeError("Warning, DEFINED version for class identifier {$classIdentifier} does not exist."); return; } } $classId = $class->attribute('id'); $this->Settings['template_look_class_id'] = $classId; $objects = eZContentObject::fetchSameClassList($classId); if (!count($objects)) { eZDebug::writeError("Object of class {$classIdentifier} does not exist."); return; } $templateLookObject = $objects[0]; $this->Settings['template_look_object'] = $templateLookObject; $this->Settings['template_look_object_id'] = $templateLookObject->attribute('id'); if (!is_array($parameters)) { return; } $this->addSetting('admin_account_id', eZSiteInstaller::getParam($parameters, 'object_remote_map/1bb4fe25487f05527efa8bfd394cecc7', '')); $this->addSetting('guest_accounts_id', eZSiteInstaller::getParam($parameters, 'object_remote_map/5f7f0bdb3381d6a461d8c29ff53d908f', '')); $this->addSetting('anonymous_accounts_id', eZSiteInstaller::getParam($parameters, 'object_remote_map/15b256dbea2ae72418ff5facc999e8f9', '')); $this->addSetting('package_object', eZSiteInstaller::getParam($parameters, 'package_object', false)); $this->addSetting('design_list', eZSiteInstaller::getParam($parameters, 'design_list', array())); $this->addSetting('main_site_design', strtolower($this->solutionName())); $this->addSetting('extension_list', array('ezwt', 'ezstarrating', 'ezgmaplocation', strtolower($this->solutionName()))); $this->addSetting('version', $this->solutionVersion()); $this->addSetting('locales', eZSiteInstaller::getParam($parameters, 'all_language_codes', array())); // usual user siteaccess like 'ezwebin_site' $this->addSetting('user_siteaccess', eZSiteInstaller::getParam($parameters, 'user_siteaccess', '')); // usual admin siteaccess like 'ezwebin_site_admin' $this->addSetting('admin_siteaccess', eZSiteInstaller::getParam($parameters, 'admin_siteaccess', '')); // extra siteaccess based on languages info, like 'eng', 'rus', ... $this->addSetting('language_based_siteaccess_list', $this->languageNameListFromLocaleList($this->setting('locales'))); $this->addSetting('user_siteaccess_list', array_merge(array($this->setting('user_siteaccess')), $this->setting('language_based_siteaccess_list'))); $this->addSetting('all_siteaccess_list', array_merge($this->setting('user_siteaccess_list'), array($this->setting('admin_siteaccess')))); $this->addSetting('access_type', eZSiteInstaller::getParam($parameters, 'site_type/access_type', '')); $this->addSetting('access_type_value', eZSiteInstaller::getParam($parameters, 'site_type/access_type_value', '')); $this->addSetting('admin_access_type_value', eZSiteInstaller::getParam($parameters, 'site_type/admin_access_type_value', '')); $this->addSetting('host', eZSiteInstaller::getParam($parameters, 'host', '')); $siteaccessUrls = array('admin' => $this->createSiteaccessUrls(array('siteaccess_list' => array($this->setting('admin_siteaccess')), 'access_type' => $this->setting('access_type'), 'access_type_value' => $this->setting('admin_access_type_value'), 'host' => $this->setting('host'), 'host_prepend_siteaccess' => false)), 'user' => $this->createSiteaccessUrls(array('siteaccess_list' => array($this->setting('user_siteaccess')), 'access_type' => $this->setting('access_type'), 'access_type_value' => $this->setting('access_type_value'), 'host' => $this->setting('host'), 'host_prepend_siteaccess' => false)), 'translation' => $this->createSiteaccessUrls(array('siteaccess_list' => $this->setting('language_based_siteaccess_list'), 'access_type' => $this->setting('access_type'), 'access_type_value' => $this->setting('access_type_value') + 1, 'host' => $this->setting('host'), 'exclude_port_list' => array($this->setting('admin_access_type_value'), $this->setting('access_type_value'))))); $this->addSetting('siteaccess_urls', $siteaccessUrls); $this->addSetting('primary_language', eZSiteInstaller::getParam($parameters, 'all_language_codes/0', '')); $this->addSetting('var_dir', eZSiteInstaller::getParam($parameters, 'var_dir', 'var/' . $this->setting('user_siteaccess'))); }
function objectList() { return eZContentObject::fetchSameClassList($this->ID); }
} $canRemoveCount = 0; foreach ($deleteIDArray as $deleteID) { $ClassObjectsCount = 0; $class = eZContentClass::fetch($deleteID); if ($class != null) { $class = eZContentClass::fetch($deleteID); $ClassID = $class->attribute('id'); $ClassName = $class->attribute('name'); if (!$class->isRemovable()) { $item = array("className" => $ClassName, 'objectCount' => 0, "is_removable" => false, 'reason' => $class->removableInformation()); $DeleteResult[] = $item; continue; } ++$canRemoveCount; $classObjects = eZContentObject::fetchSameClassList($ClassID); $ClassObjectsCount = count($classObjects); $item = array("className" => $ClassName, "is_removable" => true, "objectCount" => $ClassObjectsCount); $DeleteResult[] = $item; } } $canRemove = $canRemoveCount > 0; $Module->setTitle(ezpI18n::tr('kernel/class', 'Remove classes %class_id', null, array('%class_id' => $ClassID))); $tpl = eZTemplate::factory(); $tpl->setVariable('module', $Module); $tpl->setVariable('GroupID', $GroupID); $tpl->setVariable('DeleteResult', $DeleteResult); $tpl->setVariable('already_removed', $alreadyRemoved); $tpl->setVariable('can_remove', $canRemove); $Result = array(); $Result['content'] = $tpl->fetch("design:class/removeclass.tpl");
private function attribute_migrate($classIdentifier, $srcAttribute, $conversion, $destAttribute) { $contentClass = eZContentClass::fetchByIdentifier($classIdentifier); if (!$contentClass) { throw new Exception("Failed to instantiate content class [" . $classIdentifier . "]"); } $classDataMap = $contentClass->attribute("data_map"); if (!isset($classDataMap[$srcAttribute])) { throw new Exception("Content class '" . $classIdentifier . "' does not contain this attribute: [" . $srcAttribute . "]"); } if (!isset($classDataMap[$destAttribute])) { throw new Exception("Content class '" . $classIdentifier . "' does not contain this attribute: [" . $destAttribute . "]"); } $classId = $contentClass->attribute("id"); $objects = eZContentObject::fetchSameClassList($classId, false); $numObjects = count($objects); $conversionFunc = null; switch ($conversion) { default: echo "This mapping is not supported: [" . $conversion . "]\n"; return; break; case "rot13": $conversionFunc = "convertStringToRot13"; break; case "time2integer": $conversionFunc = "convertTimeToInteger"; break; case "trim": $conversionFunc = "convertTrim"; break; case "date2ts": $conversionFunc = "dateToTS"; break; } foreach ($objects as $n => $object) { $object = eZContentObject::fetch($object["id"]); if ($object) { // copy data with conversion $dataMap = $object->DataMap(); $src = $dataMap[$srcAttribute]; $dest = $dataMap[$destAttribute]; $dest->fromString(eep::$conversionFunc($src->toString())); $dest->store(); // publish to get changes recognized, eg object title updated eep::republishObject($object->attribute("id")); } echo "Percent complete: " . sprintf("% 3.3f", ($n + 1.0) / $numObjects * 100.0) . "%\r"; // clear caches unset($GLOBALS["eZContentObjectContentObjectCache"]); unset($GLOBALS["eZContentObjectDataMapCache"]); unset($GLOBALS["eZContentObjectVersionCache"]); unset($object); } echo "\n"; }
function addClassAttributes( $params ) { $classInfo = $params['class']; $attributesInfo = $params['attributes']; $classID = isset( $classInfo['id'] ) ? $classInfo['id'] : false; if( $classID ) { $class = eZContentClass::fetch( $classID ); } else { if( isset( $classInfo['identifier'] ) ) { $class = eZSiteInstaller::classByIdentifier( $classInfo ); } else { $this->reportError( "neither 'id' nor 'identifier' is set for content class" , 'eZSiteInstaller::addClassAttribute' ); } } if( !is_object( $class ) ) { $this->reportError( "Can't fetch content class" , 'eZSiteInstaller::addClassAttribute' ); 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'] : 0; $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' ); $objects = eZContentObject::fetchSameClassList( $classID ); 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(); } } } } }
/** * Initialize the attribute in the existing objects. * * @param mixed $objects not used, the existing objects are fetched if * necessary (depending on the datatype of the attribute). */ function initializeObjectAttributes( &$objects = null ) { $classAttributeID = $this->ID; $classID = $this->ContentClassID; $dataType = $this->attribute( 'data_type' ); if ( $dataType->supportsBatchInitializeObjectAttribute() ) { $db = eZDB::instance(); $data = array( 'contentobject_id' => 'a.contentobject_id', 'version' => 'a.version', 'contentclassattribute_id' => $classAttributeID, 'data_type_string' => "'" . $db->escapeString( $this->DataTypeString ) . "'", 'language_code' => 'a.language_code', 'language_id' => 'MAX(a.language_id)' ); $datatypeData = $dataType->batchInitializeObjectAttributeData( $this ); $data = array_merge( $data, $datatypeData ); $cols = implode( ', ', array_keys( $data ) ); $values = implode( ', ', $data ); $sql = "INSERT INTO ezcontentobject_attribute( $cols ) SELECT $values FROM ezcontentobject_attribute a, ezcontentobject o WHERE o.id = a.contentobject_id AND o.contentclass_id=$classID GROUP BY contentobject_id, version, language_code"; $db->query( $sql ); // update ids to keep them same with one attribute for different versions if( $db->databaseName() == 'mysql' ) { $updateSql = "UPDATE ezcontentobject_attribute, ( SELECT contentobject_id, language_code, version, contentclassattribute_id, MIN( id ) AS minid FROM ezcontentobject_attribute WHERE contentclassattribute_id = $classAttributeID GROUP BY contentobject_id, language_code, version, contentclassattribute_id ) t SET ezcontentobject_attribute.id = t.minid WHERE ezcontentobject_attribute.contentobject_id = t.contentobject_id AND ezcontentobject_attribute.language_code = t.language_code AND ezcontentobject_attribute.contentclassattribute_id = $classAttributeID"; } else if( $db->databaseName() == 'postgresql' ) { $updateSql = "UPDATE ezcontentobject_attribute SET id=t.minid FROM ( SELECT contentobject_id, language_code, version, contentclassattribute_id, MIN( id ) AS minid FROM ezcontentobject_attribute WHERE contentclassattribute_id = $classAttributeID GROUP BY contentobject_id, language_code, version, contentclassattribute_id ) t WHERE ezcontentobject_attribute.contentobject_id = t.contentobject_id AND ezcontentobject_attribute.language_code = t.language_code AND ezcontentobject_attribute.contentclassattribute_id = $classAttributeID"; } else if( $db->databaseName() == 'oracle' ) { $updateSql = "UPDATE ezcontentobject_attribute a SET a.id = ( SELECT MIN( id ) FROM ezcontentobject_attribute b WHERE b.contentclassattribute_id = $classAttributeID AND b.contentobject_id = a.contentobject_id AND b.language_code = a.language_code ) WHERE a.contentclassattribute_id = $classAttributeID"; } else { $updateSql = ""; } $db->query( $updateSql ); } else { $limit = 1000; $offset = 0; while ( true ) { $contentObjects = eZContentObject::fetchSameClassList( $classID, true, $offset, $limit ); if ( empty( $contentObjects ) ) { break; } foreach ( $contentObjects as $object ) { $contentobjectID = $object->attribute( 'id' ); $objectVersions = $object->versions(); // the start version ID, to make sure one attribute in different version has same id. $startAttributeID = array(); foreach ( $objectVersions as $objectVersion ) { $translations = $objectVersion->translations( false ); $version = $objectVersion->attribute( 'version' ); foreach ( $translations as $translation ) { $objectAttribute = eZContentObjectAttribute::create( $classAttributeID, $contentobjectID, $version, $translation ); if( array_key_exists( $translation, $startAttributeID ) ) { $objectAttribute->setAttribute( 'id', $startAttributeID[$translation] ); } $objectAttribute->setAttribute( 'language_code', $translation ); $objectAttribute->initialize(); $objectAttribute->store(); if( !array_key_exists( $translation, $startAttributeID ) ) { $startAttributeID[$translation] = $objectAttribute->attribute( 'id' ); } $objectAttribute->postInitialize(); } } } $offset += $limit; eZContentObject::clearCache(); } } }
$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); $priceClassAttribute->store(); unset($GLOBALS['eZContentClassAttributeCache'][$priceClassAttributeID]); // update objects $offset = 0; $limit = 1000; $cli->output('Converting', false); while ($offset < $objectListCount) { $objectList = eZContentObject::fetchSameClassList($class->attribute('id'), true, $offset, $limit); $offset += count($objectList); foreach ($objectList as $object) { $contentObjectID = $object->attribute('id'); $objectVersions =& $object->versions(); foreach ($objectVersions as $objectVersion) { $version = $objectVersion->attribute('version'); $objectAttributeList = eZContentObjectAttribute::fetchSameClassAttributeIDList($priceClassAttributeID, true, $version, $contentObjectID); foreach ($objectAttributeList as $objectAttribute) { $priceValue = $objectAttribute->attribute('data_float'); $multiprice = eZMultiPriceData::create($objectAttribute->attribute('id'), $version, $defaultCurrencyCode, $priceValue, eZMultiPriceData::VALUE_TYPE_CUSTOM); $multiprice->store(); $objectAttribute->setAttribute('data_type_string', 'ezmultiprice'); $objectAttribute->setAttribute('data_float', 0); $objectAttribute->setAttribute('sort_key_int', 0); $objectAttribute->store();
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(); } }
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(); }
function initializeObjectAttributes(&$objects = null) { $classAttributeID = $this->ID; $classID = $this->ContentClassID; $dataType = $this->attribute('data_type'); if ($dataType->supportsBatchInitializeObjectAttribute()) { $db = eZDB::instance(); $data = array('contentobject_id' => 'a.contentobject_id', 'version' => 'a.version', 'contentclassattribute_id' => $classAttributeID, 'data_type_string' => "'" . $db->escapeString($this->DataTypeString) . "'", 'language_code' => 'a.language_code', 'language_id' => 'MAX(a.language_id)'); $datatypeData = $dataType->batchInitializeObjectAttributeData($this); $data = array_merge($data, $datatypeData); $cols = implode(', ', array_keys($data)); $values = implode(', ', $data); $sql = "INSERT INTO ezcontentobject_attribute( {$cols} )\n SELECT {$values}\n FROM ezcontentobject_attribute a, ezcontentobject o\n WHERE o.id = a.contentobject_id AND\n o.contentclass_id={$classID}\n GROUP BY contentobject_id,\n version,\n language_code"; $db->query($sql); } else { if (!is_array($objects)) { $objects = eZContentObject::fetchSameClassList($classID); } 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, $translation); $objectAttribute->setAttribute('language_code', $translation); $objectAttribute->initialize(); $objectAttribute->store(); $objectAttribute->postInitialize(); } } } } }
private function fetchallinstances($classIdentifier, $additional) { $limit = false; if (isset($additional["limit"])) { $limit = $additional["limit"]; } $offset = false; if (isset($additional["offset"])) { $offset = $additional["offset"]; } $classId = eZContentClass::classIDByIdentifier($classIdentifier); $allInstances = eZContentObject::fetchSameClassList($classId, false, $offset, $limit); $title = "All instances of content class '" . $classIdentifier . "'"; eep::displayNonObjectList($allInstances, $title); }
/** * 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"; }
$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)); } $db->arrayQuery($ratingQuery . implode(', ', $ratingValues) . ';'); $readValues = array(); $nodes = eZContentObjectTreeNode::fetchByContentObjectID($row['id'], false);
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(); } }