partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 7ae29f8a6c21010544dcc19cfccbf3a027a3ea89
parent dda82a63c098ea6171c9d1b0a266c10f53db79ab
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed,  8 Feb 2012 01:01:01 +0100

Force re-generation of proxies on setup, fixes #136

Diffstat:
Msrc/backend/de/RaumZeitLabor/PartKeepr/Setup/MiscSettingsSetup.php | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Setup/MiscSettingsSetup.php b/src/backend/de/RaumZeitLabor/PartKeepr/Setup/MiscSettingsSetup.php @@ -11,6 +11,7 @@ class MiscSettingsSetup extends AbstractSetup { public function run () { $this->markCronjobsAsRun(); $this->clearAPCCache(); + $this->regenerateProxies(); } /** @@ -25,10 +26,44 @@ class MiscSettingsSetup extends AbstractSetup { } } + /** + * Clears the APC cache to push out old entries + */ public function clearAPCCache () { if (function_exists("apc_clear_cache")) { apc_clear_cache(); apc_clear_cache("user"); } } + + /** + * Re-generates all proxies. This is analog to doctrine orm:generate-proxies + * + * @throws \InvalidArgumentException + */ + public function regenerateProxies () { + $em = $this->entityManager; + + $metadatas = $em->getMetadataFactory()->getAllMetadata(); + $destPath = $em->getConfiguration()->getProxyDir(); + + if ( ! is_dir($destPath)) { + mkdir($destPath, 0777, true); + } + + $destPath = realpath($destPath); + + if ( ! file_exists($destPath)) { + throw new \InvalidArgumentException( + sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $em->getConfiguration()->getProxyDir()) + ); + } else if ( ! is_writable($destPath)) { + throw new \InvalidArgumentException( + sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath) + ); + } + + $em->getProxyFactory()->generateProxyClasses($metadatas, $destPath); + } + } \ No newline at end of file