/** * 昨日、一昨日のコンテンツにページャを指定する * * @return void **/ private function _buildPastPager() { if (IS_EC2 === false) { return false; } $yesterday = date('Ymd', time() - 60 * 60 * 24); $before_yesterday = date('Ymd', time() - 60 * 60 * 48); // 既に昨日用のコンテンツを生成している場合は処理を行わない if ($this->S3->doesObjectExist('contents/' . $yesterday . '.html') === true) { return false; } // 現在indexとなっているページを昨日のコンテンツに繰り下げる try { $contents = $this->S3->download('index.html'); $pattern = '/<li class="next-page next"><a href="[^<]*<\\/a><\\/li>/'; $previous = '<li class="previous preview-page"><a href="/">< Previous</a></li>'; $next = '<li class="next-page next"><a href="/contents/' . $before_yesterday . '.html">Next ></a></li>'; $contents = preg_replace($pattern, $previous . $next, $contents); $path = '/tmp/' . $yesterday . '.html'; file_put_contents($path, $contents); $this->S3->upload($path, 'contents/' . $yesterday . '.html'); } catch (\Exception $e) { Logger::addLog($e->getFile() . ' on line ' . $e->getLine()); Logger::addLog($e->getMessage()); Logger::addLog('現在のindex.htmlを昨日のコンテンツにするの失敗した' . PHP_EOL); } // 一昨日のページャを更新する try { $contents = $this->S3->download('contents/' . $before_yesterday . '.html'); $pattern = '<li class="previous preview-page"><a href="/">< Previous</a></li>'; $previous = '<li class="previous preview-page"><a href="/contents/' . $yesterday . '.html">< Preview</a></li>'; $contents = str_replace($pattern, $previous, $contents); $path = '/tmp/' . $before_yesterday . '.html'; file_put_contents($path, $contents); $this->S3->upload($path, 'contents/' . $before_yesterday . '.html'); } catch (\Exception $e) { Logger::addLog($e->getFile() . ' on line ' . $e->getLine()); Logger::addLog($e->getMessage()); Logger::addLog('一昨日のページャがindex.html指してたのを更新するのに失敗した' . PHP_EOL); } }