} $db->commit(); // because we changed users, we have to remove content cache eZContentCacheManager::clearAllContentCache(); } if ($http->hasPostVariable("RemoveCustomerButton")) { if ($http->hasPostVariable("CustomerIDArray")) { $customerIDArray = $http->postVariable("CustomerIDArray"); $db = eZDB::instance(); $db->begin(); foreach ($customerIDArray as $customerID) { eZUserDiscountRule::removeUser($customerID); } $db->commit(); } eZContentCacheManager::clearAllContentCache(); } $membershipList = eZUserDiscountRule::fetchByRuleID($discountGroupID); $customers = array(); foreach ($membershipList as $membership) { $customers[] = eZContentObject::fetch($membership->attribute('contentobject_id')); } $ruleList = eZDiscountSubRule::fetchByRuleID($discountGroupID); $ruleArray = array(); foreach ($ruleList as $rule) { $name = $rule->attribute('name'); $percent = $rule->attribute('discount_percent'); $limitation = $rule->attribute('limitation'); $discountRuleID = $rule->attribute('id'); if ($limitation != '*') { $ruleValues = eZDiscountSubRuleValue::fetchBySubRuleID($discountRuleID);
/** * Stores the current class as a modified version, updates the contentobject_name * attribute and recreates the class group entries. * * @note It will remove classes in the previous and specified version before storing. * * @param array $attributes array of attributes * @param int $version version status * @since Version 4.3 */ public function storeVersioned($attributes, $version) { $previousVersion = $this->attribute('version'); $db = eZDB::instance(); $db->begin(); // Before removing anything from the attributes, load attribute information // which might otherwise not accessible when recreating them below. // See issue #18164 foreach ($attributes as $attribute) { $attribute->content(); } $this->removeAttributes(false, $version); $this->removeAttributes(false, $previousVersion); $this->remove(false); $this->setVersion($version, $attributes); $this->setAttribute("modifier_id", eZUser::currentUser()->attribute("contentobject_id")); $this->setAttribute("modified", time()); $this->adjustAttributePlacements($attributes); foreach ($attributes as $attribute) { $attribute->storeVersioned($version); } // Set contentobject_name to something sensible if it is missing if (count($attributes) > 0 && trim($this->attribute('contentobject_name')) == '') { $this->setAttribute('contentobject_name', '<' . $attributes[0]->attribute('identifier') . '>'); } // Recreate class member entries eZContentClassClassGroup::removeClassMembers($this->ID, $version); foreach (eZContentClassClassGroup::fetchGroupList($this->ID, $previousVersion) as $classgroup) { $classgroup->setAttribute('contentclass_version', $version); $classgroup->store(); } eZContentClassClassGroup::removeClassMembers($this->ID, $previousVersion); eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $time = time(); $handler->setTimestamp('user-class-cache', $time); $handler->setTimestamp('class-identifier-cache', $time); $handler->setTimestamp('sort-key-cache', $time); $handler->store(); eZContentCacheManager::clearAllContentCache(); $this->setAttribute('serialized_name_list', $this->NameList->serializeNames()); $this->setAttribute('serialized_description_list', $this->DescriptionList->serializeNames()); eZPersistentObject::store(); $this->NameList->store($this); $db->commit(); }
function removeRelatedCache($siteAccess) { // Delete compiled template $ini = eZINI::instance(); $iniPath = eZSiteAccess::findPathToSiteAccess($siteAccess); $siteINI = eZINI::instance('site.ini.append', $iniPath); if ($siteINI->hasVariable('FileSettings', 'CacheDir')) { $cacheDir = $siteINI->variable('FileSettings', 'CacheDir'); if ($cacheDir[0] == "/") { $cacheDir = eZDir::path(array($cacheDir)); } else { if ($siteINI->hasVariable('FileSettings', 'VarDir')) { $varDir = $siteINI->variable('FileSettings', 'VarDir'); $cacheDir = eZDir::path(array($varDir, $cacheDir)); } } } else { if ($siteINI->hasVariable('FileSettings', 'VarDir')) { $varDir = $siteINI->variable('FileSettings', 'VarDir'); $cacheDir = $ini->variable('FileSettings', 'CacheDir'); $cacheDir = eZDir::path(array($varDir, $cacheDir)); } else { $cacheDir = eZSys::cacheDirectory(); } } $compiledTemplateDir = $cacheDir . "/template/compiled"; eZDir::unlinkWildcard($compiledTemplateDir . "/", "*pagelayout*.*"); eZCache::clearByTag('template-block'); // Expire content view cache eZContentCacheManager::clearAllContentCache(); }
/** * Removes the language if there is no object having translation in it. * * \return True if the language was removed from the site, false otherwise. */ function removeThis() { if ($this->objectCount() > 0 or $this->classCount() > 0) { return false; } $this->remove(); eZContentCacheManager::clearAllContentCache(); eZContentLanguage::fetchList(true); return true; }
/** * Forza l'impostazione del colore di base di un site * * Ritorna true se il colore è stato modificato * * @param int $currentColor * @return boolean */ public static function forceSiteColor($currentColor) { // // lettura variabili per individuare file scss $designINIinstance = eZINI::instance('design.ini', 'settings', null, FALSE); $_stylesheetBaseFile = $designINIinstance->variable('StylesheetSettings', 'StylesheetBaseFile'); $_stylesheetDestFile = $designINIinstance->variable('StylesheetSettings', 'StylesheetDestinationFile'); $_stylesheetCluster = $designINIinstance->variable('StylesheetSettings', 'StylesheetCluster'); // Cicla sui file di origine for ($i = 0; $i < count($_stylesheetBaseFile); $i++) { foreach ($_stylesheetCluster as $itemCluster) { // File da sostituire. $curFile = $itemCluster . $_stylesheetBaseFile[$i]; $curDestinationFile = $itemCluster . $_stylesheetDestFile[$i]; //print_r('File :<br><b>'); //print_r($curFile); //print_r('<br>in:<br><b>'); //print_r($curDestinationFile); //die(); // recupera i valori del eZPersistentObject sinet_site_colors $colorList = Sinetsitecolors_PstObject::fetchHandlerList(); $fh = fopen($curFile, 'r'); $newRow = ''; // Legge ogni singola riga del file origine $arrayOriginalColor = explode("-", $currentColor); while (!feof($fh)) { $tmpRow = fgets($fh); $indiceColore = 0; foreach ($colorList as $objColor) { // per ogni riga del pesisten object sostituisce il name_tag con il colore letto $curname_tag = $objColor['name_tag']; if (count($arrayOriginalColor) > $indiceColore) { $tmpRow = PatBaseColorFunctions::replaceCssInLine($tmpRow, $arrayOriginalColor[$indiceColore], $curname_tag); } $indiceColore++; } $newRow .= $tmpRow; } // set del colore nel persistent object $indiceColore = 0; foreach ($colorList as $objColor) { $curname_tag = $objColor['name_tag']; $curId = $objColor['id']; if (count($arrayOriginalColor) > $indiceColore) { $simpleObj = Sinetsitecolors_PstObject::fetchById($curId); $simpleObj->setAttribute('color', $arrayOriginalColor[$indiceColore]); $simpleObj->store(); } $indiceColore++; } // Scrive il file di destinazione $fw = fopen($curDestinationFile, 'w'); if (!$fw) { echo '</b><font color=red>Errore Open W</font></pre>'; } else { $bytes = fwrite($fw, $newRow); fclose($fw); } fclose($fh); // echo('</b><font color=red>OK</font></pre>'); } } // Prova la pulizia della cache dei template eZContentCacheManager::clearAllContentCache(); eZContentCacheManager::clearContentCache(2); //die(); return true; }
static function move($nodeID, $newParentNodeID) { $result = false; if (!is_numeric($nodeID) || !is_numeric($newParentNodeID)) { return false; } $node = eZContentObjectTreeNode::fetch($nodeID); if (!$node) { return false; } $object = $node->object(); if (!$object) { return false; } $objectID = $object->attribute('id'); $oldParentNode = $node->fetchParent(); $oldParentObject = $oldParentNode->object(); // clear user policy cache if this is a user object if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) { eZUser::purgeUserCacheByUserId($object->attribute('id')); } // clear cache for old placement. // If child count exceeds threshold, do nothing here, and instead clear all view cache at the end. $childCountInThresholdRange = eZContentCache::inCleanupThresholdRange($node->childrenCount(false)); if ($childCountInThresholdRange) { eZContentCacheManager::clearContentCacheIfNeeded($objectID); } $db = eZDB::instance(); $db->begin(); $node->move($newParentNodeID); $newNode = eZContentObjectTreeNode::fetchNode($objectID, $newParentNodeID); if ($newNode) { $newNode->updateSubTreePath(true, true); if ($newNode->attribute('main_node_id') == $newNode->attribute('node_id')) { // If the main node is moved we need to check if the section ID must change $newParentNode = $newNode->fetchParent(); $newParentObject = $newParentNode->object(); if ($object->attribute('section_id') != $newParentObject->attribute('section_id')) { eZContentObjectTreeNode::assignSectionToSubTree($newNode->attribute('main_node_id'), $newParentObject->attribute('section_id'), $oldParentObject->attribute('section_id')); } } // modify assignment $curVersion = $object->attribute('current_version'); $nodeAssignment = eZNodeAssignment::fetch($objectID, $curVersion, $oldParentNode->attribute('node_id')); if ($nodeAssignment) { $nodeAssignment->setAttribute('parent_node', $newParentNodeID); $nodeAssignment->setAttribute('op_code', eZNodeAssignment::OP_CODE_MOVE); $nodeAssignment->store(); // update search index specifying we are doing a move operation $nodeIDList = array($nodeID); eZSearch::removeNodeAssignment($node->attribute('main_node_id'), $newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList); eZSearch::addNodeAssignment($newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList, true); } $result = true; } else { eZDebug::writeError("Node {$nodeID} was moved to {$newParentNodeID} but fetching the new node failed"); } $db->commit(); // clear cache for new placement. // If child count exceeds threshold, clear all view cache instead. if ($childCountInThresholdRange) { eZContentCacheManager::clearContentCacheIfNeeded($objectID); } else { eZContentCacheManager::clearAllContentCache(); } return $result; }
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(); }
/** * Removes the language if there is no object having translation in it. * * \return True if the language was removed from the site, false otherwise. */ function removeThis() { if ( ($this->objectCount() > 0) or ($this->classCount() > 0) ) { return false; } eZPersistentObject::remove(); eZContentCacheManager::clearAllContentCache(); eZContentLanguage::fetchList( true ); return true; }