rebuild refactoring
This commit is contained in:
@@ -31,7 +31,8 @@ namespace Espo\Core\ApplicationRunners;
|
||||
|
||||
use Espo\Core\{
|
||||
Application\Runner,
|
||||
DataManager,
|
||||
Exceptions\Error,
|
||||
Utils\CacheClearer,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -41,15 +42,18 @@ class ClearCache implements Runner
|
||||
{
|
||||
use Cli;
|
||||
|
||||
private DataManager $dataManager;
|
||||
private CacheClearer $cacheClearer;
|
||||
|
||||
public function __construct(DataManager $dataManager)
|
||||
public function __construct(CacheClearer $cacheClearer)
|
||||
{
|
||||
$this->dataManager = $dataManager;
|
||||
$this->cacheClearer = $cacheClearer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->dataManager->clearCache();
|
||||
$this->cacheClearer->clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,24 +30,28 @@
|
||||
namespace Espo\Core\Console\Commands;
|
||||
|
||||
use Espo\Core\{
|
||||
DataManager,
|
||||
Console\Command,
|
||||
Console\Command\Params,
|
||||
Console\IO,
|
||||
Exceptions\Error,
|
||||
Utils\CacheClearer,
|
||||
};
|
||||
|
||||
class ClearCache implements Command
|
||||
{
|
||||
private $dataManager;
|
||||
private CacheClearer $cacheClearer;
|
||||
|
||||
public function __construct(DataManager $dataManager)
|
||||
public function __construct(CacheClearer $cacheClearer)
|
||||
{
|
||||
$this->dataManager = $dataManager;
|
||||
$this->cacheClearer = $cacheClearer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(Params $params, IO $io): void
|
||||
{
|
||||
$this->dataManager->clearCache();
|
||||
$this->cacheClearer->clear();
|
||||
|
||||
$io->writeLine("Cache has been cleared.");
|
||||
}
|
||||
|
||||
@@ -31,19 +31,18 @@ namespace Espo\Core;
|
||||
|
||||
use Espo\Core\Utils\Config\MissingDefaultParamsSaver as ConfigMissingDefaultParamsSaver;
|
||||
|
||||
use Espo\Core\{
|
||||
Exceptions\Error,
|
||||
ORM\EntityManager,
|
||||
Utils\Metadata,
|
||||
Utils\Util,
|
||||
Utils\Config,
|
||||
Utils\Config\ConfigWriter,
|
||||
Utils\File\Manager as FileManager,
|
||||
Utils\Metadata\OrmMetadataData,
|
||||
Utils\Database\Schema\SchemaProxy,
|
||||
Utils\Log,
|
||||
Utils\Module,
|
||||
Rebuild\RebuildActionProcessor};
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\ORM\EntityManagerProxy;
|
||||
use Espo\Core\Utils\CacheClearer;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
use Espo\Core\Utils\Metadata\OrmMetadataData;
|
||||
use Espo\Core\Utils\Database\Schema\SchemaProxy;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Module;
|
||||
use Espo\Core\Rebuild\RebuildActionProcessor;
|
||||
|
||||
use Throwable;
|
||||
|
||||
@@ -54,8 +53,7 @@ class DataManager
|
||||
{
|
||||
private Config $config;
|
||||
private ConfigWriter $configWriter;
|
||||
private EntityManager $entityManager;
|
||||
private FileManager $fileManager;
|
||||
private EntityManagerProxy $entityManager;
|
||||
private Metadata $metadata;
|
||||
private OrmMetadataData $ormMetadataData;
|
||||
private HookManager $hookManager;
|
||||
@@ -64,14 +62,12 @@ class DataManager
|
||||
private Module $module;
|
||||
private RebuildActionProcessor $rebuildActionProcessor;
|
||||
private ConfigMissingDefaultParamsSaver $configMissingDefaultParamsSaver;
|
||||
|
||||
private string $cachePath = 'data/cache';
|
||||
private CacheClearer $cacheClearer;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $entityManager,
|
||||
EntityManagerProxy $entityManager,
|
||||
Config $config,
|
||||
ConfigWriter $configWriter,
|
||||
FileManager $fileManager,
|
||||
Metadata $metadata,
|
||||
OrmMetadataData $ormMetadataData,
|
||||
HookManager $hookManager,
|
||||
@@ -79,12 +75,12 @@ class DataManager
|
||||
Log $log,
|
||||
Module $module,
|
||||
RebuildActionProcessor $rebuildActionProcessor,
|
||||
ConfigMissingDefaultParamsSaver $configMissingDefaultParamsSaver
|
||||
ConfigMissingDefaultParamsSaver $configMissingDefaultParamsSaver,
|
||||
CacheClearer $cacheClearer
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
$this->config = $config;
|
||||
$this->configWriter = $configWriter;
|
||||
$this->fileManager = $fileManager;
|
||||
$this->metadata = $metadata;
|
||||
$this->ormMetadataData = $ormMetadataData;
|
||||
$this->hookManager = $hookManager;
|
||||
@@ -93,6 +89,7 @@ class DataManager
|
||||
$this->module = $module;
|
||||
$this->rebuildActionProcessor = $rebuildActionProcessor;
|
||||
$this->configMissingDefaultParamsSaver = $configMissingDefaultParamsSaver;
|
||||
$this->cacheClearer = $cacheClearer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,8 +103,8 @@ class DataManager
|
||||
$this->clearCache();
|
||||
$this->disableHooks();
|
||||
$this->checkModules();
|
||||
$this->populateConfigParameters();
|
||||
$this->rebuildMetadata();
|
||||
$this->populateConfigParameters();
|
||||
$this->rebuildDatabase($entityList);
|
||||
$this->rebuildActionProcessor->process();
|
||||
$this->configMissingDefaultParamsSaver->process();
|
||||
@@ -115,21 +112,13 @@ class DataManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a cache.
|
||||
* Clear cache.
|
||||
*
|
||||
* @throws Error
|
||||
*/
|
||||
public function clearCache(): void
|
||||
{
|
||||
$this->module->clearCache();
|
||||
|
||||
$result = $this->fileManager->removeInDir($this->cachePath);
|
||||
|
||||
if (!$result) {
|
||||
throw new Error("Error while clearing cache");
|
||||
}
|
||||
|
||||
$this->updateCacheTimestamp();
|
||||
$this->cacheClearer->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,18 +31,17 @@ namespace Espo\Core\ORM;
|
||||
|
||||
use Espo\ORM\{
|
||||
Entity,
|
||||
Metadata,
|
||||
Repository\Repository,
|
||||
Repository\RDBRepository,
|
||||
SqlExecutor,
|
||||
};
|
||||
|
||||
use Espo\Core\{
|
||||
Container,
|
||||
};
|
||||
use Espo\Core\Container;
|
||||
|
||||
class EntityManagerProxy
|
||||
{
|
||||
private ?EntityManager $entityManager = null;
|
||||
|
||||
private Container $container;
|
||||
|
||||
public function __construct(Container $container)
|
||||
@@ -103,4 +102,14 @@ class EntityManagerProxy
|
||||
{
|
||||
return $this->getEntityManager()->getRDBRepository($entityType);
|
||||
}
|
||||
|
||||
public function getMetadata(): Metadata
|
||||
{
|
||||
return $this->getEntityManager()->getMetadata();
|
||||
}
|
||||
|
||||
public function getSqlExecutor(): SqlExecutor
|
||||
{
|
||||
return $this->getEntityManager()->getSqlExecutor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* 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.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
|
||||
class CacheClearer
|
||||
{
|
||||
private ConfigWriter $configWriter;
|
||||
private FileManager $fileManager;
|
||||
private Module $module;
|
||||
|
||||
private string $cachePath = 'data/cache';
|
||||
|
||||
public function __construct(
|
||||
ConfigWriter $configWriter,
|
||||
FileManager $fileManager,
|
||||
Module $module
|
||||
){
|
||||
$this->configWriter = $configWriter;
|
||||
$this->fileManager = $fileManager;
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function clear(): void
|
||||
{
|
||||
$this->module->clearCache();
|
||||
|
||||
$result = $this->fileManager->removeInDir($this->cachePath);
|
||||
|
||||
if (!$result) {
|
||||
throw new Error("Error while clearing cache");
|
||||
}
|
||||
|
||||
$this->updateCacheTimestamp();
|
||||
}
|
||||
|
||||
private function updateCacheTimestamp(): void
|
||||
{
|
||||
$this->configWriter->updateCacheTimestamp();
|
||||
$this->configWriter->save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user