Pre-populate the cache for Versioned::get_versionnumber_by_stage() for
a list of record IDs, for more efficient database querying.  If $idList
is null, then every record will be pre-cached.

@param string $class
@param string $stage
@param array $idList
188208
public static function prepopulate_numchildren_cache($baseClass, $idList = null)
    {
        if (!Config::inst()->get(static::class, 'prepopulate_numchildren_cache')) {
            return;
        }

        /** @var Versioned|DataObject $singleton */
        $dummyObject = DataObject::singleton($baseClass);
        $baseTable = $dummyObject->baseTable();

        $idColumn = Convert::symbol2sql("{$baseTable}.ID");

        // Get the stageChildren() result of a dummy object and break down into a generic query
        $query = $dummyObject->stageChildren(true, true)->dataQuery()->query();

        // optional ID-list filter
        if ($idList) {
            // Validate the ID list
            foreach ($idList as $id) {
                if (!is_numeric($id)) {
                    user_error(
                        "Bad ID passed to Versioned::prepopulate_numchildren_cache() in \$idList: " . $id,
                        E_USER_ERROR
                    );
                }
            }
            $query->addWhere(['"ParentID" IN (' . DB::placeholders($idList) . ')' => $idList]);
        }

        $query->setOrderBy(null);

        $query->setSelect([
            '"ParentID"',
            "COUNT(DISTINCT $idColumn) AS \"NumChildren\"",
        ]);
        $query->setGroupBy([Convert::symbol2sql("ParentID")]);

        $numChildren = $query->execute()->map();
        self::$cache_numChildren[$baseClass]['numChildren'] = $numChildren;
        if (!$idList) {
            // If all objects are being cached, mark this cache as complete
            // to avoid counting children of childless object.
            self::$cache_numChildren[$baseClass]['numChildren']['_complete'] = true;
        }
    }
996687
private function getStageInstance(string $stageClass): StageInterface
    {
        if (!class_exists($stageClass)) {
            throw new RuntimeException('Error: Could not find requested stage class.');
        }
        if (in_array("Zikula\\Component\\Wizard\\InjectContainerInterface", class_implements($stageClass), true)) {
            return new $stageClass($this->container);
        }

        return new $stageClass();
    }
808375
protected function isLocalisedInStage($stage, $locale = null)
    {
        // Get locale
        if (!$locale) {
            $locale = FluentState::singleton()->getLocale();

            // Potentially no Locales have been created in the system yet.
            if (!$locale) {
                return false;
            }
        }

        // Get table
        $baseTable = $this->owner->baseTable();
        $table = $this->getLocalisedTable($baseTable);
        if ($stage === Versioned::LIVE) {
            $table .= self::SUFFIX_LIVE;
        }

        // Check for a cached item in the full list of all objects. These are populated optimistically.
        if (isset(static::$idsInLocaleCache[$locale][$table][$this->owner->ID])) {
            return (bool) static::$idsInLocaleCache[$locale][$table][$this->owner->ID];
        }

        if (!empty(static::$idsInLocaleCache[$locale][$table]['_complete'])) {
            return false;
        }

        // Set cache and return
        return static::$idsInLocaleCache[$locale][$table][$this->owner->ID]
            = $this->findRecordInLocale($locale, $table, $this->owner->ID);
    }
681369
public function get(string $pattern, $stages): void
    {
        $pipeline = new HttpPipeline(RequestMethodInterface::METHOD_GET, $this->prefix.$pattern, $this->routerStages);
        $pipeline->pipe($stages);
        $this->pipelineCollection->add($pipeline);
    }
