コード例 #1
0
ファイル: Digest.php プロジェクト: gitter-badger/phanbook
 public function getData()
 {
     $lastWeek = new \DateTime();
     $lastWeek->modify('-1 week');
     $parameters = ['createdAt >= ?0 AND deleted != 1', 'bind' => [$lastWeek->getTimestamp()], 'order' => 'numberViews', 'limit' => 10];
     $url = $this->config->application->publicUrl;
     $posts = [];
     foreach (Posts::find($parameters) as $post) {
         $user = $post->user;
         if ($user == false) {
             continue;
         }
         $title = $post->getTitle();
         $content = substr($this->markdown->text($post->getContent()), 0, 200);
         $link = $url . '/posts/' . $post->getId() . '/' . $post->getSlug();
         $posts[] = ['link' => $link, 'title' => $title, 'content' => strip_tags($content)];
     }
     return $posts;
 }
コード例 #2
0
 public function run()
 {
     $faker = Faker::create();
     $log = new Stream('php://stdout');
     $log->info('Start ' . __CLASS__);
     /** @var Phalcon\Db\AdapterInterface $database */
     $database = $this->getDI()->get('db');
     $database->begin();
     $postsId = Posts::find(['columns' => 'id'])->toArray();
     $tagsId = Tags::find(['columns' => 'id'])->toArray();
     for ($i = 0; $i <= self::POSTS_TAGS_TOTAL; $i++) {
         $postRandId = array_rand($postsId);
         $tagsRandId = array_rand($tagsId);
         $postTag = new PostsTags();
         $postTag->postsId = $postsId[$postRandId]['id'];
         $postTag->tagsId = $tagsId[$tagsRandId]['id'];
         if (!$postTag->save()) {
             var_dump($tags->getMessages());
             $database->rollback();
             die;
         }
         $log->info('Posts<->Tags ' . $postTag->getPostsId() . '<->' . $postTag->getTagsId());
     }
 }
コード例 #3
0
ファイル: Indexer.php プロジェクト: gitter-badger/phanbook
 /**
  * Indexes all posts in the forum in ES
  */
 public function indexAll()
 {
     $client = new Client();
     try {
         $deleteParams['index'] = $this->index;
         $client->indices()->delete($deleteParams);
     } catch (\Exception $e) {
         // the index does not exist yet
     }
     foreach (Posts::find('deleted != 1') as $post) {
         $this->_doIndex($client, $post);
     }
 }