public function byMysqlAction($param = null) { $domain = rtrim($this->config->application->siteUri, '/'); $sitemapsStorage = rtrim($this->config->application->sitemapsDir, '/'); $sitemap = new Sitemap($domain); $sitemap->setPath($sitemapsStorage . '/'); /** @var Contents[] $contents */ $contents = Contents::find(['columns' => "url, content, created_at", 'group' => "url", 'order' => "created_at DESC"]); $count = 0; foreach ($contents as $content) { $count++; if ($count % 1000 == 0) { $this->log->info("обрабатано {$count} строк"); } $data = json_decode($content->content, true); if (isset($param[3]) && $param[3] == 'full') { $condition = $data['controller'] == 'books' && ($data['action'] == 'listByClass' || $data['action'] == 'booksBySubject' || $data['action'] == 'listByBoth' || $data['action'] == 'view' || $data['action'] == 'list'); } else { $condition = $data['controller'] == 'books' && ($data['action'] == 'listByClass' || $data['action'] == 'booksBySubject' || $data['action'] == 'listByBoth' || $data['action'] == 'view'); } if ($condition) { $sitemap->addItem($content->url, 0.5, null, $content->created_at); continue; } if ($data['controller'] == 'books' && $data['action'] == 'viewTask' && $data['book']['is_single_page'] == false) { $sitemap->addItem($content->url, 0.5, null, $content->created_at); } } $sitemap->createSitemapIndex($domain . '/sitemaps/', 'Today'); }
protected function deleteContents() { /** @var Urls[] $urls */ $urls = Urls::find(['(type = :type1: OR type = :type2:) AND action = :action:', 'bind' => ['type1' => Urls::CONTENT, 'type2' => Urls::COMMON, 'action' => Urls::FOR_DELETING]]); foreach ($urls as $url) { $contentsForDeleting = Contents::find(['url = :url: AND type = :type:', 'bind' => ['url' => $url->url, 'type' => $url->type]]); $contentsForDeleting->delete(); $this->log->info("Удален контент url= . {$url->url}"); $url->delete(); } }
public function request($url, $useOwlServer = true) { $url = urldecode($url); PH_DEBUG ? Debugger::dumpBar($url, 'url') : null; if ($useOwlServer) { $url = $this->getUrl($url); $request = new Request($url); $request->getOptions()->set(CURLOPT_TIMEOUT, 8)->set(CURLOPT_RETURNTRANSFER, true)->set(CURLOPT_USERAGENT, $this->di->get('config')->curlUserAgent); $response = $request->send(); $content = json_decode($response->getContent(), true); $url = $this->getUrl('', 'common'); $request = new Request($url); $request->getOptions()->set(CURLOPT_TIMEOUT, 8)->set(CURLOPT_RETURNTRANSFER, true)->set(CURLOPT_USERAGENT, $this->di->get('config')->curlUserAgent); $response = $request->send(); $common = json_decode($response->getContent(), true); return $content + $common; } $response = Contents::get($url); return $response; }