1+ <?php
2+
3+ namespace Etre \Shell \Console \Commands \Setup ;
4+
5+ use Etre \Shell \Helper \DirectoryHelper ;
6+ use Etre \Shell \Helper \PatchesHelper ;
7+ use Symfony \Component \Console \Command \Command ;
8+ use Symfony \Component \Console \Helper \ProgressBar ;
9+ use Symfony \Component \Console \Helper \Table ;
10+ use Symfony \Component \Console \Helper \TableCell ;
11+ use Symfony \Component \Console \Input \InputDefinition ;
12+ use Symfony \Component \Console \Input \InputInterface ;
13+ use Symfony \Component \Console \Input \InputOption ;
14+ use Symfony \Component \Console \Output \OutputInterface ;
15+ use Symfony \Component \Console \Question \Question ;
16+
17+ class InitCommand extends Command
18+ {
19+ /** @var DirectoryHelper $directoryHelper */
20+ protected $ directoryHelper ;
21+
22+ /** @var PatchesHelper $patchesHelper */
23+ protected $ patchesHelper ;
24+
25+ /**
26+ * PatchCommand constructor.
27+ * @param $patchHelper
28+ */
29+ public function __construct ($ name = null )
30+ {
31+ $ this ->directoryHelper = new DirectoryHelper ();
32+ $ this ->patchesHelper = new PatchesHelper ($ this ->directoryHelper );
33+
34+ parent ::__construct ($ name );
35+ }
36+
37+ public function configure ()
38+ {
39+ $ this
40+ ->setName ('etre:setup:init ' )
41+ ->setDescription ('Create public directory and symlink js, media, and skin directories. ' )
42+ ->setHelp ("Create a Magento \"public \" director to assist in protecting application code. " );
43+ }
44+
45+ protected function execute (InputInterface $ input , OutputInterface $ output )
46+ {
47+ $ this ->makePublicDirectory ();
48+ $ output ->writeln ("<info>Created ./public directory</info> " );
49+ $ this ->symlinkPublicMageRoot (".htaccess " );
50+ $ output ->writeln ("<info>Linked .htaccess in public directory</info> " );
51+ $ this ->createIndex ();
52+ $ output ->writeln ("<info>Created index.php in public directory</info> " );
53+ $ this ->symlinkPublicMageRoot ("js " );
54+ $ output ->writeln ("<info>Linked js in public directory</info> " );
55+ $ this ->symlinkPublicMageRoot ("skin " );
56+ $ output ->writeln ("<info>Linked skin in public directory</info> " );
57+ $ this ->symlinkPublicMageRoot ("media " );
58+ $ output ->writeln ("<info>Linked media in public directory</info> " );
59+ $ this ->symlinkPublicMageRoot ("errors " );
60+ $ output ->writeln ("<info>Linked errors in public directory</info> " );
61+ $ this ->symlinkPublicMageRoot ("favicon.ico " );
62+ $ output ->writeln ("<info>Linked favicon.ico in public directory</info> " );
63+ $ this ->symlinkPublicMageRoot ("sitemaps " );
64+ $ output ->writeln ("<info>Linked sitemaps in public directory</info> " );
65+ $ output ->writeln ([
66+ "<comment>All done! You can set your document root to ./public.</comment> " ,
67+ "\t<info>Please make sure your public directory and index.php are accessible by your server.</info> "
68+ ]);
69+
70+ }
71+
72+ /**
73+ * @return bool
74+ */
75+ protected function makePublicDirectory ()
76+ {
77+ $ directoryHelper = $ this ->directoryHelper ;
78+ $ magentoDirectory = $ directoryHelper ->getApplicationDirectory ();
79+ $ pathToPublic = $ magentoDirectory . $ directoryHelper ::DS . "public " ;
80+ rmdir (($ pathToPublic ));
81+ return mkdir ($ pathToPublic ,2770 );
82+ }
83+
84+ protected function symlinkPublicMageRoot ($ imitationDirectoryName )
85+ {
86+ $ directoryHelper = $ this ->directoryHelper ;
87+ $ magentoDirectory = $ directoryHelper ->getApplicationDirectory ();
88+ $ pathToPublic = $ magentoDirectory . $ directoryHelper ::DS . "public " ;
89+ $ link = $ pathToPublic . $ directoryHelper ::DS . $ imitationDirectoryName ;
90+ $ target = $ magentoDirectory . $ directoryHelper ::DS . $ imitationDirectoryName ;
91+
92+ return symlink ($ target , $ link );
93+ }
94+
95+ protected function createIndex ()
96+ {
97+ $ directoryHelper = $ this ->directoryHelper ;
98+ $ magentoDirectory = $ directoryHelper ->getApplicationDirectory ();
99+ $ pathToPublic = $ magentoDirectory . $ directoryHelper ::DS . "public " ;
100+ $ fileContents = "<?php " .
101+ "\n\t\tdefine('MAGENTO_ROOT', dirname(getcwd())); " .
102+ "\n\t\trequire_once '../index.php'; " ;
103+ $ indexFile = $ pathToPublic . $ directoryHelper ::DS . "index.php " ;
104+ file_put_contents ($ indexFile ,$ fileContents );
105+ }
106+
107+ /**
108+ * @param OutputInterface $output
109+ */
110+ protected function writeBlankLn (OutputInterface $ output )
111+ {
112+ $ output ->writeln ("" );
113+ }
114+ }
0 commit comments