private function ensureInitialized() { if (!CommandExecutor::isCurrentCommand('oro:entity-extend:cache:', true)) { ExtendClassLoadingUtils::ensureDirExists(ExtendClassLoadingUtils::getEntityCacheDir($this->cacheDir)); if (!file_exists(ExtendClassLoadingUtils::getAliasesPath($this->cacheDir))) { $this->initializeCache(); } $this->ensureAliasesSet(); } }
/** * Generates extended entities * * @param array $schemas */ public function generate(array $schemas) { $aliases = []; foreach ($schemas as $schema) { $this->generateSchemaFiles($schema); if ($schema['type'] == 'Extend') { $aliases[$schema['entity']] = $schema['parent']; } } // write PHP class aliases to the file file_put_contents(ExtendClassLoadingUtils::getAliasesPath($this->cacheDir), serialize($aliases)); }
/** * Generates extended entities * * @param array $config */ public function generate(array $config) { $aliases = array(); foreach ($config as $item) { $this->generateYaml($item); $this->generateClass($item); if ($item['type'] == 'Extend') { $aliases[$item['entity']] = $item['parent']; } } file_put_contents(ExtendClassLoadingUtils::getAliasesPath($this->cacheDir), Yaml::dump($aliases)); }
private function ensureCacheInitialized() { $aliasesPath = ExtendClassLoadingUtils::getAliasesPath($this->kernel->getCacheDir()); if (!$this->isCommandExecuting('oro:entity-extend:dump') && !file_exists($aliasesPath)) { // We have to warm up the extend entities cache in separate process // to allow this process continue executing. // The problem is we need initialized DI contained for warming up this cache, // but in this moment we are exactly doing this for the current process. $console = escapeshellarg($this->getPhp()) . ' ' . escapeshellarg($this->kernel->getRootDir() . '/console'); $env = $this->kernel->getEnvironment(); $process = new Process($console . ' oro:entity-extend:dump' . ' --env ' . $env); $process->run(); } }
/** * Removes the entity proxies and metadata from the cache * * @param bool $keepEntityProxies Set TRUE if proxies for custom and extend entities should not be deleted */ public function clear($keepEntityProxies = false) { $filesystem = new Filesystem(); if ($keepEntityProxies) { $aliasesPath = ExtendClassLoadingUtils::getAliasesPath($this->cacheDir); if ($filesystem->exists($aliasesPath)) { $filesystem->remove($aliasesPath); } } else { $baseCacheDir = ExtendClassLoadingUtils::getEntityBaseCacheDir($this->cacheDir); if ($filesystem->exists($baseCacheDir)) { $filesystem->remove([$baseCacheDir]); } $filesystem->mkdir(ExtendClassLoadingUtils::getEntityCacheDir($this->cacheDir)); } $metadataCacheDriver = $this->em->getMetadataFactory()->getCacheDriver(); if ($metadataCacheDriver instanceof ClearableCache) { $metadataCacheDriver->deleteAll(); } }
/** * Removes the entity proxies and metadata from the cache * * @param bool $keepEntityProxies Set TRUE if proxies for custom and extend entities should not be deleted */ public function clear($keepEntityProxies = false) { $filesystem = new Filesystem(); if ($keepEntityProxies) { $aliasesPath = ExtendClassLoadingUtils::getAliasesPath($this->cacheDir); if ($filesystem->exists($aliasesPath)) { $filesystem->remove($aliasesPath); } } else { $baseCacheDir = ExtendClassLoadingUtils::getEntityBaseCacheDir($this->cacheDir); if ($filesystem->exists($baseCacheDir)) { $filesystem->remove([$baseCacheDir]); } $filesystem->mkdir(ExtendClassLoadingUtils::getEntityCacheDir($this->cacheDir)); } /** @var ExtendClassMetadataFactory $metadataFactory */ $metadataFactory = $this->em->getMetadataFactory(); $metadataFactory->clearCache(); }
/** * Removes the entity proxies and metadata from the cache * * @param bool $keepEntityProxies Set TRUE if proxies for custom and extend entities should not be deleted */ public function clear($keepEntityProxies = false) { $filesystem = new Filesystem(); if ($keepEntityProxies) { $aliasesPath = ExtendClassLoadingUtils::getAliasesPath($this->cacheDir); if ($filesystem->exists($aliasesPath)) { $filesystem->remove($aliasesPath); } } else { $baseCacheDir = ExtendClassLoadingUtils::getEntityBaseCacheDir($this->cacheDir); if ($filesystem->exists($baseCacheDir)) { $filesystem->remove([$baseCacheDir]); } $filesystem->mkdir(ExtendClassLoadingUtils::getEntityCacheDir($this->cacheDir)); } foreach ($this->entityManagerBag->getEntityManagers() as $em) { /** @var ClassMetadataFactory $metadataFactory */ $metadataFactory = $em->getMetadataFactory(); $metadataCache = $metadataFactory->getCacheDriver(); if ($metadataCache instanceof ClearableCache) { $metadataCache->deleteAll(); } } }