Skip to content
Snippets Groups Projects
Commit 6f8b7778 authored by Claudiu Cristea's avatar Claudiu Cristea
Browse files

ISAICP-9052L Improve the joinup_core.file_config_read_only service.

parent 4418cad7
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
namespace Drupal\joinup_core;
use Drupal\Core\File\FileExists;
use Drupal\Core\File\FileSystemInterface;
/**
......@@ -11,12 +12,7 @@
*/
class FileConfigReadOnly implements ConfigReadOnlyInterface {
/**
* File name of the disabled config readonly.
*
* @var string
*/
protected const string FILE_NAME = 'disable-config-readonly';
protected const string FILE = 'private://killswitch/disable-config-readonly';
public function __construct(protected FileSystemInterface $fileSystem) {}
......@@ -24,7 +20,11 @@ public function __construct(protected FileSystemInterface $fileSystem) {}
* {@inheritdoc}
*/
public function isReadOnlyEnabled(): bool {
return !file_exists($this->pathToReadOnlyFile());
$file = $this->fileSystem->realpath(static::FILE);
if ($file && file_exists($file)) {
return TRUE;
}
return FALSE;
}
/**
......@@ -32,7 +32,8 @@ public function isReadOnlyEnabled(): bool {
*/
public function enableReadOnly(): void {
if (!$this->isReadOnlyEnabled()) {
$this->fileSystem->unlink($this->pathToReadOnlyFile());
$file = $this->fileSystem->realpath(static::FILE);
$this->fileSystem->unlink($file);
}
}
......@@ -40,17 +41,8 @@ public function enableReadOnly(): void {
* {@inheritdoc}
*/
public function disableReadOnly(): void {
touch($this->pathToReadOnlyFile());
}
/**
* Returns the file path to disable the config readonly flag.
*
* @return string
* The file path
*/
protected function pathToReadOnlyFile(): string {
return DRUPAL_ROOT . '/../' . self::FILE_NAME;
$file = $this->fileSystem->realpath(static::FILE);
$this->fileSystem->saveData('', $file, FileExists::Replace);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment