Skip to content

Commit

Permalink
Merge pull request #119 from universityofadelaide/delete-install-php
Browse files Browse the repository at this point in the history
Add in delete function as part of the file scaffolding.
  • Loading branch information
singularo authored Sep 29, 2022
2 parents f4ea99b + 96352f2 commit 272a84d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/actions/ScaffoldFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Filesystem\Filesystem;
use UniversityOfAdelaide\ShepherdDrupalScaffold\ScaffoldTrait;
use UniversityOfAdelaide\ShepherdDrupalScaffold\tasks\CopyFile;
use UniversityOfAdelaide\ShepherdDrupalScaffold\tasks\DeleteFile;

/**
* Updates the Shepherd scaffold files.
Expand All @@ -25,6 +26,10 @@ public function onEvent(Event $event): void
foreach (static::tasks($this->filesystem, $scaffoldPath, $projectPath) as $task) {
$task->execute();
}

$event->getIO()->write('Deleting install.php');
$delete = new DeleteFile($this->filesystem, 'web/core', 'install.php');
$delete->execute();
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/tasks/DeleteFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace UniversityOfAdelaide\ShepherdDrupalScaffold\tasks;

use Symfony\Component\Filesystem\Filesystem;

class DeleteFile implements TaskInterface
{
protected Filesystem $filesystem;
protected string $path;
protected string $filename;

public function __construct(Filesystem $filesystem, string $path, string $filename)
{
$this->filesystem = $filesystem;
$this->path = $path;
$this->filename = $filename;
}

public function getFilename(): string
{
return $this->filename;
}

/**
* @throws \Symfony\Component\Filesystem\Exception\FileNotFoundException
* When original file doesn't exist
* @throws \Symfony\Component\Filesystem\Exception\IOException
* When copy fails
*/
public function execute(): void
{
// Skip copying files that already exist at the destination.
if (!$this->filesystem->exists($this->path . '/' . $this->filename)) {
return;
}

$this->filesystem->remove(
$this->path . '/' . $this->filename
);
}
}

0 comments on commit 272a84d

Please sign in to comment.