container = $container; } protected function getContainer() { return $this->container; } /** * Rebuild the system with metadata, database and cache clearing * * @return bool * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ public function rebuild($entityList = null) { $result = $this->clearCache(); $result &= $this->rebuildMetadata(); $result &= $this->rebuildDatabase($entityList); return $result; } /** * Clear a cache * * @return bool * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ public function clearCache() { $result = $this->getContainer()->get('fileManager')->removeInDir($this->cachePath); if ($result != true) { throw new Exceptions\Error("Error while clearing cache"); } $this->updateCacheTimestamp(); return $result; } /** * Rebuild database * * @return bool * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ public function rebuildDatabase($entityList = null) { 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 != true) { throw new Exceptions\Error("Error while rebuilding database. See log file for details."); } $this->updateCacheTimestamp(); return $result; } /** * Rebuild metadata * * @return bool * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ 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 * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ public function updateCacheTimestamp() { $this->getContainer()->get('config')->updateCacheTimestamp(); $this->getContainer()->get('config')->save(); return true; } }