Skip to content

Commit 5c5b7cf

Browse files
committed
*For Testshops* - Adds/changes robots.txt to stop crawling
1 parent 5af6763 commit 5c5b7cf

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/Command/DevEnvCommand.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Frosh\Tools\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Style\SymfonyStyle;
9+
10+
class DevEnvCommand extends Command
11+
{
12+
public static $defaultName = 'frosh:dev:env';
13+
public static $defaultDescription = 'For testshops - add/change robots.txt to stop crawling';
14+
private string $envPath;
15+
16+
public function __construct(string $envPath)
17+
{
18+
parent::__construct();
19+
$this->envPath = $envPath;
20+
}
21+
22+
protected function execute(InputInterface $input, OutputInterface $output): int
23+
{
24+
$io = new SymfonyStyle($input, $output);
25+
$robotsPath = $this->envPath."/robots.txt";
26+
27+
$fileExists = file_exists($robotsPath);
28+
if($fileExists) {
29+
$output->writeln('robots.txt exists in public folder');
30+
31+
$file = file_get_contents($robotsPath);
32+
$content = "User-agent: *\nDisallow: /\n\n".$file;
33+
file_put_contents($robotsPath, $content);
34+
35+
$io->success('robots.txt changed :)');
36+
37+
return self::SUCCESS;
38+
}
39+
40+
$robotsFile = fopen($robotsPath, "w");
41+
$robotsContent = "User-agent: *\nDisallow: /";
42+
fwrite($robotsFile, $robotsContent);
43+
fclose($robotsFile);
44+
45+
$io->success('robots.txt created :)');
46+
47+
return self::SUCCESS;
48+
}
49+
}

src/Resources/config/services.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<tag name="console.command"/>
2828
</service>
2929

30+
<service id="Frosh\Tools\Command\DevEnvCommand">
31+
<argument>%kernel.project_dir%/public</argument>
32+
<tag name="console.command"/>
33+
</service>
34+
3035
<service id="frosh.tools.cache.app" class="Frosh\Tools\Components\CacheAdapter">
3136
<argument type="service" id="cache.object"/>
3237
</service>

0 commit comments

Comments
 (0)