container = $container; } protected function getContainer() { return $this->container; } /** * Rebuild the system with metadata, database and cache clearing * * @return bool */ public function rebuild() { $result = $this->clearCache(); $result &= $this->rebuildMetadata(); $result &= $this->rebuildDatabase(); 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 Error("Error while clearing cache"); } return $result; } /** * Rebuild database * * @return bool */ public function rebuildDatabase() { try { $result = $this->getContainer()->get('schema')->rebuild(); } catch (\Exception $e) { $result = false; $GLOBALS['log']->error('Fault to rebuild database schema'.'. Details: '.$e->getMessage()); } if ($result === false) { throw new Error("Error while rebuilding database"); } return $result; } /** * Rebuild metadata * * @return bool */ public function rebuildMetadata() { $metadata = $this->getContainer()->get('metadata'); $metadata->init(true); $ormMeta = $metadata->getOrmMetadata(true); return empty($ormMeta) ? false : true; } }