namespace Drupal\Console\Utils;
use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Logger\LoggerChannelFactory;
/**
* @var string
*/
- protected $cacheDirectory;
+ protected $cacheServicesFile;
/**
* Site constructor.
if (file_exists($driver_folder->getRealpath() . '/Install/Tasks.php')) {
$driver = $driver_folder->getBasename();
$installer = db_installer_object($driver);
- // Verify is database is installable
+ // Verify if database is installable
if ($installer->installable()) {
$reflection = new \ReflectionClass($installer);
$install_namespace = $reflection->getNamespaceName();
return false;
}
- public function getCacheDirectory()
+ public function getCachedServicesFile()
{
- if ($this->cacheDirectory) {
- return $this->cacheDirectory;
- }
-
- $configFactory = \Drupal::configFactory();
- $siteId = $configFactory->get('system.site')
- ->get('uuid');
- $pathTemporary = $configFactory->get('system.file')
- ->get('path.temporary');
- $configuration = $this->configurationManager->getConfiguration();
- $cacheDirectory = $configuration->get('application.cache.directory')?:'';
- if ($cacheDirectory) {
- if (strpos($cacheDirectory, '/') != 0) {
- $cacheDirectory = $this->configurationManager
- ->getApplicationDirectory() . '/' . $cacheDirectory;
- }
- $cacheDirectories[] = $cacheDirectory . '/' . $siteId . '/';
- }
- $cacheDirectories[] = sprintf(
- '%s/cache/%s/',
- $this->configurationManager->getConsoleDirectory(),
- $siteId
- );
- $cacheDirectories[] = $pathTemporary . '/console/cache/' . $siteId . '/';
+ if (!$this->cacheServicesFile) {
+ $configFactory = \Drupal::configFactory();
+ $siteId = $configFactory->get('system.site')
+ ->get('uuid');
- foreach ($cacheDirectories as $cacheDirectory) {
- if ($this->isValidDirectory($cacheDirectory)) {
- $this->cacheDirectory = $cacheDirectory;
- break;
- }
- }
-
- return $this->cacheDirectory;
- }
-
- private function isValidDirectory($path)
- {
- $fileSystem = new Filesystem();
- if ($fileSystem->exists($path)) {
- return true;
- }
- try {
- $fileSystem->mkdir($path);
+ $directory = \Drupal::service('stream_wrapper.temporary')
+ ->getDirectoryPath();
- return true;
- } catch (\Exception $e) {
- return false;
+ $this->cacheServicesFile = $directory . '/' . $siteId .
+ '-console.services.yml';
}
- }
- public function cachedServicesFile()
- {
- return $this->getCacheDirectory().'/console.services.yml';
+ return $this->cacheServicesFile;
}
public function cachedServicesFileExists()
{
- return file_exists($this->cachedServicesFile());
+ return file_exists($this->getCachedServicesFile());
}
public function removeCachedServicesFile()
{
if ($this->cachedServicesFileExists()) {
- unlink($this->cachedServicesFile());
+ unlink($this->getCachedServicesFile());
}
}
+
+ /**
+ * @param string $root
+ */
+ public function setRoot($root)
+ {
+ $this->root = $root;
+ }
}