From ee2ceed332ad301defa23cf207b5592f6914615a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 8 Dec 2016 18:26:57 +0200 Subject: [PATCH] -Sitemap beta --- console/SiteMapController.php | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/console/SiteMapController.php b/console/SiteMapController.php index 92ed672..8bb1eed 100755 --- a/console/SiteMapController.php +++ b/console/SiteMapController.php @@ -16,17 +16,18 @@ class SiteMapController extends Controller { - private $urlList = [ 'https://dev.extremstyle.ua/ru' ]; + private $urlList = [ 'https://extremstyle.ua/ru' ]; private $count = 1; public $fileName; public $handle; public $mapNumber = 1; public $mainMap = ''; + public $content = ''; public function getAddStatic() { return [ - 'https://dev.extremstyle.ua/ru', + 'https://extremstyle.ua/ru', ]; } @@ -88,34 +89,35 @@ } } - public function createRow($url, $priority, &$content) + public function createRow($url, $priority) { - if ($this->checkUrl($url)) { +// if ($this->checkUrl($url)) { + if($this->count % 500 == 0) { $this->stdout($this->count . " : ", Console::BOLD); $this->stdout($url . "\n", Console::FG_YELLOW); - $content .= '' . '' . $url . '' . '' . date( + } + $this->content .= '' . '' . $url . '' . '' . date( 'Y-m-d' ) . '' . 'Weekly' . '' . $priority . '' . ''; $this->count++; - if ($this->count % 40000 == 0) { - $content .= ''; - - fwrite($this->handle, $content); + if ($this->count % 10000 == 0) { + $this->content .= ''; + $this->stdout('Added unset' . "\n", Console::FG_CYAN); + fwrite($this->handle, $this->content); fclose($this->handle); - unset($content); $this->mapNumber++; $this->mainMap .= ''. - 'https://dev.extremstyle.ua/ru/' . $this->fileName . ''. + 'https://extremstyle.ua/ru/' . $this->fileName . ''. '' . date('Y-m-d') . ''. ''; $this->fileName = 'sitemap' . $this->mapNumber . '.xml'; $this->handle = fopen(Yii::getAlias('@frontend') . '/web' . '/' . $this->fileName, "w"); - $content = ''; + $this->content = ''; } - } +// } } public function actionProcess() @@ -128,14 +130,14 @@ Yii::$app->urlManager->addRules($config[ 'components' ][ 'urlManager' ][ 'rules' ]); $this->mainMap = ''; $this->mainMap .= ''; - $this->fileName = 'test_sitemap' . $this->mapNumber . '.xml'; + $this->fileName = 'sitemap' . $this->mapNumber . '.xml'; setlocale(LC_ALL, 'ru_RU.CP1251'); $this->handle = fopen(Yii::getAlias('@frontend') . '/web' . '/' . $this->fileName, "w"); - $content = ''; + $this->content = ''; foreach ($this->getAddStatic() as $page) { - $this->createRow($page, 1, $content); + $this->createRow($page, 1); } foreach ($this->getStaticPages() as $page) { @@ -145,7 +147,7 @@ 'slug' => $page->lang->alias, ] ); - $this->createRow($url, 1, $content); + $this->createRow($url, 1); } foreach ($this->getCategories() as $category) { @@ -155,11 +157,14 @@ 'category' => $category->lang->alias, ] ); - $this->createRow($url, 0.8, $content); + $this->createRow($url, 0.8); } foreach ($this->getVariants() as $rows) { foreach ($rows as $row) { + if(!preg_match("@^[a-zA-Z\d]+$@i", $row->sku)) { + continue; + } $url = Url::to( [ 'catalog/product', @@ -167,7 +172,7 @@ 'variant' => $row->sku, ] ); - $this->createRow($url, 0.9, $content); + $this->createRow($url, 0.9); } } @@ -179,7 +184,7 @@ 'slug' => $brand->lang->alias, ] ); - $this->createRow($url, 0.7, $content); + $this->createRow($url, 0.7); } @@ -193,7 +198,7 @@ 'filters' => [ $group->lang->alias => [ $option->lang->alias ] ], ] ); - $this->createRow($url, 0.8, $content); + $this->createRow($url, 0.8); } } @@ -201,17 +206,17 @@ foreach ($this->getSeoLinks() as $link) { $url = Yii::$app->urlManager->baseUrl . $link->url; - $this->createRow($url, 0.7, $content); + $this->createRow($url, 0.7); } - $content .= ''; + $this->content .= ''; - fwrite($this->handle, $content); + fwrite($this->handle, $this->content); fclose($this->handle); $this->mainMap .= ''. - 'https://dev.extremstyle.ua/ru/' . $this->fileName . ''. + 'https://extremstyle.ua/ru/' . $this->fileName . ''. '' . date('Y-m-d') . ''. ''. ''; @@ -220,7 +225,7 @@ fwrite($mainHandle, $this->mainMap); fclose($mainHandle); - print Yii::getAlias('@frontend') . '/web' . '/' . $this->fileName; + $this->stdout(Yii::getAlias('@frontend') . '/web' . '/' . $this->fileName . "\n", Console::FG_GREEN); } } -- libgit2 0.21.4