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'); $userIds = Users::find(['columns' => 'id'])->toArray(); $database->begin(); for ($i = 0; $i <= self::POSTS_TOTAL; $i++) { $title = $faker->company; $userRandId = array_rand($userIds); $posts = new Posts(); $posts->usersId = $userIds[$userRandId]['id']; $posts->type = rand(0, 1) ? 'questions' : 'tips'; $posts->title = $title; $posts->slug = \Phalcon\Tag::friendlyTitle($title); $posts->numberViews = rand(5, 100); $posts->numberReply = rand(0, 20); $posts->content = $faker->text; $posts->sticked = 'N'; $posts->status = 'A'; $posts->locked = 'N'; $posts->deleted = 0; $posts->acceptedAnswer = 'N'; if (!$posts->save()) { var_dump($posts->getMessages()); $database->rollback(); die; } $log->info('posts: ' . $posts->getTitle()); } }
/** * Index a single document * * @param Client $client * @param Posts $post */ protected function _doIndex($client, $post) { $karma = $post->getNumberViews() + 0 + $post->getNumberReply(); if ($karma > 0) { $params = []; $params['body'] = ['id' => $post->getId(), 'title' => $post->getTitle(), 'content' => $post->getContent(), 'karma' => $karma]; $params['index'] = $this->index; $params['type'] = $this->type; $params['id'] = 'post-' . $post->getId(); $ret = $client->index($params); var_dump($ret); } }