container = $container; } protected function getContainer() { return $this->container; } /** * Rebuild the system with metadata, database and cache clearing * * @return bool */ public function rebuild($entityList = array()) { $result = $this->clearCache(); $result &= $this->rebuildMetadata(); $result &= $this->rebuildDatabase($entityList); return $result; } /** * Clear a cache * * @return bool */ public function clearCache() { $cacheDir = $this->getContainer()->get('config')->get('cachePath'); $result = $this->getContainer()->get('fileManager')->removeInDir($cacheDir); if ($result === false) { throw new Exceptions\Error("Error while clearing cache"); } $this->updateCacheTimestamp(); return $result; } /** * Rebuild database * * @return bool */ public function rebuildDatabase($entityList = array()) { try { $result = $this->getContainer()->get('schema')->rebuild($entityList); } catch (\Exception $e) { $result = false; $GLOBALS['log']->error('Fault to rebuild database schema'.'. Details: '.$e->getMessage()); } if ($result === false) { throw new Exceptions\Error("Error while rebuilding database. See log file for details."); } $this->updateCacheTimestamp(); return $result; } /** * Rebuild metadata * * @return bool */ public function rebuildMetadata() { $metadata = $this->getContainer()->get('metadata'); $metadata->init(true); $ormMeta = $metadata->getOrmMetadata(true); $this->updateCacheTimestamp(); return empty($ormMeta) ? false : true; } /** * Update cache timestamp * * @return bool */ public function updateCacheTimestamp() { $config = $this->getContainer()->get('config'); return $config->set('cacheTimestamp', time()); } }