Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
indexcommand.php
1<?php
2
4
6use Symfony\Component\Console;
7
8
9class IndexCommand extends Console\Command\Command
10{
15 protected function configure()
16 {
17 //$inBitrixDir = realpath(Application::getDocumentRoot().Application::getPersonalRoot()) === realpath(getcwd());
18
19 $this
20 // the name of the command (the part after "bin/console")
21 ->setName('translate:index')
22
23 // the short description shown while running "php bin/console list"
24 ->setDescription('Indexes project for localization language files.')
25
26 // the full command description shown when running the command with
27 // the "--help" option
28 ->setHelp('This system command builds search index of localization language files.')
29
30 ->setDefinition(
31 new Console\Input\InputDefinition(array(
32 new Console\Input\InputOption(
33 'path',
34 'p',
35 Console\Input\InputArgument::OPTIONAL,
36 'Path to look through.',
37 '/bitrix/modules'
38 )
39 ))
40 )
41 ;
42 }
43
50 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
51 {
52 $vn = ($output->getVerbosity() > Console\Output\OutputInterface::VERBOSITY_QUIET);
53 $vv = ($output->getVerbosity() >= Console\Output\OutputInterface::VERBOSITY_VERY_VERBOSE);
54
55 $path = $input->getOption('path');
56
57 if ($vn)
58 {
59 $startTime = \microtime(true);
60 $memoryBefore = \memory_get_usage();
61 $output->writeln('--------Translate::index-----------');
62 $output->writeln("Indexing path: {$path}");
63 }
64
65 $filt = new Translate\Filter([
66 'path' => $path
67 ]);
68
69 //-----------------
70 // lang folders
71 $pathLang = new Translate\Index\PathLangCollection();
72 if ($vn)
73 {
74 $pathLang::$verbose = $vv;
75 $output->write("PathLangCollection::purge..");
76 }
77
78 $pathLang->purge($filt);
79
80 if ($vn)
81 {
82 $time = round(\microtime(true) - $startTime, 2);
83 $output->writeln("\tdone\t{$time}sec");
84 $output->write("PathLangCollection::collect..");
85 }
86
87 $pathLang->collect($filt);
88
89 if ($vn)
90 {
91 $time = \round(\microtime(true) - $startTime, 2);
92 $output->writeln("\tdone\t{$time}sec");
93 }
94
95 //-----------------
96 // path structure
97 $pathIndex = new Translate\Index\PathIndexCollection();
98 if ($vn)
99 {
100 $pathIndex::$verbose = $vv;
101 $output->write("PathIndexCollection::purge..");
102 }
103
104 $pathIndex->purge($filt)->unvalidate($filt);
105 if ($vn)
106 {
107 $time = \round(\microtime(true) - $startTime, 2);
108 $output->writeln("\tdone\t{$time}sec");
109 $output->write("PathIndexCollection::collect..");
110 }
111
112 $pathIndex->collect($filt);
113
114 if ($vn)
115 {
116 $time = \round(\microtime(true) - $startTime, 2);
117 $output->writeln("\tdone\t{$time}sec");
118 }
119
120 //-----------------
121 // lang files
122 $fileIndex = new Translate\Index\FileIndexCollection();
123 if ($vn)
124 {
125 $fileIndex::$verbose = $vv;
126 $output->write("FileIndexCollection::collect..");
127 }
128
129 $fileIndex->collect($filt);
130
131 if ($vn)
132 {
133 $time = \round(\microtime(true) - $startTime, 2);
134 $output->writeln("\tdone\t{$time}sec");
135 }
136
137 //-----------------
138 // phrases
139 $phraseIndex = new Translate\Index\PhraseIndexCollection();
140 if ($vn)
141 {
142 $phraseIndex::$verbose = $vv;
143 $output->write("PhraseIndexCollection::collect..");
144 }
145
146 $phraseIndex->collect($filt);
147 $pathIndex->validate($filt, false);
148
149 if ($vn)
150 {
151 // summary stats
152 $time = \round(\microtime(true) - $startTime, 2);
153 $output->writeln("\tdone\t{$time}sec");
154
155 $memoryAfter = \memory_get_usage();
156 $memoryDiff = $memoryAfter - $memoryBefore;
157 $output->writeln('Memory usage: '.(\round($memoryAfter/1024/1024, 1)).'M (+'.(\round($memoryDiff/1024/1024, 1)).'M)');
158 $output->writeln('Memory peak usage: '.(\round(\memory_get_peak_usage()/1024/1024, 1)).'M');
159 }
160
161 return 0;
162 }
163}
execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)