698576
public function loadTypeDataByIdentifier($identifier, $status)
    {
        try {
            return $this->innerGateway->loadTypeDataByIdentifier($identifier, $status);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1134485
public function flattenIdentifier(ClassMetadata $class, array $id)
    {
        $flatId = array();

        foreach ($class->identifier as $field) {
            if (isset($class->associationMappings[$field]) && isset($id[$field]) && is_object($id[$field])) {
                /* @var $targetClassMetadata ClassMetadata */
                $targetClassMetadata = $this->metadataFactory->getMetadataFor(
                    $class->associationMappings[$field]['targetEntity']
                );

                if ($this->unitOfWork->isInIdentityMap($id[$field])) {
                    $associatedId = $this->flattenIdentifier($targetClassMetadata, $this->unitOfWork->getEntityIdentifier($id[$field]));
                } else {
                    $associatedId = $this->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($id[$field]));
                }

                $flatId[$field] = implode(' ', $associatedId);
            } elseif (isset($class->associationMappings[$field])) {
                $associatedId = array();

                foreach ($class->associationMappings[$field]['joinColumns'] as $joinColumn) {
                    $associatedId[] = $id[$joinColumn['name']];
                }

                $flatId[$field] = implode(' ', $associatedId);
            } else {
                $flatId[$field] = $id[$field];
            }
        }

        return $flatId;
    }
1171061
protected function populateFromResultset(Resultset $resultset = null, $classname = null, $id_column = null, $index_column = null)
        {
            $items = array();
            if ($resultset instanceof Resultset) {
                if (Core::isDebugMode()) {
                    $previous_time = Core::getDebugTime();
                    $populated_classnames = array();
                    $populated_classes = 0;
                }

                $query = $resultset->getQuery();
                $id_column = ($id_column) ?? $query->getTable()->getIdColumn();
                if ($index_column === null) {
                    $index_column = ($query->getIndexBy()) ? $query->getIndexBy() : $id_column;
                }
                $classnames = Core::getCachedTableEntityClasses('\\'.get_class($this));
                if ($classname === null) {
                    $classname = Core::getCachedTableEntityClass('\\'.get_class($this));
                }
                while ($row = $resultset->getNextRow()) {
                    if ($classnames) {
                        $classname = $this->getSubclassNameFromRow($row, $classnames);
                    }
                    $row_id = $row->get($id_column);
                    $is_cached = $classname::getB2DBTable()->hasCachedB2DBObject($row_id);
                    $item = $this->populateFromRow($row, $classname, $id_column, $row_id, true);
                    $items[$row->get($index_column)] = $item;
                    if (!$is_cached && Core::isDebugMode()) {
                        $populated_classnames[$classname] = $classname;
                        $populated_classes++;
                    }
                }

                if (Core::isDebugMode()) {
                    Core::objectPopulationHit($populated_classes, $populated_classnames, $previous_time);
                }
            }
            return $items;
        }
526698
protected function find($identifiers, $targetClass)
    {
        if ($identifiers instanceof $targetClass) {
            return $identifiers;
        }

        if ($this->isNullIdentifier($identifiers)) {
            return null;
        }

        return $this->objectManager->find($targetClass, $identifiers);
    }
1272258
public static void initialize(final Class<?> _class)
        throws CacheReloadException
    {
        if (InfinispanCache.get().exists(Attribute.NAMECACHE)) {
            InfinispanCache.get().<String, Attribute>getCache(Attribute.NAMECACHE).clear();
        } else {
            InfinispanCache.get().<String, Attribute>getCache(Attribute.NAMECACHE)
                            .addListener(new CacheLogListener(Attribute.LOG));
        }

        if (InfinispanCache.get().exists(Attribute.IDCACHE)) {
            InfinispanCache.get().<Long, Attribute>getCache(Attribute.IDCACHE).clear();
        } else {
            InfinispanCache.get().<Long, Attribute>getCache(Attribute.IDCACHE)
                            .addListener(new CacheLogListener(Attribute.LOG));
        }
    }
834127
public function loadDescendantProductGroupIDListInto(&$idList)
    {
        if ($children = $this->AllChildren()) {
            foreach ($children as $child) {
                if (in_array($child->ID, $idList)) {
                    continue;
                }

                if ($child instanceof self) {
                    $idList[] = $child->ID;
                    $child->loadDescendantProductGroupIDListInto($idList);
                }
            }
        }
    }
451916
function appendClass( $class, $version = false )
    {
        if ( $class instanceof eZContentClass )
        {
            $classID = $class->attribute( 'id' );
            $version = $class->attribute( 'version' );
        }
        else
        {
            $classID = $class;
        }
        $classGroupLink = eZContentClassClassGroup::create( $classID,
                                                            $version,
                                                            $this->attribute( 'id' ),
                                                            $this->attribute( 'name' ) );
        $classGroupLink->store();
        return $classGroupLink;
    }
763597
public function get($class, array $id)
    {
        if (!$this->isEnabled()) {
            return false;
        }

        $key = self::key($class, $id);

        return isset($this->members[$key])
        ? $this->members[$key]
        : false;
    }
1235042
public function loadDescendantIDListInto(&$idList) {
        if($children=$this->AllChildren()) {
            foreach($children as $child) {
                if(in_array($child->ID, $idList)) {
                    continue;
                }
                $idList[]=$child->ID;
                $ext=$child->getExtensionInstance('Hierarchy');
                $ext->setOwner($child);
                $ext->loadDescendantIDListInto($idList);
                $ext->clearOwner();
            }
        }
    }
1097456
private static function init($class)
    {
        self::$_init[$class] = true;

        if (isset($_GET['cms_content_version']) && ctype_digit($_GET['cms_content_version'])) {
            self::$_version = (int)$_GET['cms_content_version'];
        }

        $cache_key = 'components_' . PAGE_ID . '_v_' . self::$_version;
        $res = NULL;
        if (Settings::isCacheEnabled()) {
            $res = Cacher::getInstance()->getDefaultCacher()->get($cache_key);
        }

        if (is_array($res)) { // Set from cache
            self::$_components[$class] = $res;
        } else { // Get from DB
            if (self::$_version) {
                // From history
                $components_collection = new PageComponentHistoryRepository();
                $components_collection->setWhereVersion(self::$_version);
            } else {
                // From current version
                $components_collection = new PageComponentEntityRepository();
            }
            $components_collection->setWherePageId(PAGE_ID);
            self::$_components[$class] = $components_collection->getPairs('data', 'component');

            // Get Custom components
            $customs = new PageComponentCustomEntityRepository();
            $customs->setWherePageId(PAGE_ID);
            $customs->setWhereComponent($class);
            $customs->addOrderByField('order');

            $custom_components_in_database = $customs->getAsArrayOfObjectData(true);
            foreach ($custom_components_in_database as $custom) {
                self::$_components[$class][$class . '_' . $custom['tab']][$custom['order']][$custom['name']] = $custom['value'];
            }

            // Make all custom components have all fields
            $custom_components_in_controller = self::getControllerCustomComponents($class);
            foreach ($custom_components_in_database as $custom) {
                // Set unavailable fields as empty
                foreach (self::$_components[$class][$class . '_' . $custom['tab']] as $order => $data) {
                    if (isset($custom_components_in_controller[$class . '_' . $custom['tab']])
                        && isset(self::$_components[$class][$class . '_' . $custom['tab']][$order])
                        && (
                            count(self::$_components[$class][$class . '_' . $custom['tab']][$order])
                            !=
                            count($custom_components_in_controller[$class . '_' . $custom['tab']]))
                    ) {
                        foreach ($custom_components_in_controller[$class . '_' . $custom['tab']] as $field_key => $field_value) {
                            if (!isset(self::$_components[$class][$class . '_' . $custom['tab']][$order][$field_key])) {
                                self::$_components[$class][$class . '_' . $custom['tab']][$order][$field_key] = ''; // Set empty field
                            }
                        }
                    }
                }

            }

            // Set any empty value to all non-existing components to avoid error in front
            foreach ($custom_components_in_controller as $custom_key => $custom_fields) {
                list($class, $custom_tab) = explode('_', $custom_key, 2);
                if (!isset(self::$_components[$class][$class . '_' . $custom_tab]) || !is_array(self::$_components[$class][$class . '_' . $custom_tab])) {
                    self::$_components[$class][$class . '_' . $custom_tab] = []; // Set empty array to iterate from
                }
            }

            // Save to cache
            if (Settings::isCacheEnabled()) {
                Cacher::getInstance()->getDefaultCacher()->set($cache_key, self::$_components[$class]);
            }
        }
    }
726203
public function updateRevisions(Model $Model, $idlist = array()) {
		if (!$Model->ShadowModel) {
			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
			return;
		}
		foreach ($idlist as $id) {
			$Model->id = $id;
			$Model->createRevision();
		}
	}
1242668
protected function getInsertObjectIdentitySql($identifier, $classId, $entriesInheriting)
    {
        $query = <<<QUERY
              INSERT INTO %s (class_id, object_identifier, entries_inheriting)
              VALUES (%d, %s, %s)
QUERY;

        return sprintf(
            $query,
            $this->options['oid_table_name'],
            $classId,
            $this->connection->quote($identifier),
            $this->connection->getDatabasePlatform()->convertBooleans($entriesInheriting)
        );
    }
906570
public function findAllByNotifiableQb($identifier, $class, $order = 'DESC')
    {
        return $this->createQueryBuilder('nn')
            ->addSelect('n')
            ->join('nn.notification', 'n')
            ->join('nn.notifiableEntity', 'ne')
            ->where('ne.identifier = :identifier')
            ->andWhere('ne.class = :class')
            ->orderBy('n.id', $order)
            ->setParameter('identifier', $identifier)
            ->setParameter('class', $class)
            ;
    }