/** * Create sitemap data. * * @return array */ protected function createSiteMapData() { $data = []; $pasteBin = new M\PasteBin(); $last = $pasteBin->orderBy('id')->get()->last(); $data[] = ['loc' => '/pastebin', 'lastmod' => $last->created_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.7']; $all = $pasteBin->select(['hash', 'created_at'])->where('protect', '=', false)->get(); foreach ($all as $p) { $data[] = ['loc' => "/pastebin/show/{$p->hash}", 'lastmod' => $p->created_at->format('Y-m-d'), 'changefreq' => 'never', 'priority' => '0.4']; } $memo = new M\Memo(); $last = $memo->orderBy('id')->get()->last(); $data[] = ['loc' => '/memo', 'lastmod' => $last->created_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.7']; foreach ($memo->select(['id', 'created_at'])->get() as $m) { $data[] = ['loc' => "/memo/show/{$m->id}", 'lastmod' => $m->created_at->format('Y-m-d'), 'changefreq' => 'never', 'priority' => '0.4']; } foreach ($memo->select('user_sn')->distinct()->get() as $m) { $updated_at = $memo->where('user_sn', '=', $m->user_sn)->get()->last()->updated_at; $data[] = ['loc' => "/memo/user/{$m->user_sn}", 'lastmod' => $updated_at->format('Y-m-d'), 'changefreq' => 'monthly', 'priority' => '0.4']; } return $data; }
/** * Update paste bin user_sn. * * @param $userId * @param $userSn */ protected function updatePasteBin($userId, $userSn) { $memo = new PasteBin(); $all = $memo->select(['user_sn', 'user_id'])->whereUserId($userId)->get(); foreach ($all as $pb) { if ($pb->user_sn === $userSn) { continue; } $pb->user_sn = $userSn; $pb->update(); } }