Commit 6c673f5d6198fdc6a1889f0eb1c3929079204883
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,6 +13,7 @@ use Yii; | ||
| 13 | use common\models\Page; | 13 | use common\models\Page; |
| 14 | use common\models\PageSearch; | 14 | use common\models\PageSearch; |
| 15 | use yii\helpers\ArrayHelper; | 15 | use yii\helpers\ArrayHelper; |
| 16 | +use yii\helpers\Console; | ||
| 16 | use yii\helpers\Url; | 17 | use yii\helpers\Url; |
| 17 | use yii\console\Controller; | 18 | use yii\console\Controller; |
| 18 | use yii\web\NotFoundHttpException; | 19 | use yii\web\NotFoundHttpException; |
| @@ -102,15 +103,15 @@ class SiteMapController extends Controller | @@ -102,15 +103,15 @@ class SiteMapController extends Controller | ||
| 102 | 103 | ||
| 103 | 104 | ||
| 104 | public function createRow( $url, $priority, &$content ){ | 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 | $content .= '<url>' . | 108 | $content .= '<url>' . |
| 108 | '<loc>' . $url . '</loc>' . | 109 | '<loc>' . $url . '</loc>' . |
| 109 | '<lastmod>' . date('Y-m-d') . '</lastmod>' . | 110 | '<lastmod>' . date('Y-m-d') . '</lastmod>' . |
| 110 | '<changefreq>Weekly</changefreq>' . | 111 | '<changefreq>Weekly</changefreq>' . |
| 111 | '<priority>' . $priority .'</priority>' . | 112 | '<priority>' . $priority .'</priority>' . |
| 112 | '</url>'; | 113 | '</url>'; |
| 113 | - } | 114 | +// } |
| 114 | } | 115 | } |
| 115 | 116 | ||
| 116 | 117 | ||
| @@ -124,7 +125,7 @@ class SiteMapController extends Controller | @@ -124,7 +125,7 @@ class SiteMapController extends Controller | ||
| 124 | 125 | ||
| 125 | Yii::$app->urlManager->addRules($config['components']['urlManager']['rules']); | 126 | Yii::$app->urlManager->addRules($config['components']['urlManager']['rules']); |
| 126 | 127 | ||
| 127 | - | 128 | + $this->stdout('Start!' . "\n", Console::FG_RED); |
| 128 | 129 | ||
| 129 | $dirName = Yii::getAlias('@frontend').'/web'; | 130 | $dirName = Yii::getAlias('@frontend').'/web'; |
| 130 | 131 | ||
| @@ -134,36 +135,45 @@ class SiteMapController extends Controller | @@ -134,36 +135,45 @@ class SiteMapController extends Controller | ||
| 134 | $handle = fopen($dirName .'/'. $filename, "w"); | 135 | $handle = fopen($dirName .'/'. $filename, "w"); |
| 135 | 136 | ||
| 136 | $content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | 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 | foreach ($this->getAddStatic() as $page) { | 141 | foreach ($this->getAddStatic() as $page) { |
| 139 | $this->createRow($page , 1,$content); | 142 | $this->createRow($page , 1,$content); |
| 140 | } | 143 | } |
| 144 | + $this->stdout('Add static pages' . "\n", Console::FG_BLUE); | ||
| 141 | 145 | ||
| 142 | foreach ($this->getStaticPages() as $page) { | 146 | foreach ($this->getStaticPages() as $page) { |
| 143 | $url = Url::to(['text/main','translit' => $page->translit]); | 147 | $url = Url::to(['text/main','translit' => $page->translit]); |
| 148 | + | ||
| 144 | $this->createRow($url , 1,$content); | 149 | $this->createRow($url , 1,$content); |
| 145 | } | 150 | } |
| 151 | + $this->stdout('Add categories' . "\n", Console::FG_BLUE); | ||
| 146 | 152 | ||
| 147 | foreach ($this->getCategories() as $category) { | 153 | foreach ($this->getCategories() as $category) { |
| 154 | + | ||
| 148 | $url = Url::to(['catalog/category', 'category' => $category]); | 155 | $url = Url::to(['catalog/category', 'category' => $category]); |
| 149 | $this->createRow($url , 1,$content); | 156 | $this->createRow($url , 1,$content); |
| 150 | } | 157 | } |
| 151 | - | 158 | + |
| 159 | + $this->stdout('Add products' . "\n", Console::FG_BLUE); | ||
| 152 | 160 | ||
| 153 | foreach ($this->getProducts() as $product) { | 161 | foreach ($this->getProducts() as $product) { |
| 154 | - | 162 | + |
| 155 | $url = Url::to(['catalog/product', 'product' => $product]); | 163 | $url = Url::to(['catalog/product', 'product' => $product]); |
| 156 | $this->createRow($url , 0.9, $content); | 164 | $this->createRow($url , 0.9, $content); |
| 157 | } | 165 | } |
| 158 | - | 166 | + |
| 167 | + $this->stdout('Add articles' . "\n", Console::FG_BLUE); | ||
| 159 | 168 | ||
| 160 | foreach ($this->getArticles() as $article) { | 169 | foreach ($this->getArticles() as $article) { |
| 161 | - | 170 | + |
| 162 | $url = Url::to(['articles/show', 'translit' => $article->translit]); | 171 | $url = Url::to(['articles/show', 'translit' => $article->translit]); |
| 163 | $this->createRow($url , 0.8,$content); | 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 | foreach($this->getCategories() as $category){ | 178 | foreach($this->getCategories() as $category){ |
| 169 | foreach ($this->getBrands($category) as $brand) { | 179 | foreach ($this->getBrands($category) as $brand) { |
| @@ -173,7 +183,8 @@ class SiteMapController extends Controller | @@ -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 | foreach($this->getCategories() as $category){ | 189 | foreach($this->getCategories() as $category){ |
| 179 | foreach ($this->getFilters($category) as $filter) { | 190 | foreach ($this->getFilters($category) as $filter) { |
| @@ -184,7 +195,9 @@ class SiteMapController extends Controller | @@ -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 | foreach($this->getSeoLinks() as $link){ | 201 | foreach($this->getSeoLinks() as $link){ |
| 189 | $url = Yii::$app->urlManager->baseUrl.$link->url; | 202 | $url = Yii::$app->urlManager->baseUrl.$link->url; |
| 190 | $this->createRow($url , 0.7, $content); | 203 | $this->createRow($url , 0.7, $content); |
| @@ -219,8 +232,8 @@ class SiteMapController extends Controller | @@ -219,8 +232,8 @@ class SiteMapController extends Controller | ||
| 219 | 232 | ||
| 220 | fwrite($handle, $content); | 233 | fwrite($handle, $content); |
| 221 | fclose($handle); | 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 | } |