Commit 6c673f5d6198fdc6a1889f0eb1c3929079204883

Authored by Alexey Boroda
1 parent 21f69fb1

-Sitemap generation in process

Showing 1 changed file with 26 additions and 13 deletions   Show diff stats
console/controllers/SiteMapController.php
... ... @@ -13,6 +13,7 @@ use Yii;
13 13 use common\models\Page;
14 14 use common\models\PageSearch;
15 15 use yii\helpers\ArrayHelper;
  16 +use yii\helpers\Console;
16 17 use yii\helpers\Url;
17 18 use yii\console\Controller;
18 19 use yii\web\NotFoundHttpException;
... ... @@ -102,15 +103,15 @@ class SiteMapController extends Controller
102 103  
103 104  
104 105 public function createRow( $url, $priority, &$content ){
105   - if($this->checkUrl($url)){
106   - print $this->count++ . "\n";
  106 +// if($this->checkUrl($url)){
  107 + $this->stdout( '# ' . $this->count++ . "\n", Console::FG_GREEN);
107 108 $content .= '<url>' .
108 109 '<loc>' . $url . '</loc>' .
109 110 '<lastmod>' . date('Y-m-d') . '</lastmod>' .
110 111 '<changefreq>Weekly</changefreq>' .
111 112 '<priority>' . $priority .'</priority>' .
112 113 '</url>';
113   - }
  114 +// }
114 115 }
115 116  
116 117  
... ... @@ -124,7 +125,7 @@ class SiteMapController extends Controller
124 125  
125 126 Yii::$app->urlManager->addRules($config['components']['urlManager']['rules']);
126 127  
127   -
  128 + $this->stdout('Start!' . "\n", Console::FG_RED);
128 129  
129 130 $dirName = Yii::getAlias('@frontend').'/web';
130 131  
... ... @@ -134,36 +135,45 @@ class SiteMapController extends Controller
134 135 $handle = fopen($dirName .'/'. $filename, "w");
135 136  
136 137 $content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
  138 +
  139 + $this->stdout('Add static' . "\n", Console::FG_BLUE);
137 140  
138 141 foreach ($this->getAddStatic() as $page) {
139 142 $this->createRow($page , 1,$content);
140 143 }
  144 + $this->stdout('Add static pages' . "\n", Console::FG_BLUE);
141 145  
142 146 foreach ($this->getStaticPages() as $page) {
143 147 $url = Url::to(['text/main','translit' => $page->translit]);
  148 +
144 149 $this->createRow($url , 1,$content);
145 150 }
  151 + $this->stdout('Add categories' . "\n", Console::FG_BLUE);
146 152  
147 153 foreach ($this->getCategories() as $category) {
  154 +
148 155 $url = Url::to(['catalog/category', 'category' => $category]);
149 156 $this->createRow($url , 1,$content);
150 157 }
151   -
  158 +
  159 + $this->stdout('Add products' . "\n", Console::FG_BLUE);
152 160  
153 161 foreach ($this->getProducts() as $product) {
154   -
  162 +
155 163 $url = Url::to(['catalog/product', 'product' => $product]);
156 164 $this->createRow($url , 0.9, $content);
157 165 }
158   -
  166 +
  167 + $this->stdout('Add articles' . "\n", Console::FG_BLUE);
159 168  
160 169 foreach ($this->getArticles() as $article) {
161   -
  170 +
162 171 $url = Url::to(['articles/show', 'translit' => $article->translit]);
163 172 $this->createRow($url , 0.8,$content);
164 173  
165 174 }
166   -
  175 +
  176 + $this->stdout('Add brands' . "\n", Console::FG_BLUE);
167 177  
168 178 foreach($this->getCategories() as $category){
169 179 foreach ($this->getBrands($category) as $brand) {
... ... @@ -173,7 +183,8 @@ class SiteMapController extends Controller
173 183 }
174 184 }
175 185 }
176   -
  186 +
  187 + $this->stdout('Add filters' . "\n", Console::FG_BLUE);
177 188  
178 189 foreach($this->getCategories() as $category){
179 190 foreach ($this->getFilters($category) as $filter) {
... ... @@ -184,7 +195,9 @@ class SiteMapController extends Controller
184 195  
185 196 }
186 197 }
187   -
  198 +
  199 + $this->stdout('Add seo links' . "\n", Console::FG_BLUE);
  200 +
188 201 foreach($this->getSeoLinks() as $link){
189 202 $url = Yii::$app->urlManager->baseUrl.$link->url;
190 203 $this->createRow($url , 0.7, $content);
... ... @@ -219,8 +232,8 @@ class SiteMapController extends Controller
219 232  
220 233 fwrite($handle, $content);
221 234 fclose($handle);
222   -
223   - print $dirName .'/'. $filename;
  235 + $this->stdout('File name: ' . $dirName .'/'. $filename . "\n", Console::FG_CYAN);
  236 +
224 237 }
225 238  
226 239 }
... ...