/** * Fetch content class attributes by dataTypestring * * @param array $imageDataTypeStrings array of image datatype strings. ie: array( 'ezimage' ) * @return array Array of content class attributes, empty array if not * @static */ static function fetchContentClassImageAttributes($imageDataTypeStrings = false) { $contentClassImageAttributes = array(); if (!is_array($imageDataTypeStrings)) { // Default datatypes to create image alias variations $imageDataTypeStrings = eZINI::instance('bcimagealias.ini')->variable('BCImageAliasSettings', 'ImageDataTypeStringList'); } foreach ($imageDataTypeStrings as $dataTypeString) { $contentClassImageAttributes = array_merge($contentClassImageAttributes, eZContentClassAttribute::fetchList(true, array('data_type' => $dataTypeString))); } return $contentClassImageAttributes; }
/** * Get an array of all defined class attributes with ezxmltext datatype. * * @return array */ public function xmlClassAttributeIds() { if ($this->xmlClassAttributeIdArray === null) { // First we want to find all class attributes which are defined. We won't be touching // attributes which are in a transient state. $xmlTextAttributes = eZContentClassAttribute::fetchList(true, array('data_type' => 'ezxmltext', 'version' => 0)); $this->xmlClassAttributeIdArray = array(); foreach ($xmlTextAttributes as $classAttr) { $this->xmlClassAttributeIdArray[] = $classAttr->attribute('id'); } unset($xmlTextAttributes); } return $this->xmlClassAttributeIdArray; }
/** * Purges the image aliases of all ezimage attribute. The original image is * kept. * * @param array $cacheItem * @access public */ static function purgeImageAlias($cacheItem) { // 1. fetch ezcontentclass having an ezimage attribute // 2. fetch objects of these classes // 3. purge image alias for all version $imageContentClassAttributes = eZContentClassAttribute::fetchList(true, array('data_type' => 'ezimage', 'version' => eZContentClass::VERSION_STATUS_DEFINED)); $classIds = array(); $attributeIdentifiersByClass = array(); foreach ($imageContentClassAttributes as $ccAttr) { $identifier = $ccAttr->attribute('identifier'); $ccId = $ccAttr->attribute('contentclass_id'); if (!isset($attributeIdentifiersByClass[$ccId])) { $attributeIdentifiersByClass[$ccId] = array(); } $attributeIdentifiersByClass[$ccId][] = $identifier; $classIds[] = $ccId; } $subTreeParams = array('ClassFilterType' => 'include', 'ClassFilterArray' => $classIds, 'MainNodeOnly' => true, 'IgnoreVisibility' => true, 'LoadDataMap' => false, 'Limit' => 100, 'Offset' => 0); $count = 0; while (true) { $nodes = eZContentObjectTreeNode::subTreeByNodeID($subTreeParams, 1); if (empty($nodes)) { break; } foreach ($nodes as $node) { call_user_func($cacheItem['reporter'], '', $count); $object = $node->attribute('object'); self::purgeImageAliasForObject($cacheItem, $object, $attributeIdentifiersByClass[$object->attribute('contentclass_id')]); $count++; } eZContentObject::clearCache(); $subTreeParams['Offset'] += $subTreeParams['Limit']; } self::clearImageAlias($cacheItem); }
private function listAllAttributes() { $attributeList = @eZContentClassAttribute::fetchList(); $contentClassList = eZContentClass::fetchAllClasses(true, false, false); $classDictionary = array(); foreach ($contentClassList as $classInfo) { $classId = $classInfo->ID; $classDictionary[$classInfo->ID] = $classInfo->Identifier; } $results = array(); $results[] = array("ID", "Identifier", "Data Type", "Content Class ID", "Content class identifier"); foreach ($attributeList as $attributeInfo) { $attributeId = $attributeInfo->ID; $ContentClassID = $attributeInfo->ContentClassID; $results[] = array($attributeId, $attributeInfo->Identifier, $attributeInfo->DataTypeString, $attributeInfo->ContentClassID, isset($classDictionary[$attributeInfo->ContentClassID]) ? $classDictionary[$attributeInfo->ContentClassID] : "Doesn't exist"); } eep::printTable($results, "list all attributes"); }
/** * Checks for integrity all object attributes of a given datatype. Or for a single attribute of one class. * The rules applied for each datatype depend on ini settings. * The datatype to check is set via loadDatatypeChecks() * * @param string $type datatype name or classidentifier/attributeidentifier * @param bool $also_unpublished * @return array * @throws Exception */ public function check($type, $also_unpublished = false) { $classIdentifierFilter = null; $attributeIdentifierFilter = null; if ($this->isAttributeDefinition($type)) { list($classIdentifierFilter, $attributeIdentifierFilter) = $this->parseAttributeDefinition($type); $type = $this->datatypeByAttributeDefinition($type); } if (!isset($this->checkerClasses[$type])) { $this->loadDatatypeChecksforType($type); } $warnings = array(); // Loop over all class attributes using the datatype: $classAttributes = eZContentClassAttribute::fetchList(true, array('version' => eZContentClass::VERSION_STATUS_DEFINED, 'data_type' => $type)); $db = eZDB::instance(); foreach ($classAttributes as $classAttribute) { $classIdentifier = eZContentClass::classIdentifierByID($classAttribute->attribute('contentclass_id')); $attributeIdentifier = $classAttribute->attribute('identifier'); if ($classIdentifierFilter !== null && $classIdentifier !== $classIdentifierFilter || $attributeIdentifierFilter !== null && $attributeIdentifier !== $attributeIdentifierFilter) { continue; } $this->output("Checking attribute '{$attributeIdentifier}' in class '{$classIdentifier}'..."); // the checkers get initialized once per class attribute $checkers = array(); foreach ($this->checkerClasses[$type] as $key => $checkerClass) { $checkers[$key] = call_user_func_array(array($checkerClass, 'instance'), array($classAttribute)); } $offset = 0; $total = 0; do { $tables = 'ezcontentobject_attribute'; $where = 'contentclassattribute_id = ' . $classAttribute->attribute('id'); if (!$also_unpublished) { $tables .= ', ezcontentobject'; $where .= ' AND ezcontentobject.id = ezcontentobject_attribute.contentobject_id' . ' AND ezcontentobject.current_version = ezcontentobject_attribute.version' . ' AND ezcontentobject.status = 1'; } $query = "SELECT ezcontentobject_attribute.* " . "FROM {$tables} " . "WHERE {$where}"; $rows = $db->arrayQuery($query, array('offset' => $offset, 'limit' => $this->limit)); if ($rows === false) { throw new Exception("DB Error, something is deeply wrong here"); } foreach ($rows as $row) { foreach ($checkers as $checker) { $problems = $checker->checkObjectAttribute($row); if (count($problems)) { $warnings = array_merge($warnings, $problems); } } } $offset += $this->limit; $total += count($rows); } while (count($rows) > 0); $this->output("Checked {$total} object attributes"); } return $warnings; }
public function attributeDecoder($event, $attr) { switch ($attr) { case 'handlers': return nxcSocialNetworksPublishHandler::fetchList($event->attribute('id')); case 'available_handler_names': if (count(self::$handlerNames) === 0) { $types = nxcSocialNetworksPublishHandler::getTypes(); foreach ($types as $type => $handlerClass) { try { $handler = new $handlerClass(array()); self::$handlerNames[$type] = $handler->attribute('name'); unset($handler); } catch (Exception $e) { } } } return self::$handlerNames; case 'available_shorten_handler_names': if (count(self::$shortenHandlerNames) === 0) { $types = nxcSocialNetworksLinkShortenHandler::getHandlers(); foreach ($types as $type => $shortenHandlerClass) { try { $shortenHandler = new $shortenHandlerClass(array()); self::$shortenHandlerNames[$type] = $shortenHandler->name; unset($shortenHandler); } catch (Exception $e) { } } } return self::$shortenHandlerNames; case 'available_message_handler_names': if (count(self::$messageHandlerNames) === 0) { $types = nxcSocialNetworksMessageHandler::getHandlers(); foreach ($types as $type => $messageHandlerClass) { try { $messageHandler = new $messageHandlerClass(array()); self::$messageHandlerNames[$type] = $messageHandler->name; unset($messageHandler); } catch (Exception $e) { } } } return self::$messageHandlerNames; case 'contentclass_attribute_list': if (count(self::$classAttributes) === 0) { $classAttributes = eZContentClassAttribute::fetchList(true, array('data_type' => array(array(eZStringType::DATA_TYPE_STRING, eZTextType::DATA_TYPE_STRING)))); // Sorting class attributes $sort = array(); $attrIDs = array(); foreach ($classAttributes as $attribute) { $class = eZContentClass::fetch($attribute->attribute('contentclass_id')); $sort[$attribute->attribute('id')] = $class->attribute('name') . $attribute->attribute('name'); $attrIDs[$attribute->attribute('id')] = $attribute; } asort($sort); self::$classAttributes = array(); foreach ($sort as $id => $sortString) { self::$classAttributes[$id] = $attrIDs[$id]; } } return self::$classAttributes; case 'affected_class_ids': return unserialize($event->attribute('data_text1')); default: return null; } }