Skip to content

Commit 272a84d

Browse files
authored
Merge pull request #119 from universityofadelaide/delete-install-php
Add in delete function as part of the file scaffolding.
2 parents f4ea99b + 96352f2 commit 272a84d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/actions/ScaffoldFiles.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Filesystem\Filesystem;
99
use UniversityOfAdelaide\ShepherdDrupalScaffold\ScaffoldTrait;
1010
use UniversityOfAdelaide\ShepherdDrupalScaffold\tasks\CopyFile;
11+
use UniversityOfAdelaide\ShepherdDrupalScaffold\tasks\DeleteFile;
1112

1213
/**
1314
* Updates the Shepherd scaffold files.
@@ -25,6 +26,10 @@ public function onEvent(Event $event): void
2526
foreach (static::tasks($this->filesystem, $scaffoldPath, $projectPath) as $task) {
2627
$task->execute();
2728
}
29+
30+
$event->getIO()->write('Deleting install.php');
31+
$delete = new DeleteFile($this->filesystem, 'web/core', 'install.php');
32+
$delete->execute();
2833
}
2934

3035
/**

src/tasks/DeleteFile.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace UniversityOfAdelaide\ShepherdDrupalScaffold\tasks;
6+
7+
use Symfony\Component\Filesystem\Filesystem;
8+
9+
class DeleteFile implements TaskInterface
10+
{
11+
protected Filesystem $filesystem;
12+
protected string $path;
13+
protected string $filename;
14+
15+
public function __construct(Filesystem $filesystem, string $path, string $filename)
16+
{
17+
$this->filesystem = $filesystem;
18+
$this->path = $path;
19+
$this->filename = $filename;
20+
}
21+
22+
public function getFilename(): string
23+
{
24+
return $this->filename;
25+
}
26+
27+
/**
28+
* @throws \Symfony\Component\Filesystem\Exception\FileNotFoundException
29+
* When original file doesn't exist
30+
* @throws \Symfony\Component\Filesystem\Exception\IOException
31+
* When copy fails
32+
*/
33+
public function execute(): void
34+
{
35+
// Skip copying files that already exist at the destination.
36+
if (!$this->filesystem->exists($this->path . '/' . $this->filename)) {
37+
return;
38+
}
39+
40+
$this->filesystem->remove(
41+
$this->path . '/' . $this->filename
42+
);
43+
}
44+
}

0 commit comments

Comments
 (0)